### Start Docker Compose Project Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/github.com/aws/aws-lambda-go/otellambda/example/README.md Use this command to initiate the example environment with Docker Compose. Ensure Docker Compose is installed and configured. ```sh docker-compose up --detach ``` -------------------------------- ### Start HTTP Services with Docker Compose Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/net/http/otelhttp/example/README.md Use this command to bring up the http-server and http-client services for the example. Ensure Docker Compose is installed. ```sh docker-compose up --detach http-server http-client ``` -------------------------------- ### Installation Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/github.com/aws/aws-lambda-go/otellambda/README.md Install the AWS Lambda instrumentation package using go get. ```APIDOC ## Installation ```bash go get -u go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-lambda-go/otellambda ``` ``` -------------------------------- ### Setup SDK and Propagators in Go Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/examples/passthrough/README.md This setup propagates context and creates new, potentially recorded spans. It requires configuring an exporter and a TracerProvider. ```go exp, _ := stdout.New(stdout.WithPrettyPrint()) tp = sdktrace.NewTracerProvider( sdktrace.WithBatcher(exp), ) otel.SetTracerProvider(tp) // Setup Propagators otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{})) ``` -------------------------------- ### Manage AWS SDK V2 instrumentation example lifecycle Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/README.md Commands to start, inspect, and clean up the instrumentation example environment. ```sh docker-compose up --detach ``` ```sh docker-compose logs ``` ```sh docker-compose down ``` -------------------------------- ### Install AWS Lambda X-Ray Instrumentation Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/github.com/aws/aws-lambda-go/otellambda/xrayconfig/README.md Use the go get command to add the instrumentation package to your project. ```bash go get -u go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-lambda-go/otellambda/xrayconfig ``` -------------------------------- ### Install AWS Lambda Instrumentation Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/github.com/aws/aws-lambda-go/otellambda/README.md Use go get to install the AWS Lambda instrumentation package for Golang. ```bash go get -u go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-lambda-go/otellambda ``` -------------------------------- ### Verifying Example Builds Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/RELEASING.md Runs the verification script to ensure examples build correctly against published releases by removing local replace declarations. ```sh ./tools/verify_examples.sh ``` -------------------------------- ### Start OpenCensus Client Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/propagators/opencensus/examples/README.md Run the client implementation to initiate requests with OpenCensus propagation. ```bash go run opencensus_client/client.go ``` -------------------------------- ### Install AWS Lambda Resource Detector Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/detectors/aws/lambda/README.md Use this command to install the AWS Lambda resource detector package for your Go project. ```bash go get -u go.opentelemetry.io/contrib/detectors/aws/lambda ``` -------------------------------- ### Run gRPC Server and Client Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/google.golang.org/grpc/otelgrpc/example/README.md Commands to start the gRPC server and client services. ```sh go run ./server ``` ```sh go run ./client ``` -------------------------------- ### Start OpenTelemetry Server Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/propagators/opencensus/examples/README.md Run the server implementation that utilizes the OpenCensus binary propagation format. ```bash go run opentelemetry_server/server.go ``` -------------------------------- ### Manual AWS Resource Cleanup Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/github.com/aws/aws-lambda-go/otellambda/example/README.md Run this script to manually clean up any AWS resources that might have been created by the example and were not automatically destroyed. This is a fallback in case the example terminates unexpectedly. ```sh ./manualAWSCleanup.sh ``` -------------------------------- ### Run Echo Services Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/github.com/labstack/echo/otelecho/example/README.md Starts the echo-server and echo-client services in the background. ```bash docker-compose up --detach echo-server echo-client ``` -------------------------------- ### Example Client Output Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/propagators/opencensus/examples/README.md Sample output from the OpenCensus client showing the generated TraceID and SpanID. ```text Configuring OpenCensus, and registering the Print exporter. TraceID: 9d59b1bdbde34cdaac6cfb5b8f3c4685 SpanID: 07733a2559ef492d ... Greeting: Hello world ``` -------------------------------- ### Example Server Output Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/propagators/opencensus/examples/README.md Sample output from the OpenTelemetry server showing the received SpanContext and ParentSpanID. ```json [ { "SpanContext": { "TraceID": "9d59b1bdbde34cdaac6cfb5b8f3c4685", "SpanID": "94738571415fdb63", "TraceFlags": 1 }, "ParentSpanID": "07733a2559ef492d", ... } ] ``` -------------------------------- ### Run Docker Compose for Sampling Server Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/samplers/jaegerremote/README.md Start the necessary services for remote sampling using docker-compose. This command is used to set up the environment for testing the Jaeger remote sampler. ```shell docker-compose up -d ``` -------------------------------- ### Setup Propagators Only in Go Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/examples/passthrough/README.md Use this configuration to propagate context without recording spans. Ensure only TextMapPropagators are set. ```go otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{})) ``` -------------------------------- ### Configure Jaeger Remote Sampler in Go Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/samplers/jaegerremote/README.md Configure the Jaeger remote sampler with a service name, sampling server URL, refresh interval, and an initial sampler. This setup is used when initializing the OpenTelemetry TracerProvider. ```go jaegerRemoteSampler := jaegerremote.New( "your-service-name", jaegerremote.WithSamplingServerURL("http://{sampling_service_host_name}:5778/sampling"), jaegerremote.WithSamplingRefreshInterval(10*time.Second), jaegerremote.WithInitialSampler(trace.TraceIDRatioBased(0.5)), ) tp := trace.NewTracerProvider( trace.WithSampler(jaegerRemoteSampler), ... ) otel.SetTracerProvider(tp) ``` -------------------------------- ### Deploy OpenTelemetry infrastructure with Docker Compose Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/examples/otel-collector/README.md Starts the OpenTelemetry Collector, Jaeger, and Prometheus services in the background. ```bash docker compose up -d ``` -------------------------------- ### Run Go Program for Remote Sampling Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/samplers/jaegerremote/README.md Execute the Go program that utilizes the Jaeger remote sampler. The program will start with a default sampling percentage and attempt to fetch strategies from the configured collector. ```shell go run . ``` -------------------------------- ### Shut down Docker services Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/examples/otel-collector/README.md Stops and removes the containers started by Docker Compose. ```bash docker compose down ``` -------------------------------- ### Run the Go application Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/examples/otel-collector/README.md Executes the sample application that generates telemetry data. ```bash go run main.go ``` -------------------------------- ### Configure X-Ray Recommended Options Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/github.com/aws/aws-lambda-go/otellambda/xrayconfig/README.md Apply recommended instrumentation options to the handler to enable X-Ray trace propagation. ```go // Add import import "go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-lambda-go/otellambda/xrayconfig" // add options to InstrumentHandler call func main() { lambda.Start(otellambda.InstrumentHandler(HandleRequest, xrayconfig.WithRecommendedOptions()...)) } ``` -------------------------------- ### Compile Protobuf Definitions Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/google.golang.org/grpc/otelgrpc/example/README.md Use this command to generate Go code from .proto files when service definitions change. ```sh # protobuf v34.0 protoc -I api --go_out=paths=source_relative:./api --go-grpc_out=paths=source_relative:./api api/hello-service.proto ``` -------------------------------- ### Sync Core OTel Packages Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/RELEASING.md Upgrade all go.opentelemetry.io/otel packages to the latest tag by running 'make sync-core'. Ensure the COREPATH points to a local copy of the opentelemetry-go repository that is up to date. ```shell make sync-core COREPATH= ``` -------------------------------- ### Run Precommit Checks Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/RELEASING.md Execute the 'make precommit' command to run linters and tests. This verifies that the updated OTel dependencies are compatible with the contrib repository and that no errors are introduced. ```shell make precommit ``` -------------------------------- ### Basic Usage Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/github.com/aws/aws-lambda-go/otellambda/README.md Instrument a basic Lambda handler function by wrapping it with otellambda.InstrumentHandler. ```APIDOC ## Basic Usage ### Original Handler ```go package main import ( "context" "fmt" "github.com/aws/aws-lambda-go/lambda" ) type MyEvent struct { Name string `json:"name"` } func HandleRequest(ctx context.Context, name MyEvent) (string, error) { return fmt.Sprintf("Hello %s!", name.Name ), nil } func main() { lambda.Start(HandleRequest) } ``` ### Instrumented Handler ```go // Add import import "go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-lambda-go/otellambda" // wrap lambda handler function func main() { lambda.Start(otellambda.InstrumentHandler(HandleRequest)) } ``` ``` -------------------------------- ### Usage With Options Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/github.com/aws/aws-lambda-go/otellambda/README.md Configure the instrumentation with various options to customize tracing behavior, such as providing a custom TracerProvider, Flusher, or Propagator. ```APIDOC ## AWS Lambda Instrumentation Options | Options | Input Type | Description | | --- | --- | --- | | `WithTracerProvider` | `trace.TracerProvider` | Provide a custom `TracerProvider` for creating spans. Consider using the [AWS Lambda Resource Detector][lambda-detector-url] with your tracer provider to improve tracing information. | | `WithFlusher` | `otellambda.Flusher` | This instrumentation will call the `ForceFlush` method of its `Flusher` at the end of each invocation. Should you be using asynchronous logic (such as `sddktrace's BatchSpanProcessor`) it is very import for spans to be `ForceFlush`'ed before [Lambda freezes](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html) to avoid data delays. | | `WithEventToCarrier` | `func(eventJSON []byte) propagation.TextMapCarrier{}` | Function for providing custom logic to support retrieving trace header from different event types that are handled by AWS Lambda (e.g., SQS, CloudWatch, Kinesis, API Gateway) and returning them in a `propagation.TextMapCarrier` which a Propagator can use to extract the trace header into the context. | | `WithPropagator` | `propagation.Propagator` | The `Propagator` the instrumentation will use to extract trace information into the context. | | `WithTraceAttributeFn` | `func(eventJSON []byte) []attribute.KeyValue` | Function to extract custom attributes from different event types (e.g., SQS, CloudWatch, Kinesis, API Gateway, custom event) and return them as a slice of `attribute.KeyValue` to be added to the span. | ### Usage With Options Example ```go import ( "context" "encoding/json" "fmt" "reflect" "github.com/aws/aws-lambda-go/lambda" "go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-lambda-go/otellambda" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/propagation" "go.opentelemetry.io/otel/sdk/export/trace as sdktrace" "go.opentelemetry.io/otel/sdk/trace" "go.opentelemetry.io/otel/sdk/trace/stdouttrace" ) var someHeaderKey = "Key" // used by propagator and EventToCarrier function to identify trace header type mockHTTPRequest struct { Headers map[string][]string Body string } func mockEventToCarrier(eventJSON []byte) propagation.TextMapCarrier{ var request mockHTTPRequest _ = json.unmarshal(eventJSON, &request) return propagation.HeaderCarrier{someHeaderKey: []string{request.Headers[someHeaderKey]}} } func mockTraceAttributeFn(eventJSON []byte) []attribute.KeyValue { var request mockHTTPRequest _ = json.unmarshal(eventJSON, &request) return []attribute.KeyValue{attribute.String("mock.request.type", reflect.TypeOf(request).String())} } type mockPropagator struct{}` func HandleRequest(ctx context.Context, request mockHTTPRequest) error { return fmt.Sprintf("Hello %s!", request.Body ), nil } func main() { exp, _ := stdouttrace.New() tp := sdktrace.NewTracerProvider( sdktrace.WithBatcher(exp)) lambda.Start(otellambda.InstrumentHandler(HandleRequest, otellambda.WithTracerProvider(tp), otellambda.WithFlusher(tp), otellambda.WithTraceAttributeFn(mockTraceAttributeFn), otellambda.WithEventToCarrier(mockEventToCarrier), otellambda.WithPropagator(mockPropagator{}))) } ``` ``` -------------------------------- ### Initialize EC2 Resource Detector Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/detectors/aws/README.md Instantiate a new EC2 Resource detector. This detector captures EC2 instance environment attributes like region, availability zone, account ID, host ID, image ID, and instance type. ```go // Instantiate a new EC2 Resource detector ec2ResourceDetector := ec2.NewResourceDetector() resource, err := ec2ResourceDetector.Detect(context.Background()) ``` -------------------------------- ### Fetch Sampling Strategy with curl Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/samplers/jaegerremote/README.md Use curl to fetch the sampling strategy file from a running sampling server, specifying the service name as a query parameter. ```shell curl 'localhost:5778/sampling?service=foo' ``` ```shell curl 'localhost:5778/sampling?service=myService' ``` -------------------------------- ### Initialize EKS Resource Detector Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/detectors/aws/README.md Instantiate a new EKS Resource detector. This detector captures Kubernetes cluster name and container ID for EKS environments. ```go // Instantiate a new EKS Resource detector eksResourceDetector := eks.NewResourceDetector() resource, err := eksResourceDetector.Detect(context.Background()) ``` -------------------------------- ### Custom AWS Lambda Instrumentation Options Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/github.com/aws/aws-lambda-go/otellambda/README.md Demonstrates advanced usage of AWS Lambda instrumentation with custom options like TracerProvider, Flusher, TraceAttributeFn, EventToCarrier, and Propagator. This allows for fine-grained control over tracing behavior and data collection. ```go var someHeaderKey = "Key" // used by propagator and EventToCarrier function to identify trace header type mockHTTPRequest struct { Headers map[string][]string Body string } func mockEventToCarrier(eventJSON []byte) propagation.TextMapCarrier{ var request mockHTTPRequest _ = json.unmarshal(eventJSON, &request) return propagation.HeaderCarrier{someHeaderKey: []string{request.Headers[someHeaderKey]}} } func mockTraceAttributeFn(eventJSON []byte) []attribute.KeyValue { var request mockHTTPRequest _ = json.unmarshal(eventJSON, &request) return []attribute.KeyValue{attribute.String("mock.request.type", reflect.TypeOf(request).String())} } type mockPropagator struct{} // Extract - read from `someHeaderKey` // Inject // Fields func HandleRequest(ctx context.Context, request mockHTTPRequest) error { return fmt.Sprintf("Hello %s!", request.Body ), nil } func main() { exp, _ := stdouttrace.New() tp := sdktrace.NewTracerProvider( sdktrace.WithBatcher(exp)) lambda.Start(otellambda.InstrumentHandler(HandleRequest, otellambda.WithTracerProvider(tp), otellambda.WithFlusher(tp), otellambda.WithTraceAttributeFn(mockTraceAttributeFn), otellambda.WithEventToCarrier(mockEventToCarrier), otellambda.WithPropagator(mockPropagator{}))) } ``` -------------------------------- ### Instrument Basic Lambda Handler Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/github.com/aws/aws-lambda-go/otellambda/README.md Wraps a basic Lambda handler function with otellambda.InstrumentHandler to enable OpenTelemetry tracing. Ensure the otellambda package is imported. ```go // Add import import "go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-lambda-go/otellambda" // wrap lambda handler function func main() { lambda.Start(otellambda.InstrumentHandler(HandleRequest)) } ``` -------------------------------- ### Create Prerelease Branch for Module Set Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/RELEASING.md Use 'make prerelease' to update a specific module set's version and create a new 'prerelease' branch. This command utilizes multimod for version management. ```shell make prerelease MODSET= ``` -------------------------------- ### Enable Deprecated Runtime Metrics Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/runtime/internal/x/README.md Set the environment variable to re-enable deprecated metrics. The value must be the case-insensitive string "true". ```console export OTEL_GO_X_DEPRECATED_RUNTIME_METRICS=true ``` -------------------------------- ### Verify OTel Dependency Changes Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/RELEASING.md After updating dependencies, use 'git diff' to review the changes made to the go.mod and go.sum files. This helps confirm that the correct Git SHA has been applied to all OTel modules. ```shell git diff ``` -------------------------------- ### Update OTel Dependencies and Tidy Go Modules Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/RELEASING.md Use these commands to update the project's OpenTelemetry dependencies to a specific Git SHA and then tidy the Go modules. Ensure the GITSHA environment variable is set before running. ```shell export GITSHA= make update-all-otel-deps make go-mod-tidy ``` -------------------------------- ### Initialize ECS Resource Detector Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/detectors/aws/README.md Instantiate a new ECS Resource detector. This detector captures ECS environment attributes including region, availability zone, account ID, resource ID, container details, and various AWS ECS specific ARNs and launch types. ```go // Instantiate a new ECS Resource detector ecsResourceDetector := ecs.NewResourceDetector() resource, err := ecsResourceDetector.Detect(context.Background()) ``` -------------------------------- ### Instrument a Lambda Handler Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/github.com/aws/aws-lambda-go/otellambda/xrayconfig/README.md Wrap a standard Lambda handler function using otellambda.InstrumentHandler. ```go package main import ( "context" "fmt" "github.com/aws/aws-lambda-go/lambda" "go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-lambda-go/otellambda" ) type MyEvent struct { Name string `json:"name"` } func HandleRequest(ctx context.Context, name MyEvent) (string, error) { return fmt.Sprintf("Hello %s!", name.Name ), nil } func main() { lambda.Start(otellambda.InstrumentHandler(HandleRequest)) } ``` -------------------------------- ### View Server Logs Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/github.com/labstack/echo/otelecho/example/README.md Displays the logs for the echo-server to inspect generated spans. ```bash docker-compose logs echo-server ``` -------------------------------- ### Detect GCP Resources with Environment Variable Unpacking Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/detectors/gcp/README.md This Go snippet detects GCP resources and unpacks the OTEL_RESOURCE_ATTRIBUTES environment variable using the `WithFromEnv` option. Custom attributes can still be added. ```go ctx := context.Background() // Detect your resources res, err := resource.New(ctx, resource.WithDetectors(gcp.NewDetector()), resource.WithTelemetrySDK(), resource.WithFromEnv(), // unpacks OTEL_RESOURCE_ATTRIBUTES // Add your own custom attributes to identify your application resource.WithAttributes( semconv.ServiceNameKey.String("my-application"), semconv.ServiceNamespaceKey.String("my-company-frontend-team"), ), ) ... ``` -------------------------------- ### Detect AWS Lambda Resources in Go Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/detectors/aws/lambda/README.md Instantiate the Lambda resource detector and use it to detect resource attributes within your AWS Lambda Go application. Ensure necessary imports are included. ```go package main import ( "github.com/aws/aws-lambda-go/lambda" sdktrace "go.opencensus.io/otel/sdk/trace" lambdadetector "go.opentelemetry.io/contrib/detectors/aws/lambda" ) func main() { detector := lambdadetector.NewResourceDetector() res, err := detector.Detect(context.Background()) if err != nil { fmt.Printf("failed to detect lambda resources: %v\n", err) } tp := sdktrace.NewTracerProvider( sdktrace.WithResource(res), ) lambda.Start() } ``` -------------------------------- ### View HTTP Client Logs Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/net/http/otelhttp/example/README.md Check the logs for the http-client service to view the span and metric generated by its HTTP request. This helps in verifying the client-side tracing. ```sh docker-compose logs http-client ``` -------------------------------- ### Run Dice Application Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/examples/dice/README.md Execute the dice application using the run.sh script with the specified instrumentation mode. ```bash ./run.sh uninstrumented ``` ```bash ./run.sh instrumented ``` -------------------------------- ### Verify Prerelease Branch Changes Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/RELEASING.md After creating a prerelease branch, use 'git diff' to compare the current state with the newly created branch. This allows for verification of the version changes made by multimod. ```shell git diff HEAD..prerelease__ ``` -------------------------------- ### Detect GCP Resources and Set Custom Attributes Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/detectors/gcp/README.md Use this snippet to detect GCP resources and add custom service identification attributes. Ensure the OpenTelemetry SDK is initialized. ```go ctx := context.Background() // Detect your resources res, err := resource.New(ctx, // Use the GCP resource detector! resource.WithDetectors(gcp.NewDetector()), // Keep the default detectors resource.WithTelemetrySDK(), // Add your own custom attributes to identify your application resource.WithAttributes( semconv.ServiceNameKey.String("my-application"), semconv.ServiceNamespaceKey.String("my-company-frontend-team"), ), ) if err != nil { // Handle err } // Use the resource in your tracerprovider (or meterprovider) tp := trace.NewTracerProvider( // ... other options trace.WithResource(res), ) ``` -------------------------------- ### Add OpenCensus Binary Propagator to otelgrpc Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/propagators/opencensus/README.md Use the WithPropagators option to add the OpenCensus binary propagation format to otelgrpc interceptors. This is necessary for seamless migration when one service uses OpenCensus and the other uses OpenTelemetry. ```go import "go.opentelemetry.io/contrib/propagators/opencensus" opt := otelgrpc.WithPropagators(opencensus.Binary{}) ``` -------------------------------- ### Run Gorelease for Breaking Changes Validation Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/RELEASING.md Use 'make gorelease' to run the gorelease tool. This command checks for unwanted changes in the public API before proceeding with the release. ```shell make gorelease ``` -------------------------------- ### Tagging a Module Set Release Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/RELEASING.md Executes the make target to tag a specific module set at a given commit hash. ```sh make add-tags MODSET= COMMIT= ``` -------------------------------- ### View HTTP Server Logs Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/net/http/otelhttp/example/README.md Inspect the logs for the http-server service to see the span generated by its response to the client's request. This is crucial for verifying server-side tracing. ```sh docker-compose logs http-server ``` -------------------------------- ### Pushing Tags to Upstream Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/RELEASING.md Pushes all tags matching a specific version string to the upstream remote repository. ```sh export VERSION="" for t in $( git tag -l | grep "$VERSION" ); do git push upstream "$t"; done ``` -------------------------------- ### Inspect Docker Compose Logs Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/github.com/aws/aws-lambda-go/otellambda/example/README.md View the logs from the running Docker Compose services to inspect the instrumentation output. This is useful for verifying trace data exported to stdout. ```sh docker-compose logs ``` -------------------------------- ### View Commits Since Last Tag Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/RELEASING.md Use 'git log' to review all commits made since the last release tag. This is crucial for ensuring no relevant changes are missed when updating the CHANGELOG.md. ```shell git --no-pager log --pretty=oneline "..HEAD" ``` -------------------------------- ### Configure Kubernetes Attributes via Environment Variables Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/detectors/gcp/README.md This YAML configuration sets environment variables for Kubernetes pod name, namespace, and container name. These can be used to populate OTEL_RESOURCE_ATTRIBUTES. ```yaml env: - name: POD_NAME valueFrom: fieldRef: fieldPath: metadata.name - name: NAMESPACE_NAME valueFrom: fieldRef: fieldPath: metadata.namespace - name: CONTAINER_NAME value: my-container-name - name: OTEL_RESOURCE_ATTRIBUTES value: k8s.pod.name=$(POD_NAME),k8s.namespace.name=$(NAMESPACE_NAME),k8s.container.name=$(CONTAINER_NAME) ``` -------------------------------- ### Basic Lambda Handler Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/github.com/aws/aws-lambda-go/otellambda/README.md A standard AWS Lambda Go handler function that processes a JSON event and returns a string. This serves as the base for instrumentation. ```go package main import ( "context" "fmt" "github.com/aws/aws-lambda-go/lambda" ) type MyEvent struct { Name string `json:"name"` } func HandleRequest(ctx context.Context, name MyEvent) (string, error) { return fmt.Sprintf("Hello %s!", name.Name ), nil } func main() { lambda.Start(HandleRequest) } ``` -------------------------------- ### Stop Services Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/github.com/labstack/echo/otelecho/example/README.md Shuts down the running Docker containers. ```bash docker-compose down ``` -------------------------------- ### Merge Prerelease Branch Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/RELEASING.md Once the prerelease branch is verified and any issues are fixed, merge it into your main release branch using 'git merge'. ```shell git merge prerelease__ ``` -------------------------------- ### Set Span Status on Error in Go Source: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/README.md When an instrumented operation returns an error, set the span status to codes.Error and include the error message. Optionally, set the 'error.type' attribute using the semconv package. Avoid using span.RecordError(err). ```go res, err := t.rt.RoundTrip(r) if err != nil { span.SetAttributes(semconv.ErrorType(err)) span.SetStatus(codes.Error, err.Error()) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.