{"id":15137758,"url":"https://github.com/udhos/opentelemetry-trace-sqs","last_synced_at":"2025-10-23T13:30:48.438Z","repository":{"id":176690225,"uuid":"656400822","full_name":"udhos/opentelemetry-trace-sqs","owner":"udhos","description":"opentelemetry-trace-sqs propagates Open Telemetry tracing with SQS messages for Go language","archived":false,"fork":false,"pushed_at":"2024-12-19T23:56:11.000Z","size":85,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-30T18:48:16.968Z","etag":null,"topics":["aws","b3","go","golang","open-telemetry","open-telemetry-go","sqs","tracing"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/udhos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-20T22:07:01.000Z","updated_at":"2024-12-30T15:44:18.000Z","dependencies_parsed_at":"2023-10-25T23:31:29.144Z","dependency_job_id":"243a55de-cc67-45f6-98cd-b9c40f68c9ac","html_url":"https://github.com/udhos/opentelemetry-trace-sqs","commit_stats":{"total_commits":45,"total_committers":2,"mean_commits":22.5,"dds":"0.022222222222222254","last_synced_commit":"96d128566167f0ae3cb9d1b81f91cd6ee82e758c"},"previous_names":["udhos/opentelemetry-trace-sqs"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udhos%2Fopentelemetry-trace-sqs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udhos%2Fopentelemetry-trace-sqs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udhos%2Fopentelemetry-trace-sqs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udhos%2Fopentelemetry-trace-sqs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/udhos","download_url":"https://codeload.github.com/udhos/opentelemetry-trace-sqs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237834591,"owners_count":19373754,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","b3","go","golang","open-telemetry","open-telemetry-go","sqs","tracing"],"created_at":"2024-09-26T07:01:54.085Z","updated_at":"2025-10-23T13:30:48.093Z","avatar_url":"https://github.com/udhos.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![license](http://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/udhos/opentelemetry-trace-sqs/blob/main/LICENSE)\n[![Go Report Card](https://goreportcard.com/badge/github.com/udhos/opentelemetry-trace-sqs)](https://goreportcard.com/report/github.com/udhos/opentelemetry-trace-sqs)\n[![Go Reference](https://pkg.go.dev/badge/github.com/udhos/opentelemetry-trace-sqs.svg)](https://pkg.go.dev/github.com/udhos/opentelemetry-trace-sqs)\n\n# opentelemetry-trace-sqs\n\n[opentelemetry-trace-sqs](https://github.com/udhos/opentelemetry-trace-sqs) propagates Open Telemetry tracing with SQS messages for the Go language. Injecting with SNS Publish is also supported since SNS-to-SQS fanout is a common case.\n\n# Tracing propagation with SQS\n\n## Extract trace from SQS received message\n\nUse `SqsCarrierAttributes.Extract()` to extract trace context from SQS message.\n\n```go\nimport (\n    \"github.com/aws/aws-sdk-go-v2/service/sqs/types\"\n    \"github.com/udhos/opentelemetry-trace-sqs/otelsqs\"\n)\n\n// handleSQSMessage is an example function that uses SqsCarrierAttributes.Extract to\n// extract tracing context from inbound SQS message.\nfunc handleSQSMessage(app *application, inboundSqsMessage types.Message) {\n    // Extract the tracing context from a received SQS message\n    ctx := otelsqs.NewCarrier().Extract(context.Background(), inboundSqsMessage.MessageAttributes)\n\n    // Use the trace context as usual, for instance, starting a new span\n    ctxNew, span := app.tracer.Start(ctx, \"handleSQSMessage\")\n    defer span.End()\n\n    // One could log the traceID\n    log.Printf(\"handleSQSMessage: traceID=%s\", span.SpanContext().TraceID().String())\n\n    // Now handle the SQS message\n```\n\n## Inject trace context into SQS message before sending\n\nUse `SqsCarrierAttributes.Inject()` to inject trace context into SQS message before sending it.\n\n```go\nimport (\n    \"github.com/aws/aws-sdk-go-v2/service/sqs/types\"\n    \"github.com/udhos/opentelemetry-trace-sqs/otelsqs\"\n)\n\n// sendSQSMessage is an example function that uses SqsCarrierAttributes.Inject to\n// propagate tracing context into outgoing SQS message.\n// 'ctx' holds current tracing context.\nfunc sendSQSMessage(ctx context.Context, app *application, outboundSqsMessage types.Message) {\n    // You have a trace context in 'ctx' that you need to propagate into SQS message 'outboundSqsMessage'\n    ctxNew, span := app.tracer.Start(ctx, \"sendSQSMessage\")\n    defer span.End()\n\n    // Inject the tracing context\n    if errInject := otelsqs.NewCarrier().Inject(ctxNew, outboundSqsMessage.MessageAttributes); errInject != nil {\n        log.Printf(\"inject error: %v\", errInject)\n    }\n\n    // Now you can send the SQS message\n```\n\n# Inject with SNS Publish\n\nUse `SnsCarrierAttributes.Inject` to inject trace context into SNS publishing.\n\n```go\nimport (\n    \"github.com/aws/aws-sdk-go-v2/service/sns\"\n    \"github.com/aws/aws-sdk-go-v2/service/sns/types\"\n    \"github.com/udhos/opentelemetry-trace-sqs/otelsns\"\n)\n\n// publish is an example function that uses SnsCarrierAttributes.Inject to\n// propagate tracing context with SNS publishing.\n// 'ctx' holds current tracing context.\nfunc publish(ctx context.Context, topicArn, msg string) {\n    input := \u0026sns.PublishInput{\n        TopicArn:          aws.String(topicArn),\n        Message:           aws.String(msg),\n        MessageAttributes: make(map[string]types.MessageAttributeValue),\n    }\n\n    // Inject the tracing context\n    if errInject := otelsns.NewCarrier().Inject(ctx, input.MessageAttributes); errInject != nil {\n        log.Printf(\"inject error: %v\", errInject)\n    }\n\n    // Now invoke SNS publish for input\n```\n\n# Open Telemetry tracing recipe for GIN and HTTP\n\n1. Initialize the tracing - see main.go\n2. Enable trace propagation - see internal/tracing\n3. Retrieve tracing from request context\n\n3.1. If using GIN\n\nGIN - Use otelgin middleware\n\n```go\n// gin\nimport \"go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin\"\nrouter.Use(otelgin.Middleware(\"virtual-service\"))\n```\n\nGIN - Get context with c.Request.Context()\n\n```go\n// gin\nfunc handlerRoute(c *gin.Context, app *application) {\n    const me = \"handlerRoute\"\n    ctx, span := app.tracer.Start(c.Request.Context(), me)\n    defer span.End()\n// ...\n```\n\n3.2. If using standard http package\n\nHTTP - Wrap handler with otelhttp.NewHandler\n\n```go\nwrappedHandler := otelhttp.NewHandler(handler, \"hello-instrumented\")\nhttp.Handle(\"/hello-instrumented\", wrappedHandler)\n```\n\nHTTP - Get context with r.Context()\n\n```go\nfunc httpHandler(w http.ResponseWriter, r *http.Request) {\n    const me = \"httpHandler\"\n    ctx, span := app.tracer.Start(r.Context(), me)\n    defer span.End()\n// ...\n```\n\n4. For http client, create a Request from Context and wrap transport with otelhttp.NewTransport\n\n```go\nnewCtx, span := app.tracer.Start(ctx, \"backendHTTP.fetch\")\nreq, errReq := http.NewRequestWithContext(newCtx, \"GET\", u, nil)\nclient := http.Client{Transport: otelhttp.NewTransport(http.DefaultTransport)}\nresp, errGet := client.Do(req)\n```\n\n# Test trace propagation across SQS\n\n```\n# Jaeger\n./run-jaeger-local.sh\n\nopen jaeger: http://localhost:16686\n\n# Server 1\nexport QUEUE_URL_INPUT=https://sqs.us-east-1.amazonaws.com/100010001000/q1\nexport QUEUE_URL_OUTPUT=https://sqs.us-east-1.amazonaws.com/100010001000/q2\nexport OTEL_SERVICE_NAME=opentelemetry-trace-sqs-gin-1\nexport HTTP_ADDR=:8001\nexport BACKEND_URL=http://localhost:8002/send\nopentelemetry-trace-sqs-gin\n\n# Server 2\nexport QUEUE_URL_INPUT=https://sqs.us-east-1.amazonaws.com/100010001000/q2\nexport QUEUE_URL_OUTPUT=https://sqs.us-east-1.amazonaws.com/100010001000/q3\nexport OTEL_SERVICE_NAME=opentelemetry-trace-sqs-gin-2\nexport HTTP_ADDR=:8002\nexport BACKEND_URL=http://localhost:8003/send\nopentelemetry-trace-sqs-gin\n\n# Server 3\nexport QUEUE_URL_INPUT=https://sqs.us-east-1.amazonaws.com/100010001000/q3\nexport QUEUE_URL_OUTPUT=https://sqs.us-east-1.amazonaws.com/100010001000/q4\nexport OTEL_SERVICE_NAME=opentelemetry-trace-sqs-gin-3\nexport HTTP_ADDR=:8003\nexport BACKEND_URL=http://wrong:8002/send\nopentelemetry-trace-sqs-gin\n\ncurl -d '{\"a\":\"b\"}' localhost:8001/send\n```\n\n# References\n\n## Open Issue\n\n[Instrumentation for SNS/SQS](https://github.com/open-telemetry/opentelemetry-go-contrib/issues/1613)\n\n## OpenTelemetry Go Contrib Instrumentation\n\nhttps://github.com/open-telemetry/opentelemetry-go-contrib/tree/main/instrumentation\n\n## OpenTelemetry Registry\n\nhttps://opentelemetry.io/ecosystem/registry/\n\n## B3 Propagation\n\nhttps://github.com/openzipkin/b3-propagation\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fudhos%2Fopentelemetry-trace-sqs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fudhos%2Fopentelemetry-trace-sqs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fudhos%2Fopentelemetry-trace-sqs/lists"}