[Tracing] Add interoperability between the Datadog Baggage API and the OpenTelemetry Baggage API #7921
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.Baggagestruct.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.ClearBaggagestatic OpenTelemetry.Baggage.Current { get; set; }static OpenTelemetry.Baggage.RemoveBaggagestatic OpenTelemetry.Baggage.SetBaggage(2 overloads)Notably, in the OpenTelemetry model, baggage is immutable, so each operation duplicates the
Currentbaggage (or the one provided in theBaggageargument), modifies it in the specified way, then sets the baggage instance as the newCurrentbefore returning.For this approach,
Datadog.Trace.Baggage.Currentwill be the source of truth for the "current" baggage. First, HTTP server instrumentations will populateDatadog.Trace.Baggage.Currentwith the contents of the incomingbaggageHTTP 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 theOpenTelemetry.Baggage.Current, which will now be instrumented to copy over the contents ofDatadog.Trace.Baggage.Currentinto the returned value. Then, if the user wants to updateOpenTelemetry.Baggage.Currentwith an immutableOpenTelemetry.Baggageinstance (or indirectly through the other static methods), then the automatic instrumentation will updateDatadog.Trace.Baggage.Currentto match its contents.Note: Since the Datadog baggage model is mutable, and users holding a reference to
Datadog.Trace.Baggage.Currentexpect it to be up-to-date, updates fromOpenTelemetry.Baggage.set_Currentempty theDatadog.Trace.Baggage.Currentdictionary and repopulate it.Test coverage
TODO: Integration test
Other details
Remaining work for this PR: Add a snapshot integration test, likely using the
Samples.NetActivitySdkapplication, by modifying baggage with both API's and persisting the values as span tags so we can assert against them.