Hello, if you're running the component with camel-main runtime, then, the things are a bit trickier. Please, have a look at the section about how to enable opentelemetry in camel main documentation [1]. You can notice that there is an additional dependency you need to provide and also some flag to be enabled on the agent. You're also using the variables %X{trace_id} and %X{span_id}, but when you're using the MDC configuration provided by the opentelemetry, then they really are %X{traceId} and %X{spanId}
Cheers, Pasquale. [1] https://camel.apache.org/components/next/others/opentelemetry.html#_using_with_standalone_camel On Wed, Feb 5, 2025 at 5:06 PM Mikael Koskinen <mijap...@gmail.com> wrote: > Hi Pasquale, > > Thank you for the quick response and sorry for missing the earlier > discussion. > > I read through the documentation you linked and unfortunately had no luck > setting this up. I'll try again but if someone has the time and energy to > point out where I'm missing a step, it is appreciated: > > application.properties: > > > camel.jbang.dependencies=camel:opentelemetry,agent:io.opentelemetry.javaagent:opentelemetry-javaagent:1.31.0,io.opentelemetry.instrumentation:opentelemetry-log4j-context-data-2.17-autoconfigure:1.31.0-alpha > camel.opentelemetry.enabled=true > > exporting: > > camel export --runtime=camel-main --gav=com.foo:acme:1.0-SNAPSHOT > --directory=./publish * > > modified src/main/resources/log4j2.properties and copied the example from > docs: > > appender.stdout.layout.pattern = %d{HH:mm:ss.SSS} [%t] %-5level > %logger{36} trace_id=%X{trace_id} span_id=%X{span_id} > trace_flags=%X{trace_flags} - %msg%n > > testing: > > ./mvnw clean package > java -javaagent:agent/opentelemetry-javaagent-1.31.0.jar > -Dcamel.jbang.version=4.8.3 -Dotel.traces.exporter=none > -Dotel.metrics.exporter=none -Dotel.logs.exporter=otlp > -Dotel.exporter.otlp.endpoint=http://localhost:4317 > -Dotel.exporter.otlp.protocol=grpc -Dotel.service.name=otel-test > -Dotel.service.version=1.0.0 > -Dotel.service.instance.id=91c4e045-5fbd-4611-8fef-22eb079fb519 > -Dotel.instrumentation.log4j-context-data.add-baggage=true -jar > target/acme-1.0-SNAPSHOT.jar > > result: > > OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader > classes because bootstrap classpath has been appended > [otel.javaagent 2025-02-05 18:01:57:196 +0200] [main] INFO > io.opentelemetry.javaagent.tooling.VersionLogger - opentelemetry-javaagent > - version: 1.31.0 > 18:01:58.362 [main] INFO org.apache.camel.main.MainSupport trace_id= > span_id= trace_flags= - Apache Camel (Main) 4.9.0 is starting > 18:01:58.448 [main] INFO org.apache.camel.main.BaseMainSupport trace_id= > span_id= trace_flags= - Classpath scanning enabled from base package: > com.foo.acme > 18:01:59.083 [main] INFO org.apache.camel.main.BaseMainSupport trace_id= > span_id= trace_flags= - Auto-configuration summary > 18:01:59.083 [main] INFO org.apache.camel.main.BaseMainSupport trace_id= > span_id= trace_flags= - [application.properties] > camel.main.basePackageScan = com.foo.acme > 18:01:59.083 [main] INFO org.apache.camel.main.BaseMainSupport trace_id= > span_id= trace_flags= - [application.properties] > camel.opentelemetry.enabled = true > 18:01:59.403 [main] INFO org.apache.camel.impl.engine.AbstractCamelContext > trace_id= span_id= trace_flags= - Apache Camel 4.9.0 (camel-1) is starting > 18:01:59.405 [main] INFO > org.apache.camel.opentelemetry.OpenTelemetryTracer trace_id= span_id= > trace_flags= - OpenTelemetryTracer enabled using instrumentation-name: > camel > 18:01:59.405 [main] INFO org.apache.camel.impl.engine.AbstractCamelContext > trace_id= span_id= trace_flags= - Using ThreadPoolFactory: > > org.apache.camel.opentelemetry.OpenTelemetryInstrumentedThreadPoolFactory@984de01 > 18:01:59.408 [main] INFO org.apache.camel.main.BaseMainSupport trace_id= > span_id= trace_flags= - Property-placeholders summary > 18:01:59.408 [main] INFO org.apache.camel.main.BaseMainSupport trace_id= > span_id= trace_flags= - [application.properties] > AdditionalMessage = This message comes from the application.properties > 18:01:59.408 [main] INFO org.apache.camel.impl.engine.AbstractCamelContext > trace_id= span_id= trace_flags= - Routes startup (total:1) > 18:01:59.409 [main] INFO org.apache.camel.impl.engine.AbstractCamelContext > trace_id= span_id= trace_flags= - Started route1 (timer://yaml) > 18:01:59.409 [main] INFO org.apache.camel.impl.engine.AbstractCamelContext > trace_id= span_id= trace_flags= - Apache Camel 4.9.0 (camel-1) started in > 5ms (build:0ms init:0ms start:5ms boot:1s14ms) > 18:02:00.434 [Camel (camel-1) thread #2 - timer://yaml] INFO route1 > trace_id= span_id= trace_flags= - Hello This message comes from the > application.properties > 18:02:03.909 [Camel (camel-1) thread #2 - timer://yaml] INFO route1 > trace_id= span_id= trace_flags= - Hello This message comes from the > application.properties > > And this how the collector gets things: > > LogRecord #0 > ObservedTimestamp: 2025-02-05 16:04:29.483556871 +0000 UTC > Timestamp: 2025-02-05 16:04:29.483552147 +0000 UTC > SeverityText: INFO > SeverityNumber: Info(9) > Body: Str(Hello This message comes from the application.properties) > Trace ID: > Span ID: > Flags: 0 > > ke 5.2.2025 klo 16.07 Pasquale Congiusti (pasquale.congiu...@gmail.com) > kirjoitti: > > > Hi Mikael, > > we discussed about it some times ago in the dev mailing list. The feature > > is deprecated as it is not working correctly due to the specific way each > > telemetry is implemented [1]. However you can always use the specific > > opentelemetry way to do that [2]. > > > > Cheers, > > Pasquale. > > > > [1] > > > https://camel.apache.org/components/next/others/tracing.html#_mdc_logging > > [2] > > > > > https://camel.apache.org/components/next/others/opentelemetry.html#_mdc_logging > > > > On Wed, Feb 5, 2025 at 2:11 PM Mikael Koskinen <mijap...@gmail.com> > wrote: > > > > > Hi, > > > > > > Enabling OpenTelemetry in Camel Main is straightforward, thanks to the > > good > > > documentation on Camel JBang's page. I get telemetry, metrics and logs > > > moving. > > > > > > But I have a problem with the logs that the OTEL Collector receives. > The > > > logs are missing trace and span ids. I have enabled mdc logging in > > > application.properties: > > > > > > > > > > > > *camel.main.useMdcLogging* > > > And I can see the span_id and trace_id when json logging is enabled: > > > > > > > > > > > > {"@timestamp":"2025-02-05T12:06:39.095Z","ecs.version":"1.2.0","log.level":"INFO","message":"Hello > > > This message comes from the > > > application.properties","process.thread.name":"Camel > > > (camel-1) thread #4 - > > > > > > > > > timer://yaml","log.logger":"integration.camel.yaml:8","camel.contextId":"otel-test","camel.exchangeId":"FBC40ADA8D08EAB-0000000000000002","camel.messageId":"FBC40ADA8D08EAB-0000000000000002","camel.routeId":"route1","span_id":"6a0dbd5a9773d891","trace_id":"b3499efd42a7ec8971ff04cc19f08d3a"} > > > > > > But on the OTEL Collector side span_id and trace_id are both empty. > > > > > > I enabled OTEL Java Agent's debugging and it displays the following: > > > > > > [otel.javaagent 2025-02-05 14:06:39:096 +0200] [Camel (camel-1) thread > > #4 - > > > timer://yaml] INFO > io.opentelemetry.exporter.logging.LoggingSpanExporter > > - > > > 'timer' : b3499efd42a7ec8971ff04cc19f08d3a 6a0dbd5a9773d891 SERVER > > [tracer: > > > camel:] AttributesMap{data={url.path=yaml, component=camel-timer, > > > url.query=period=3500, thread.id=39, > camel.uri=timer://yaml?period=3500, > > > thread.name=Camel (camel-1) thread #4 - timer://yaml, > url.scheme=timer}, > > > capacity=128, totalAddedValues=7} > > > > > > I'm not sure if that is correct. Should the AttributesMap contain the > > > span_id and trace_id? I'm using the Camel LTS version. > > > > > > I would really appreciate it if anyone has any ideas on how to get > > trace_id > > > and span_id correctly to work for logs. > > > > > > Best regards, > > > Mikael > > > > > >