Liudmila created CAMEL-18661:
---------------------------------
Summary: Camel OpenTelemtery instrumentation does not make spans
current
Key: CAMEL-18661
URL: https://issues.apache.org/jira/browse/CAMEL-18661
Project: Camel
Issue Type: Bug
Components: camel-opentelemetry
Affects Versions: 3.19.0
Environment: any, functional issue
Reporter: Liudmila
Attachments: camel_and_service_bus.png
I have the following application:
{code:java}
@Component
public class SourceRoute extends EndpointRouteBuilder {
private static final String cs = "...";
@Override
public void configure() {
from(timer("tick").period(1000).repeatCount(1))
.log("Timer triggered")
.setBody(simple("hello"))
.to(azureServicebus("testme").
serviceBusType("topic").
connectionString(cs));
}
} {code}
And I run it with [OpenTelemtery Java
agent|https://github.com/open-telemetry/opentelemetry-java-instrumentation/].
Camel creates "tick" and "testme" spans.
ServiceBus SDK is instrumented too and it creates it's own spans.
h2. Actual behavior:
Spans created by ServiceBus SDK are unrelated to Camel spans. I.e. ServiceBus
spans and Camel spans are in different traces (check out the attached
screenshot).
h2. Expected behavior:
Camel "testme" span is a parent of ServiceBus spans:
* tick
** testme
*** ServiceBus.message
*** ServiceBus.send
h2. Investigation
If I look into the OTel instrumentation code (and debug my application). I can
see that OTel span starts here
https://github.com/apache/camel/blob/1175c2666821457dcb6cf0921f4076508459341a/components/camel-opentelemetry/src/main/java/org/apache/camel/opentelemetry/OpenTelemetryTracer.java#L92
and then is 'activated' here
https://github.com/apache/camel/blob/main/components/camel-tracing/src/main/java/org/apache/camel/tracing/Tracer.java#L248
But the activation code only puts trace_id and span_id on MDC.
The proposal for Camel is to make OpenTelemtery span active (using
Span.makeCurrent()).
This is the only way underlying traces can be correlated to Camel spans.
{code:java}
try (Scope s = span.makeCurrent()) {
// wrap processing, but always clean up the scope to avoid leaks
} {code}
OTel instrumentation will take care of propagating this context anywhere else.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)