CAMEL-23225: Remove ThreadLocal context fallback from camel-opentelemetry2#22255
CAMEL-23225: Remove ThreadLocal context fallback from camel-opentelemetry2#22255
Conversation
…etry2 - Remove BAGGAGE_CAMEL_FLAG / dirty context detection in create() method, always use Context.root() as base for extract() - Remove baggage flag logic and baggageScope from OpenTelemetrySpanAdapter - Delete OpenTelemetryInstrumentedThreadPoolFactory and OpenTelemetryInstrumentedThreadFactoryListener (Context.taskWrapping) - Remove corresponding META-INF service files Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
Analysis of removed code — historical contextChecked git history to verify we're not removing something added for a good reason. Here's what I found: Key commits
Risk assessmentThe By always using However, per the design doc ( Next step: Investigating whether the callers (e.g., Camel Vert.x HTTP component, platform-http) already inject Claude Code on behalf of Guillaume Nodet |
This is not true: #20720 has fixed that problem. |
- Rename SpanInjection → SpanInjectionTest so surefire picks it up (was silently skipped since it didn't match *Test naming convention) - Use traceparent Exchange header instead of ThreadLocal Context.current() to simulate external parent spans, per the design doc - Use setNoParent() when creating test spans to avoid inheriting stale Context.current() state from other test classes (pre-existing issue) - Clear exporter between test methods to prevent inter-test leakage Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Investigation resultsInvestigated the callers to verify Exchange-header-based propagation works end-to-end: How context flows in production
This confirms the design doc's approach works: context propagation via Exchange headers is already the path used by all HTTP components. SpanInjection test fixThe
Root cause of the inter-test failure: Fix applied:
Claude Code on behalf of Guillaume Nodet |
Closing this PRAfter investigation and feedback from @squakez (the camel-opentelemetry2 author), this PR is incorrect:
The one valid fix from this PR: the `SpanInjection` test was never running (class name didn't match surefire `*Test` convention) and tested ThreadLocal propagation instead of header-based. Will submit that as a separate small PR if desired. Claude Code on behalf of Guillaume Nodet |
Summary
Per the tracing design doc (
proposals/tracing.adoc), context propagation should be handled exclusively via Exchange headers (W3Ctraceparent), not ThreadLocal. This PR removes the ThreadLocal-based context propagation mechanisms fromcamel-opentelemetry2:OpenTelemetryTracer.create(): When no Camel parent span exists, always useContext.root()as the base forextract(). Removed theBAGGAGE_CAMEL_FLAG/ "dirty context" detection that fell back toContext.current()— theextract()call on Exchange headers is sufficient to pick up upstream traces.OpenTelemetrySpanAdapter: RemovedBAGGAGE_CAMEL_FLAGconstant, baggage flag injection in constructor, andbaggageScopemanagement. Span scope (makeCurrent()) is kept as it's needed byinject().OpenTelemetryInstrumentedThreadPoolFactoryandOpenTelemetryInstrumentedThreadFactoryListener: These wrapped Camel thread pools withContext.taskWrapping()to propagate ThreadLocal context across threads — contradicting the design principle that context flows via Exchange headers.This is an alternative approach to the Spring Boot
TaskDecoratorin apache/camel-spring-boot#1730 — rather than adding more ThreadLocal propagation infrastructure, this follows the design doc's principle of Exchange-header-only propagation. If this approach is accepted, apache/camel-spring-boot#1730 should be closed as not needed.Test plan
mvn test -B -pl components/camel-opentelemetry2) — they use header-based propagationmvn formatter:format impsort:sort)Claude Code on behalf of Guillaume Nodet
🤖 Generated with Claude Code