이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 110. 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.

110.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>
Copy to Clipboard Toggle word wrap

110.2. Configuration properties

The configuration properties for the OpenTelemetry tracer are:

Expand
OptionDefaultDescription

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.

110.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);
Copy to Clipboard Toggle word wrap

110.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.

110.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);
  }
}
Copy to Clipboard Toggle word wrap

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 ##
Copy to Clipboard Toggle word wrap

110.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
Copy to Clipboard Toggle word wrap

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
Copy to Clipboard Toggle word wrap

110.6. Adding the RouteID attribute to the span

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:

import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.tracing.SpanAdapter;
import org.apache.camel.tracing.decorators.DirectSpanDecorator;

public class RouteIDSpanDecorator extends DirectSpanDecorator {

    @Override
    public void pre(SpanAdapter span, Exchange exchange, Endpoint endpoint) {
        super.pre(span, exchange, endpoint);
        span.setTag("camel.route.id", exchange.getFromRouteId());
    }
}
Copy to Clipboard Toggle word wrap

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.

110.7. Spring Boot Auto-Configuration

The component supports 2 options, which are listed below.

Expand
NameDescriptionDefaultType

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

110.8. MDC Logging

Note

Mapped Diagnostic Context (MDC) logging is a deprecated feature that may disappear in future version of the project.

The Mapped Diagnostic Context (MDC) feature can be enabled using the specific tracing/telemetry framework SDK. For details, see the documentation for the tracing component you are using.

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.

Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2026 Red Hat
맨 위로 이동