open-telemetry / open-telemetry/opentelemetry-java-instrumentation
Add custom javaagent <-> application context bridge to enable custom context propagation
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 2.6k
- Forks
- 1.2k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 228
Description
Is your feature request related to a problem? Please describe.
I'd like to leverage OTel context propagation to propagate my own custom Context scoped-values, similar to io.opentelemetry.api.baggage.Baggage. However, I do not want to use Baggage because the custom values are their own separate logical set of data with their own specific constraints whose propagation I'd like to independently enable or disable (e.g. -Dotel.propagators=tracecontext,baggage,custom or -Dotel.propagators=tracecontext,custom).
I'd also like to read my custom values from an application's Context.current(), which were extracted from a custom header by a custom propagator via an OTel Java agent extension.
However, this doesn't seem to work because the Java agent context is separate from the application context, except for Span and Baggage, which have a ContextKeyBridge.
Describe the solution you'd like
Therefore, I'd like to be able to register a custom ContextKeyBridge in AgentContextWrapper.CONTEXT_KEY_BRIDGES, perhaps similar to how custom propagators are registered, so that my custom Context scoped-values can be shared between agent and application.
Describe alternatives you've considered
- Just use Baggage; however, Baggage allows for any data to be set and propagated. I only want a small set of data with very specific constraints (e.g. a UUID and an Instant).
- It's theoretically possible to (ab)use Baggage to pass data between the Java agent and application contexts; however, it would be messy, leaky, and have unwanted side effects.
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading AgentContextWrapper.java, especially CONTEXT_KEY_BRIDGES and the existing Span and Baggage ContextKeyBridge implementations. Compare this with custom propagator registration and determine how a custom bridge could be registered and exposed to both agent and application contexts; done means the requested custom scoped values can be shared without using Baggage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100