Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Library Instrumentation for Spring Webflux

Provides OpenTelemetry instrumentation for Spring's WebClient and Webflux server.

For this instrumentation, the minimum supported version of Spring Webflux is 5.3.0.

Add dependencies to your project

For Maven, add to your pom.xml:

<dependencies>
  <dependency>
    <groupId>io.opentelemetry.instrumentation</groupId>
    <artifactId>opentelemetry-spring-webflux-5.3</artifactId>
    <version>OPENTELEMETRY_VERSION</version>
  </dependency>

  <!-- This artifact should already be present in your application -->
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webflux</artifactId>
    <version>SPRING_VERSION</version>
  </dependency>
</dependencies>

For Gradle, add to your dependencies:

implementation("io.opentelemetry.instrumentation:opentelemetry-spring-webflux-5.3:OPENTELEMETRY_VERSION")

// this artifact should already be present in your application
implementation("org.springframework:spring-webflux:SPRING_VERSION")

Features

SpringWebfluxTelemetry can emit a client span for each request sent using WebClient by implementing the ExchangeFilterFunction interface.

SpringWebfluxTelemetry can also emit a server span for each request received, by implementing a WebFilter and using the OpenTelemetry Reactor instrumentation to ensure context is passed around correctly.

Web client instrumentation

The WebClient instrumentation will emit the error.type attribute with value cancelled whenever an outgoing HTTP request is cancelled.

Setup

Here is how to set up client and server instrumentation respectively:

import io.opentelemetry.instrumentation.spring.webflux.v5_3.SpringWebfluxTelemetry;

@Configuration
public class WebClientConfig {
  private final SpringWebfluxTelemetry webfluxTelemetry;

  public WebClientConfig(OpenTelemetry openTelemetry) {
    this.webfluxTelemetry = SpringWebfluxTelemetry.builder(openTelemetry).build();
  }

  // Adds instrumentation to WebClients
  @Bean
  public WebClient.Builder webClient() {
    WebClient webClient = WebClient.create();
    return webClient.mutate().filters(webfluxTelemetry::addClientTracingFilter);
  }

  // Adds instrumentation to Webflux server
  @Bean
  public WebFilter webFilter() {
    return webfluxTelemetry.createWebFilterAndRegisterReactorHook();
  }
}

Starter Guide

Check out OpenTelemetry Manual Instrumentation to learn more about using the OpenTelemetry API to instrument your code.