[ 
https://issues.apache.org/jira/browse/CAMEL-23283?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18073107#comment-18073107
 ] 

Pasquale Congiusti commented on CAMEL-23283:
--------------------------------------------

I've had a deeper look and I think I managed to reproduce. Your original PR 
intuition was good as we really miss to store the context via scope opening 
(this is not needed by Camel, but, may be needed by any custom process like the 
one you're doing). I am working to a transparent fix and documentation. In the 
while, a possible workaround is that you extract the current span from the 
exchange headers (which is Camel consistent storage manager), create a new span 
and close it within the same process execution.

If you use opentelemetry2 directly, then, this use case is already working as 
expected and don't need any workaround.

Stay tuned and thanks for the original work which is serving as reference for 
the final fix.

> OpenTelemetry/Micrometer traces are not correctly structured for 
> JMS-initiated routes
> -------------------------------------------------------------------------------------
>
>                 Key: CAMEL-23283
>                 URL: https://issues.apache.org/jira/browse/CAMEL-23283
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-tracing
>    Affects Versions: 4.15.0, 4.16.0, 4.17.0, 4.18.0, 4.18.1
>            Reporter: Bjorn Beskow
>            Assignee: Pasquale Congiusti
>            Priority: Minor
>             Fix For: 4.20.0
>
>         Attachments: jms-micrometer-observability.zip
>
>
> When using camel-micrometer-observability, traces and spans are not correctly 
> structured if a traceId and root span is not already present (as a result of 
> OTEL context propagation from the caller, or by a Spring Boot framework 
> component in front of the camel component).
> The effect is twofold:
>  * traceId and spanId is not put in the MDC context, and hence not present in 
> any logs created.
>  * Nested spans created programmatically using the Micrometer Observation API 
> are not properly nested (they get their own, unique traceId's).
> The attached sample project pinpoints the problem: For an exchange with a 
> "traceparent" propagated from the caller, everything works as expected. For 
> an exchange without a propagated existing trace, the tests show that the MDC 
> is not properly populated and any nested spans have the wrong structure.
> 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 e.g. 
> programmatic child span creation that relies on tracer.currentSpan() to find 
> a parent span (for example via the ObservationRegistry). It also becomes 
> invisible for the MDC context.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to