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

Thomas Gantenbein commented on CAMEL-21472:
-------------------------------------------

Actually, forget about those lines regarding the MDC context: They are not 
necessary. I think I included them when I had not yet set 
`builder.setNoParent()` and was surprised to still find the same traceId in the 
logs. But it wasn't about the MDC context, it was about that 
`builder.setNoParent()`. Removing traceId from MDC seems to be done as expected 
(at least: expected by {_}me{_}) in ActiveSpanManager.

And I agree that this "fix" is counterintuitive. Also, it will work, I guess, 
for cases were messages originate from Camel, but it will not work if another 
service calls Camel, for example, with an existing traceId in a HTTP header: 
we'd start a new traceId, which is certainly not what's expected.

The span seems to be ended in 
[https://github.com/apache/camel/blob/main/components/camel-tracing/src/main/java/org/apache/camel/tracing/Tracer.java#L328,]
 but maybe we'd have to check there if there is no parent span and, if so, 
clear the context – no idea how that is done exactly. It seems to me that the 
"context" of a trace is stored in ThreadLocalStorage and by calling 
Span.fromContext(ctx), that information is restored when a new exchange is 
started – including the traceId from a previous trace processed on the same 
thread.

Anyway, [~squakez], if you prefer to work on this by yourself I'll let you do 
your work and not disturb. If you appreciate comments like these and 
suggestions, I'll continue to try out things if I find time.

> Opentelemetry is using the same traceId when exchange is fired from file or 
> timer component
> -------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-21472
>                 URL: https://issues.apache.org/jira/browse/CAMEL-21472
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-opentelemetry
>    Affects Versions: 4.8.1
>            Reporter: Thomas Gantenbein
>            Assignee: Pasquale Congiusti
>            Priority: Major
>             Fix For: 4.8.2, 4.9.0
>
>         Attachments: image-2024-11-26-09-59-35-555.png
>
>
> *Problem*
> When using a consumer like {{timer}} or {{{}file{}}}, the traceId remains the 
> same for all messages. When using a consumer like netty (or, I assume, any 
> other http/tcp-based consumer), every call gets its own traceId as expected.
> See also 
> https://camel.zulipchat.com/#narrow/channel/257298-camel/topic/Same.20OTEL.20trace.20for.20all.20messages.20into.20IBM.20MQ
> *Reproducer*
> [https://github.com/thomas-gantenbein-tga/camel-opentelemetry/tree/main]
> [~pcongiusti], thanks for your answer on Zulip Chat. Let me know if I should 
> further explain or minimize that reproducer.



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

Reply via email to