opentelemetry-java-instrume.../instrumentation/spring/spring-webflux-5.0/library
Trask Stalnaker 05471b053b
Webflux instrumentation fix (#7251)
When a webflux filter is added which throws an exception, the
instrumentation does not currently capture the `http.status_code`.

The fix is to move `WebClientTracingFilter` from the first to the last
filter in the chain, which I think(?) is the general strategy we've
taken for other client instrumentation, e.g. so that if a filter makes
another http call it won't be suppressed.

I don't love the test coverage I added, so let me know if you have any
better suggestions?

EDIT: btw, I did archaeology to confirm that behavior (adding to the
beginning of the chain) has been in place since the webflux
instrumentation was added originally
6f472a62a0 (diff-493ad89b5bde807c90387aa2bb67eb10d3bcef6b6a388bd31e11796a6d01ac38R36)
2022-11-22 15:09:22 -08:00
..
src/main/java/io/opentelemetry/instrumentation/spring/webflux/client Webflux instrumentation fix (#7251) 2022-11-22 15:09:22 -08:00
NOTICE.txt Reactor bugs (#1189) 2020-09-15 09:57:03 +09:00
README.md Introduce markdown lint check (#7175) 2022-11-16 20:48:42 -08:00
build.gradle.kts Migrate instrumentation gradle files to kotlin (#3414) 2021-06-28 17:27:12 +09:00

README.md

Library Instrumentation for Spring Webflux version 5.0 and higher

Provides OpenTelemetry instrumentation for Spring's WebClient.

Quickstart

Add these dependencies to your project

Replace SPRING_VERSION with the version of spring you're using. Minimum version: 5.0

Replace OPENTELEMETRY_VERSION with the latest release.

For Maven, add to your pom.xml dependencies:

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

   <!-- opentelemetry exporter -->
   <!-- replace this default exporter with your opentelemetry exporter (ex. otlp/zipkin/jaeger/..) -->
   <dependency>
    <groupId>io.opentelemetry</groupId>
    <artifactId>opentelemetry-exporter-logging</artifactId>
    <version>OPENTELEMETRY_VERSION</version>
  </dependency>

  <!-- required to instrument spring-webflux -->
  <!-- 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:

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

// opentelemetry exporter
// replace this default exporter with your opentelemetry exporter (ex. otlp/zipkin/jaeger/..)
implementation("io.opentelemetry:opentelemetry-exporter-logging:OPENTELEMETRY_VERSION")

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

Features

SpringWebfluxTracing

SpringWebfluxTracing emits client span for each request sent using WebClient by implementing the ExchangeFilterFunction interface. An example is shown below:

Usage

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.instrumentation.spring.webflux.client.SpringWebfluxTracing;

import org.springframework.beans.factory.annotation.Autowired;
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.Builder webClient(OpenTelemetry openTelemetry) {

      WebClient webClient = WebClient.create();
      SpringWebfluxTracing instrumentation = SpringWebfluxTracing.create(openTelemetry);

      return webClient.mutate().filters(instrumentation::addClientTracingFilter);
   }
}

Starter Guide

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