Out of the box instrumentation

Out of the box instrumentation is available for several frameworks:

FeaturePropertyDefault Value
JDBCotel.instrumentation.jdbc.enabledtrue
Logbackotel.instrumentation.logback-appender.enabledtrue
Spring Webotel.instrumentation.spring-web.enabledtrue
Spring Web MVCotel.instrumentation.spring-webmvc.enabledtrue
Spring WebFluxotel.instrumentation.spring-webflux.enabledtrue
Kafkaotel.instrumentation.kafka.enabledtrue
MongoDBotel.instrumentation.mongo.enabledtrue
Micrometerotel.instrumentation.micrometer.enabledfalse
R2DBC (reactive JDBC)otel.instrumentation.r2dbc.enabledtrue

Turn on instrumentations selectively

To use only specific instrumentations, turn off all the instrumentations first by setting the otel.instrumentation.common.default-enabled property to false. Then, turn on instrumentations one by one.

For example, if you want to only enable the JDBC instrumentation, set otel.instrumentation.jdbc.enabled to true.

Common instrumentation configuration

Common properties for all database instrumentations:

System propertyTypeDefaultDescription
otel.instrumentation.common.db-statement-sanitizer.enabledBooleantrueEnables the DB statement sanitization.

JDBC Instrumentation

System propertyTypeDefaultDescription
otel.instrumentation.jdbc.statement-sanitizer.enabledBooleantrueEnables the DB statement sanitization.

Logback

You can enable experimental features with system properties to capture attributes :

System propertyTypeDefaultDescription
otel.instrumentation.logback-appender.experimental-log-attributesBooleanfalseEnable the capture of experimental log attributes thread.name and thread.id.
otel.instrumentation.logback-appender.experimental.capture-code-attributesBooleanfalseEnable the capture of source code attributes. Note that capturing source code attributes at logging sites might add a performance overhead.
otel.instrumentation.logback-appender.experimental.capture-marker-attributeBooleanfalseEnable the capture of Logback markers as attributes.
otel.instrumentation.logback-appender.experimental.capture-key-value-pair-attributesBooleanfalseEnable the capture of Logback key value pairs as attributes.
otel.instrumentation.logback-appender.experimental.capture-logger-context-attributesBooleanfalseEnable the capture of Logback logger context properties as attributes.
otel.instrumentation.logback-appender.experimental.capture-mdc-attributesStringComma separated list of MDC attributes to capture. Use the wildcard character * to capture all attributes.

Alternatively, you can enable these features by adding the OpenTelemetry Logback appender in your logback.xml or logback-spring.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>
                %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
            </pattern>
        </encoder>
    </appender>
    <appender name="OpenTelemetry"
        class="io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender">
        <captureExperimentalAttributes>false</captureExperimentalAttributes>
        <captureCodeAttributes>true</captureCodeAttributes>
        <captureMarkerAttribute>true</captureMarkerAttribute>
        <captureKeyValuePairAttributes>true</captureKeyValuePairAttributes>
        <captureLoggerContext>true</captureLoggerContext>
        <captureMdcAttributes>*</captureMdcAttributes>
    </appender>
    <root level="INFO">
        <appender-ref ref="console"/>
        <appender-ref ref="OpenTelemetry"/>
    </root>
</configuration>

Spring Web Autoconfiguration

Provides autoconfiguration for the RestTemplate trace interceptor defined in opentelemetry-spring-web-3.1. This autoconfiguration instruments all requests sent using Spring RestTemplate beans by applying a RestTemplate bean post processor. This feature is supported for spring web versions 3.1+. To learn more about the OpenTelemetry RestTemplate interceptor, see opentelemetry-spring-web-3.1.

The following ways of creating a RestTemplate are supported:

package otel;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestTemplateConfig {

  @Bean
  public RestTemplate restTemplate() {
    return new RestTemplate();
  }
}
package otel;

import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class RestTemplateController {

  private final RestTemplate restTemplate;

  public RestTemplateController(RestTemplateBuilder restTemplateBuilder) {
    restTemplate = restTemplateBuilder.rootUri("http://localhost:8080").build();
  }
}

The following ways of creating a RestClient are supported:

package otel;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestClient;

@Configuration
public class RestClientConfig {

  @Bean
  public RestClient restClient() {
    return RestClient.create();
  }
}
package otel;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestClient;

@RestController
public class RestClientController {

  private final RestClient restClient;

  public RestClientController(RestClient.Builder restClientBuilder) {
    restClient = restClientBuilder.baseUrl("http://localhost:8080").build();
  }
}

As it’s possible with the Java agent, you can configure the capture of the following entities:

Spring Web MVC Autoconfiguration

This feature autoconfigures instrumentation for Spring WebMVC controllers by adding a telemetry producing servlet Filter bean to the application context. The filter decorates the request execution with a server span, propagating the incoming tracing context if received in the HTTP request. To learn more about the OpenTelemetry Spring WebMVC instrumentation, see the opentelemetry-spring-webmvc-5.3 instrumentation library.

As it’s possible with the Java agent, you can configure the capture of the following entities:

Spring WebFlux Autoconfiguration

Provides autoconfigurations for the OpenTelemetry WebClient ExchangeFilter defined in opentelemetry-spring-webflux-5.3. This autoconfiguration instruments all outgoing HTTP requests sent using Spring’s WebClient and WebClient Builder beans by applying a bean post processor. This feature is supported for spring webflux versions 5.0+. For details, see opentelemetry-spring-webflux-5.3.

The following ways of creating a WebClient are supported:

package otel;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.WebClient;

@Configuration
public class WebClientConfig {

  @Bean
  public WebClient webClient() {
    return WebClient.create();
  }
}
package otel;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.client.WebClient;

@RestController
public class WebClientController {

  private final WebClient webClient;

  public WebClientController(WebClient.Builder webClientBuilder) {
    webClient = webClientBuilder.baseUrl("http://localhost:8080").build();
  }
}

Kafka Instrumentation

Provides autoconfiguration for the Kafka client instrumentation.

System propertyTypeDefaultDescription
otel.instrumentation.kafka.experimental-span-attributesBooleanfalseEnables the capture of experimental span attributes.

Micrometer Instrumentation

Provides autoconfiguration for the Micrometer to OpenTelemetry bridge.

MongoDB Instrumentation

Provides autoconfiguration for the MongoDB client instrumentation.

System propertyTypeDefaultDescription
otel.instrumentation.mongo.statement-sanitizer.enabledBooleantrueEnables the DB statement sanitization.

R2DBC Instrumentation

Provides autoconfiguration for the OpenTelemetry R2DBC instrumentation.

System propertyTypeDefaultDescription
otel.instrumentation.r2dbc.statement-sanitizer.enabledBooleantrueEnables the DB statement sanitization.

Dernière modification July 24, 2024: Include Java example code excerpts (#4642) (99dfcdeb)