Skip to content

fix(ext/telemetry): otel baggage propagation#31620

Merged
bartlomieju merged 6 commits intomainfrom
fix_otel_baggage
Dec 16, 2025
Merged

fix(ext/telemetry): otel baggage propagation#31620
bartlomieju merged 6 commits intomainfrom
fix_otel_baggage

Conversation

@lucacasonato
Copy link
Copy Markdown
Contributor

@lucacasonato lucacasonato commented Dec 15, 2025

There were three bugs in baggage propagation:

  • BaggageImpl was not reading items from the map passsed in, instead always creating an empty baggage
  • Deno.serve was reading out baggage and storing it in a context, but then not starting the callback in that context, but in the parent context, meaning the user did not have access to the baggage.
  • The baggage was stored on the context with the wrong key.

The gist of it is that propagation.getActiveBaggage() works now.

Secondly, this adds a composite propagator into the global OTEL context, so that propagation.extract() and propagation.inject() start working.

Fixes #28085 and fixes #30064, towards #28082

There were three bugs in baggage propagation:

- `BaggageImpl` was not reading items from the map passsed in, instead always creating an empty baggage
- `Deno.serve` was reading out baggage and storing it in a context, but then not starting the callback in that context, but in the parent context, meaning the user did not have access to the baggage.
- The baggage was stored on the context with the wrong key.

The gist of it is that `propagation.getActiveBaggage()` works now.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 15, 2025

Walkthrough

enterSpan now accepts an optional Context and callers pass an active tracing context when available. Baggage storage was refactored to use a new BAGGAGE_KEY; BaggageImpl now clones entries via SafeMap iteration. W3CBaggagePropagator inject/extract logic changed (removed empty-header early-exit). SafeIterator uses were replaced by SafeArrayIterator. A new CompositePropagator was added and bootstrap propagation wiring now considers configured propagators. Tests add server readiness files, polling-based startup waits, onListen hooks, active-baggage logging, and an HTTP request sending a baggage header userId=alice.

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR partially addresses linked issues: it fixes baggage propagation bugs (#28085, #30064) but lacks Deno.telemetry.addPropagator() API and OTEL_PROPAGATORS env var interpretation required by #28085. Implement Deno.telemetry.addPropagator() API and OTEL_PROPAGATORS environment variable interpretation to fully satisfy #28085 requirements.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main fix: OTEL baggage propagation issues in the telemetry extension.
Description check ✅ Passed The description details three specific baggage propagation bugs fixed and mentions addition of composite propagator, directly relating to the changeset.
Out of Scope Changes check ✅ Passed All changes are scoped to OTEL baggage propagation fixes and composite propagator implementation, directly addressing the PR objectives.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix_otel_baggage

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e2fdefd and 63dd52b.

📒 Files selected for processing (1)
  • ext/telemetry/telemetry.ts (11 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx,js}: For JavaScript runtime debugging, enable V8 inspector with --inspect-brk flag and connect Chrome DevTools to chrome://inspect
Use console.log() for debug prints in JavaScript runtime code

Files:

  • ext/telemetry/telemetry.ts
🪛 Biome (2.1.2)
ext/telemetry/telemetry.ts

[error] 46-46: Do not shadow the global "decodeURIComponent" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)


[error] 47-47: Do not shadow the global "encodeURIComponent" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

🔇 Additional comments (5)
ext/telemetry/telemetry.ts (5)

206-214: LGTM - enables baggage propagation in request handlers.

The optional context parameter allows callers to pass in a context with baggage, fixing the issue where request handlers couldn't access propagated baggage.


1639-1647: Critical fix - baggage entries are now properly cloned.

This fixes the bug where BaggageImpl always created empty baggage. The manual iteration with SafeMapIterator ensures entries are properly copied from the source map.


1690-1690: Critical fix - consistent baggage key across inject/extract.

Introducing a dedicated constant ensures baggage stored during extraction can be retrieved during injection, fixing the wrong-key bug.


1744-1796: LGTM - well-implemented composite propagator.

The implementation correctly aggregates multiple propagators with proper error handling. The extract method threads context through propagators using reduce, and fields are properly deduplicated.


1866-1866: Important fix - enables propagation without tracing/metrics.

The updated condition at line 1866 ensures the otel object is initialized when only propagators are configured, making propagation.extract() and propagation.inject() available even without full tracing/metrics enabled.

Also applies to: 1878-1880


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@bartlomieju bartlomieju enabled auto-merge (squash) December 16, 2025 12:04
@bartlomieju bartlomieju merged commit 4c08a08 into main Dec 16, 2025
20 checks passed
@bartlomieju bartlomieju deleted the fix_otel_baggage branch December 16, 2025 12:12
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.

OTEL propagation.inject doesn't appear to work [otel] interpret OTEL_PROPAGATORS env var, and expose propagators in @opentelemetry/api

2 participants