Skip to content

feat(tracing): propagate W3C trace context across AWS messaging - #540

Merged
arjun-rajappa merged 4 commits into
masterfrom
aws-w3c-trace-context-propagation
Oct 29, 2026
Merged

arjun-rajappa merged 4 commits into
masterfrom
aws-w3c-trace-context-propagation

Conversation

@arjun-rajappa

Copy link
Copy Markdown
Contributor

Why

Trace context was only propagated through AWS messaging using the proprietary X-INSTANA-* headers, so services not using the Instana tracer couldn't continue the trace. SQS and SNS also cap messages at 10 message attributes, so adding headers blindly could make a publish fail. Separately, four instrumentations each carried their own copy of a traceparent/tracestate regex, and Shoryuken broke on messages without Instana headers.

What

  • Outbound W3C headers
    • aws_sdk_sqs.rb and aws_sdk_sns.rb inject traceparent and tracestate alongside X_INSTANA_T/S/L.
    • When fewer than 5 of the 10 message attribute slots are free, only the W3C headers are injected.
    • SNS publish_batch is now supported through a shared inject_trace_attributes helper.
    • aws_sdk_lambda.rb adds traceparent and tracestate to the client_context payload and guards against a nil span context.
  • Shared parser: add Instana::Util.parse_w3c_trace_context(traceparent, tracestate) in util.rb.
    • It uses the OpenTelemetry trace-context propagator.
    • It returns nil on invalid input.
    • Otherwise it returns trace_id, span_id, level and the external_* values.
    • The Instana in=<trace>;<span> tracestate entry takes precedence.
    • Metrics/ModuleLength is disabled inline on Instana::Util.
  • Callers: shoryuken.rb, bunny.rb, grpc.rb and active_job.rb replace their duplicated regexes with the shared parser.
  • Shoryuken: falls back to traceparent when X_INSTANA_T is absent, defaults the level to 1, and starts a fresh span when there is no incoming context.
  • Behavior change: the OTel parser is stricter than the old regexes. It accepts uppercase hex, rejects all-zero ids and tolerates trailing fields, and returns nil for malformed headers.
  • Tests: add coverage in test/instrumentation/aws_test.rb and test/instrumentation/shoryuken_test.rb.

Signed-off-by: Arjun Rajappa <arjun.rajappa@ibm.com>
@arjun-rajappa arjun-rajappa self-assigned this Oct 28, 2026
@github-actions

This comment was marked as outdated.

@arjun-rajappa
arjun-rajappa force-pushed the aws-w3c-trace-context-propagation branch 2 times, most recently from c80b00a to db84e3f Compare October 28, 2026 10:25
Signed-off-by: Arjun Rajappa <arjun.rajappa@ibm.com>
@arjun-rajappa
arjun-rajappa force-pushed the aws-w3c-trace-context-propagation branch from db84e3f to 3fe15e4 Compare October 28, 2026 10:27
@arjun-rajappa
arjun-rajappa requested a review from a team October 28, 2026 10:32
…ana_headers

Signed-off-by: Arjun Rajappa <arjun.rajappa@ibm.com>
…Util

Signed-off-by: Arjun Rajappa <arjun.rajappa@ibm.com>
@sonarqubecloud

Copy link
Copy Markdown

@pvital pvital left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me.

@arjun-rajappa
arjun-rajappa merged commit 36e1128 into master Oct 29, 2026
232 checks passed
@arjun-rajappa
arjun-rajappa deleted the aws-w3c-trace-context-propagation branch October 29, 2026 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants