Chapter 108. 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.
108.1. Dependencies Copy linkLink copied to clipboard!
Add the following dependency to your pom.xml for this component:
<dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-opentelemetry-starter</artifactId> </dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-opentelemetry-starter</artifactId>
</dependency>
108.2. Configuration properties Copy linkLink copied to clipboard!
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. |
108.2.1. Using Camel OpenTelemetry Copy linkLink copied to clipboard!
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
108.3. Spring Boot Copy linkLink copied to clipboard!
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.
108.4. Using tracing strategy Copy linkLink copied to clipboard!
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.
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 ##
camel:
opentelemetry:
exclude-patterns:
- ## Set some ID here to filter ##
108.5. Java Agent Copy linkLink copied to clipboard!
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
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-configurationfor 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
java -javaagent:path/to/opentelemetry-javaagent.jar \
-Dotel.service.name=your-service-name \
-Dotel.traces.exporter=jaeger \
-jar myapp.jar
108.6. Adding the RouteID attribute to the span Copy linkLink copied to clipboard!
To identify the origin of the Route, it is necessary to add the RouteID attribute to the span. The workaround is to use the Span decorator from Camel. For this, add a custom decorator for each component you want to enrich with the route id. For example, if you want to print the route id in the direct component, the implementation is as follows:
Add the file named org.apache.camel.tracing.SpanDecorator to src/main/resources/META-INF/services folder which contains the reference of the class . (for example, com.redhat.xxxx.RouteIDSpanDecorator). This allows the Camel tracing feature to load the custom Span decorator with the tag applied in the trace.
108.7. Spring Boot Auto-Configuration Copy linkLink copied to clipboard!
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 |
108.8. MDC Logging Copy linkLink copied to clipboard!
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.