此内容没有您所选择的语言版本。

Chapter 243. OpenTracing Component


Available as of Camel 2.19

Important

Starting with Camel 2.21, it will be necessary to use an OpenTracing complaint tracer that is compatible with OpenTracing Java API version 0.31 or higher.

The camel-opentracing component is used for tracing and timing incoming and outgoing Camel messages using OpenTracing.

Events (spans) are captured for incoming and outgoing messages being sent to/from Camel.

See the OpenTracing website for a list of supported tracers.

243.1. Configuration

The configuration properties for the OpenTracing tracer are:

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.

There are three ways in which an OpenTracing tracer can be configured to provide distributed tracing for a Camel application:

243.1.1. Explicit

Include the camel-opentracing component in your POM, along with any specific dependencies associated with the chosen OpenTracing compliant Tracer.

To explicitly configure OpenTracing support, instantiate the OpenTracingTracer and initialize the camel context. You can optionally specify a Tracer, or alternatively it can be implicitly discovered using the Registry or ServiceLoader.

OpenTracingTracer ottracer = new OpenTracingTracer();
// By default it uses a Noop Tracer, but you can override it with a specific OpenTracing implementation.
ottracer.setTracer(...);
// And then initialize the context
ottracer.init(camelContext);

To use OpenTracingTracer in XML, all you need to do is to define the OpenTracing tracer beans. Camel will automatically discover and use them.

  <bean id="tracer" class="..."/>
  <bean id="ottracer" class="org.apache.camel.opentracing.OpenTracingTracer">
    <property name="tracer" ref="tracer"/>
  </bean>

243.1.2. Spring Boot

If you are using Spring Boot then you can add the camel-opentracing-starter dependency, and turn on OpenTracing by annotating the main class with @CamelOpenTracing.

The Tracer will be implicitly obtained from the camel context’s Registry, or the ServiceLoader, unless a Tracer bean has been defined by the application.

243.1.3. Java Agent

The third approach is to use a Java Agent to automatically configure the OpenTracing support.

Include the camel-opentracing component in your POM, along with any specific dependencies associated with the chosen OpenTracing compliant Tracer.

The OpenTracing Java Agent is associated with the following dependency:

    <dependency>
      <groupId>io.opentracing.contrib</groupId>
      <artifactId>opentracing-agent</artifactId>
    </dependency>

The Tracer used will be implicitly loaded from the camel context Registry or using the ServiceLoader.

How this agent is used will be specific to how you execute your application. Service2 in the camel-example-opentracing downloads the agent into a local folder and then uses the exec-maven-plugin to launch the service with the -javaagent command line option.

243.2. Example

You can find an example demonstrating the three ways to configure OpenTracing here: camel-example-opentracing

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.