Skip to content

Conversation

@zacharycmontoya
Copy link
Contributor

@zacharycmontoya zacharycmontoya commented Dec 9, 2025

Summary of changes

Enable updates to Baggage from either the Datadog Baggage API and the OpenTelemetry Baggage API to be visible to the other.

Relies on #7920 for properly instrumenting the static methods in the OpenTelemetry.Baggage struct.

Reason for change

This allows users of either Baggage API to make changes to the automatically-propagated Baggage header. Before, only changes made through the Datadog Baggage API would be reflected.

Implementation details

Instruments the following methods in the OpenTelemetry Baggage API:

  • static OpenTelemetry.Baggage.ClearBaggage
  • static OpenTelemetry.Baggage.Current { get; set; }
  • static OpenTelemetry.Baggage.RemoveBaggage
  • static OpenTelemetry.Baggage.SetBaggage (2 overloads)

Notably, in the OpenTelemetry model, baggage is immutable, so each operation duplicates the Current baggage (or the one provided in the Baggage argument), modifies it in the specified way, then sets the baggage instance as the new Current before returning.

For this approach, Datadog.Trace.Baggage.Current will be the source of truth for the "current" baggage. First, HTTP server instrumentations will populate Datadog.Trace.Baggage.Current with the contents of the incoming baggage HTTP header. Then, this can be updated via either baggage API. Users of the Datadog Baggage API can directly get the current baggage and modify it. Users of the OpenTelemetry Baggage API will retrieve the baggage using the OpenTelemetry.Baggage.Current, which will now be instrumented to copy over the contents of Datadog.Trace.Baggage.Current into the returned value. Then, if the user wants to update OpenTelemetry.Baggage.Current with an immutable OpenTelemetry.Baggage instance (or indirectly through the other static methods), then the automatic instrumentation will update Datadog.Trace.Baggage.Current to match its contents.

Note: Since the Datadog baggage model is mutable, and users holding a reference to Datadog.Trace.Baggage.Current expect it to be up-to-date, updates from OpenTelemetry.Baggage.set_Current empty the Datadog.Trace.Baggage.Current dictionary and repopulate it.

Test coverage

TODO: Integration test

Other details

Remaining work for this PR: Add a snapshot integration test, likely using the Samples.NetActivitySdk application, by modifying baggage with both API's and persisting the values as span tags so we can assert against them.

…t updates to OpenTelemetry.Baggage.Current are mirrored to Datadog.Trace.Baggage.Current, and vice-versa (though they will only be observed when retrieving the latest OpenTelemetry.Baggage.Current value).
@zacharycmontoya zacharycmontoya changed the title [Tracer] Add interoperability between the Datadog Baggage API and the OpenTelemetry Baggage API [Tracing] Add interoperability between the Datadog Baggage API and the OpenTelemetry Baggage API Dec 9, 2025
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