Skip to content

feat: native AWS X-Ray propagator and ID generator support#46

Merged
jstojiljkovic merged 4 commits into
tracewayapp:masterfrom
FrameAutomata:feat/AWS_XRay_Support
May 29, 2026
Merged

feat: native AWS X-Ray propagator and ID generator support#46
jstojiljkovic merged 4 commits into
tracewayapp:masterfrom
FrameAutomata:feat/AWS_XRay_Support

Conversation

@FrameAutomata

@FrameAutomata FrameAutomata commented May 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds propagator: xray and propagator: w3c+xray config options that swap the global TextMapPropagator for AWS X-Ray's X-Amzn-Trace-Id header format (or both headers simultaneously for gradual migrations)
  • Adds id_generator: xray that builds a TracerProvider using the SDK's env-var auto-configuration factories plus XRayIdGenerator, producing epoch-prefixed trace IDs that X-Ray's UI renders as timestamps
  • Both options require open-telemetry/contrib-aws (added to suggest); the bundle throws a clear LogicException at container boot if the package is absent

How it works

A new XRayBootstrapper service registers a Globals::registerInitializer callback in its constructor, then subscribes to kernel.request and console.command at PHP_INT_MAX priority. This forces Symfony to construct the service — and therefore queue the initializer — before OpenTelemetrySubscriber (priority 256) or ConsoleSubscriber (priority 128) call Globals::tracerProvider() for the first time. All existing instrumentation (HTTP, HttpClient, Messenger, Doctrine, etc.) picks up the X-Ray propagator and ID generator automatically because every subscriber goes through Globals::propagator() and Globals::tracerProvider().

Usage

composer require open-telemetry/contrib-aws
# config/packages/open_telemetry.yaml
open_telemetry:
  propagator: xray       # inject/extract X-Amzn-Trace-Id headers
  id_generator: xray     # epoch-prefixed trace IDs recognised by X-Ray UI

Point OTEL_EXPORTER_OTLP_ENDPOINT at your ADOT Collector as usual — the exporter is configured from env vars the same way as before.

Tests

All 560 existing tests pass. 28 new tests are added across three files:

  • ConfigurationTest — valid/invalid values for both new config keys, correct defaults
  • BundleBootTest — default config registers no bootstrapper; missing package throws LogicException at boot; all three propagator modes and id_generator: xray register XRayBootstrapper
  • XRayBootstrapperTest — propagator injection produces X-Amzn-Trace-Id headers; extraction parses incoming X-Ray headers into the correct span context; id_generator: xray produces 32-char hex trace IDs whose first 8 chars decode to a plausible Unix timestamp

The XRayBootstrapperTest cases currently skip (they are marked with markTestSkipped when open-telemetry/contrib-aws is absent from dev deps). Adding the package to require-dev in CI will make them live.

Closes #7

🤖 Generated with Claude Code

@jstojiljkovic

jstojiljkovic commented May 19, 2026

Copy link
Copy Markdown
Collaborator

@FrameAutomata
Thanks for the PR, can we resolve conflicts, and then I will merge this?

FrameAutomata and others added 2 commits May 19, 2026 15:21
Adds two new bundle config options:

  open_telemetry:
    propagator: xray        # w3c (default) | xray | w3c+xray
    id_generator: xray      # default | xray

Both require open-telemetry/contrib-aws (added to suggest).

XRayBootstrapper registers a Globals::registerInitializer callback and
subscribes to kernel.request / console.command at PHP_INT_MAX priority
so it is constructed — and the callback queued — before
OpenTelemetrySubscriber (priority 256) or ConsoleSubscriber (priority 128)
first access the OTel globals.

propagator: xray swaps the global TextMapPropagator for XRayPropagator,
causing all context injection / extraction (HTTP, Messenger, HttpClient)
to use the X-Amzn-Trace-Id header automatically. w3c+xray writes both
headers via MultiTextMapPropagator, useful during a migration.

id_generator: xray builds a TracerProvider using the SDK's auto-
configuration factories (ExporterFactory, SamplerFactory,
SpanProcessorFactory — all driven by OTEL_* env vars as usual) and
passes XRayIdGenerator as the fifth TracerProvider constructor argument,
producing epoch-prefixed 32-char hex trace IDs that X-Ray's UI
recognises as timestamps.

Closes tracewayapp#7

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@FrameAutomata
FrameAutomata force-pushed the feat/AWS_XRay_Support branch from 77def36 to 242220c Compare May 19, 2026 20:24
…yExtension

PHPStan level 10 flagged missing keys in the traces array type annotation
after the config moved from flat root keys to traces.propagator / traces.id_generator.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@FrameAutomata

Copy link
Copy Markdown
Contributor Author

@jstojiljkovic Try now.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 86.56716% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/XRay/XRayBootstrapper.php 81.57% 7 Missing ⚠️
src/DependencyInjection/OpenTelemetryExtension.php 84.61% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@jstojiljkovic

Copy link
Copy Markdown
Collaborator

Thanks for the thorough work on this @FrameAutomata. CI is green, merging now. 🙇

@jstojiljkovic
jstojiljkovic merged commit e4f5ebc into tracewayapp:master May 29, 2026
7 checks passed
@FrameAutomata
FrameAutomata deleted the feat/AWS_XRay_Support branch May 29, 2026 21:22
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.

[Feature] Add support for AWS XRay

3 participants