Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Information to TraceState Without Creating Span #6456

Open
tduncan opened this issue May 13, 2024 · 1 comment
Open

Add Information to TraceState Without Creating Span #6456

tduncan opened this issue May 13, 2024 · 1 comment
Labels
Feature Request Suggest an idea for this project

Comments

@tduncan
Copy link

tduncan commented May 13, 2024

Is your feature request related to a problem? Please describe.
I'm in need of a way to modify the trace state to add a custom key/value pair.

From what I can tell adding information to the TraceState requires either 1) hooking into the trace sampling mechanism or 2) creating a new span. Outside of those two use cases there does not appear to be a way to modify the trace state. My use case a custom SpanProcessor within an agent extension so neither of the above use cases applies.

Describe the solution you'd like
A mechanism to append information to the trace state without creating a new Span. Perhaps a addToTraceState method could be added to the ReadWriteSpan interface so the details of modifying the internal TraceState field could be encapsulated and the integrity of the TraceState protected.

Describe alternatives you've considered
There does not appear to be an alternative way to modify the trace state within the Java SDK. Currently the Context is used to propagate information to downstream services, but my understanding is the Context fields are not guaranteed to be retained if the custom extension I'm developing is not configured on a intermediary service.

Additional context
I'm attempting to develop a custom agent extension in which a decision made when considering the root span needs to be available to all participating services downstream in the trace. At the moment the extension is implemented as a custom SpanProcessor where the decision is made and TextMapPropagator where the information encoded/decoded using the Context as necessary. This setup works but does require every participating service to be configured to use the custom extension. It would be ideal if the information could be retained in the event that a service is not using the custom extension.

Other language implementations do allow for explicit modification of the trace state. See golang for a specific example.

@tduncan tduncan added the Feature Request Suggest an idea for this project label May 13, 2024
@jkwatson
Copy link
Contributor

This sounds like more a use-case for Baggage, rather than trying to modify the TraceState.

It is unlikely that we would allow the Java TraceState to be mutable without a preponderance of evidence that there is a use-case for it from multiple sources. Your is the first ask I have seen for this. I recommend using Baggage for this sort of operation, as it can be propagated whether or not there is a Span at all in the Context, rather than trying to put something into the W3C TraceState.

Note this comment in the Javadoc for TraceState:

 * <p>Implementations of this interface *must* be immutable and have well-defined value-based
 * equals/hashCode implementations. If an implementation does not strictly conform to these
 * requirements, behavior of the OpenTelemetry APIs and default SDK cannot be guaranteed.

Changing this requirement for immutability would potentially be a breaking change, and would necessitate going to version 2 of the APIs, which we would like to avoid at all reasonable cost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Suggest an idea for this project
Projects
None yet
Development

No branches or pull requests

2 participants