Skip to content

Camel 23283 micrometer span scope#22410

Draft
beskow wants to merge 3 commits intoapache:mainfrom
beskow:CAMEL-23283-micrometer-span-scope
Draft

Camel 23283 micrometer span scope#22410
beskow wants to merge 3 commits intoapache:mainfrom
beskow:CAMEL-23283-micrometer-span-scope

Conversation

@beskow
Copy link
Copy Markdown
Contributor

@beskow beskow commented Apr 2, 2026

Description

Pull request to correct behavior reported in https://issues.apache.org/jira/browse/CAMEL-23283:

When using camel-micrometer-observability, traces and spans are correctly created and exported for routes triggered by other, tracing-aware framework components (e.g. http). If a route is triggered by a jms message, no trace or span is exported however.

This seems to be caused by missing scope management: MicrometerObservabilitySpanAdapter::activate() only calls span.start() but doesn't put the
span into the tracer's thread-local scope. This means tracer.currentSpan() returns null during route execution, hence the span is invisible to downstream instrumentation that relies on tracer.currentSpan() to find a parent span.

The first commit adds a test to highlight the problem.
The second commit corrects the root cause of the problem, but cause side effects for other tests (the async test cases) which leaks trace information between test execution.
The third commit prevents leaked trace information from being propagated.

Target

  • I checked that the commit is targeting the correct branch (Camel 4 uses the main branch)

Tracking

  • If this is a large change, bug fix, or code improvement, I checked there is a JIRA issue filed for the change (usually before you start working on it).

Apache Camel coding standards and style

  • I checked that each commit in the pull request has a meaningful subject line and body.

  • I have run mvn clean install -DskipTests locally from root folder and I have committed all auto-generated changes.

@Croway Croway requested a review from squakez April 2, 2026 15:11
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using build-all, build-dependents, skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

Copy link
Copy Markdown
Contributor

@squakez squakez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this may patch the specific issue but it does not solve the context propagation root cause. We had recently deprecated the older tracing components in favor of the new ones based on a different more consistent context propagation design.

Instead of trying to patch the component (which would require instead to work on the root cause on the core modules) we strongly suggest to move to the new component (in this case camel-micrometer-observability, https://camel.apache.org/components/4.18.x/others/micrometer-observability.html).

@beskow
Copy link
Copy Markdown
Contributor Author

beskow commented Apr 6, 2026

Unfortunately this may patch the specific issue but it does not solve the context propagation root cause. We had recently deprecated the older tracing components in favor of the new ones based on a different more consistent context propagation design.

Instead of trying to patch the component (which would require instead to work on the root cause on the core modules) we strongly suggest to move to the new component (in this case camel-micrometer-observability, https://camel.apache.org/components/4.18.x/others/micrometer-observability.html).

I must be missing something here. This pull request is indeed for the new component (camel-micrometer-observability). The problem I reported manifests itself in both the old (camel-observability) and the new (camel-micrometer-observability) component. I only bothered to try to correct it in the new component.

If this is not the appropriate place to solve the context propagation root cause, I would need some more guidance in finding it.

@squakez
Copy link
Copy Markdown
Contributor

squakez commented Apr 6, 2026

Sorry, I mistakenly thought it was related to camel-observation. I will have a deeper look ASAP, however, the context propagation is something that for this component has to be managed by configuration via OTEL bridge, see https://camel.apache.org/components/4.18.x/others/micrometer-observability.html#_spring_boot_context_propagation - did you already tried that path? the goal of the component is to be agnostic to the specific telemetry technology.

@squakez squakez marked this pull request as draft April 6, 2026 14:34
from("direct:start")
.routeId("start")
.process(exchange -> {
capturedCurrentSpan.set(micrometerTracer.currentSpan());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something you're not allowed to do by design. The point is that, for consistency reasons, Camel has to be seen as a black box and the only context propagation is via standard traceparent (see https://github.com/apache/camel/blob/main/proposals/tracing.adoc#context-propagation)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree you should not call micrometerTracer.currentSpan() in a real route. But this is in the context of a "white-box" unit/integration test: the only purpose of that specific processor is to get the current span (using an API that should not be used in production code) and store it in the AtomicReference<io.micrometer.tracing.Span> capturedCurrentSpan in order to be able to do assertions on the presence and context of the current span in the various test methods. Isn't that a legitimate use? If not, can you recommend another way?

@beskow
Copy link
Copy Markdown
Contributor Author

beskow commented Apr 8, 2026

Sorry, I mistakenly thought it was related to camel-observation. I will have a deeper look ASAP, however, the context propagation is something that for this component has to be managed by configuration via OTEL bridge, see https://camel.apache.org/components/4.18.x/others/micrometer-observability.html#_spring_boot_context_propagation - did you already tried that path? the goal of the component is to be agnostic to the specific telemetry technology.

Yes, I already use the OTEL bridge.

I have prepared a small example project (using SpringBoot, Micrometer and the OTEL bridge) to pinpoint the problems I experience. In doing so, I have also tried to be more precise in the problem report in https://issues.apache.org/jira/browse/CAMEL-23283.

You can find the sample project here: https://issues.apache.org/jira/secure/attachment/13081632/jms-micrometer-observability.zip

Thanks for your help, let me know what I can do to assist further!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants