Chapter 101. OpenTelemetry Since Camel 3.5 The OpenTelemetry component is used for tracing and timing the incoming and outgoing Camel messages using OpenTelemetry . Events (spans) are captured for incoming and outgoing messages that are sent to/from Camel. 101.1. Dependencies Add the following dependency to your pom.xml for this component: <dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-opentelemetry-starter</artifactId> </dependency> 101.2. Configuration The configuration properties for the OpenTelemetry tracer are: Option Default Description excludePatterns Sets exclude pattern(s) that will disable tracing for Camel messages that matches the pattern. The content is a Set<String> where the key is a pattern. The pattern uses the rules from Intercept. encoding false Sets whether the header keys need to be encoded (connector specific) or not. The value is a boolean. Dashes need for instances to be encoded for JMS property keys. 101.2.1. Using Camel OpenTelemetry Add the camel-opentelemetry component in your POM, in addition to any specific dependencies associated with the chosen OpenTelemetry compliant Tracer. To explicitly configure OpenTelemetry support, instantiate the OpenTelemetryTracer and initialize the camel context. You can optionally specify a Tracer , or alternatively it can be implicitly discovered using the Registry import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.trace.Tracer; OpenTelemetryTracer otelTracer = new OpenTelemetryTracer(); // By default it uses the DefaultTracer, but you can override it with a specific OpenTelemetry Tracer implementation. otelTracer.setTracer(...); // And then initialize the context otelTracer.init(camelContext); 101.3. Spring Boot Add the camel-opentelemetry-starter dependency, and then turn on the OpenTracing by annotating the main class with @CamelOpenTelemetry . The OpenTelemetryTracer is implicitly obtained from the camel context's Registry , unless a OpenTelemetryTracer bean has been defined by the application. 101.4. Using tracing strategy The camel-opentelemetry component starter allows you to trace not only the from/to Camel endpoints but also the Java Beans invoked from Camel processor/bean too. By default, Java beans invoked from Camel Processor or bean are categorized as another "span", that is, if user writes .to("bean:beanName?method=methodName") , it will be categorized under the same "span" with the from/to Camel endpoints. To categorize the Java beans invoked from Camel processor/bean under the same "span", you can use the org.apache.camel.opentelemetry.OpenTelemetryTracingStrategy class with the setTracingStrategy() option. import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.trace.Tracer; @Configuration public class CamelOtelConfiguration { public CamelOtelConfiguration(CamelContext camelContext, OpenTelemetryTracer tracer) { var strategy = new OpenTelemetryTracingStrategy(tracer); tracer.setTracingStrategy(strategy); camelContext.getCamelContextExtension().addInterceptStrategy(strategy); } } In case of too much data, you can filter the data by camel.opentelemetry.exclude-patterns property. camel: opentelemetry: exclude-patterns: - ## Set some ID here to filter ## 101.5. Java Agent Download the Java agent . This package includes the instrumentation agent as well as instrumentations for all supported libraries and all available data exporters. The package provides a completely automatic, out-of-the-box experience. Enable the instrumentation agent using the -javaagent flag to the JVM. java -javaagent:path/to/opentelemetry-javaagent.jar \ -jar myapp.jar By default, the OpenTelemetry Java agent uses OTLP exporter configured to send data to OpenTelemetry collector at http://localhost:4317 . Configuration parameters are passed as Java system properties ( -D flags) or as environment variables. See Configuring the agent and OpenTelemetry auto-configuration for the full list of configuration items. For example: java -javaagent:path/to/opentelemetry-javaagent.jar \ -Dotel.service.name=your-service-name \ -Dotel.traces.exporter=jaeger \ -jar myapp.jar 101.6. Spring Boot Auto-Configuration The component supports 2 options, which are listed below. Name Description Default Type camel.opentelemetry.encoding Activate or deactivate the dash encoding in headers (required by JMS) for messaging. Boolean camel.opentelemetry.exclude-patterns Sets exclude pattern(s) that will disable the tracing for the Camel messages that matches the pattern. Set 101.7. MDC Logging When MDC Logging is enabled for the active Camel context, the Trace ID and Span ID are added and removed from the MDC for each route, where the keys are trace_id and span_id , respectively.

Commands:
<dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-opentelemetry-starter</artifactId> </dependency>
import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.trace.Tracer; OpenTelemetryTracer otelTracer = new OpenTelemetryTracer(); // By default it uses the DefaultTracer, but you can override it with a specific OpenTelemetry Tracer implementation. otelTracer.setTracer(...); // And then initialize the context otelTracer.init(camelContext);
import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.trace.Tracer; @Configuration public class CamelOtelConfiguration { public CamelOtelConfiguration(CamelContext camelContext, OpenTelemetryTracer tracer) { var strategy = new OpenTelemetryTracingStrategy(tracer); tracer.setTracingStrategy(strategy); camelContext.getCamelContextExtension().addInterceptStrategy(strategy); } }
camel: opentelemetry: exclude-patterns: - ## Set some ID here to filter ##
java -javaagent:path/to/opentelemetry-javaagent.jar -jar myapp.jar
java -javaagent:path/to/opentelemetry-javaagent.jar -Dotel.service.name=your-service-name -Dotel.traces.exporter=jaeger -jar myapp.jar