opentelemetry-java-instrume.../instrumentation/spring/spring-webmvc-3.1/library
Mateusz Rzeszutek b2c90c79b5
Extract HTTP request & response content length from headers (#6415)
* Extract HTTP request & response content length from headers

* remove unused method

* fix camel tests

* fix google http client tests

* fix HttpUrlConnection tests

* fix k8s and jaxrs tests

* fix aws tests

* actually fix aws tests 🤞

* fix elasticsearch tests

* fix ratpack tests

* fix spring webflux tests

* fix vertx tests

* fix reactor netty tests
2022-08-05 10:55:47 -07:00
..
src/main/java/io/opentelemetry/instrumentation/spring/webmvc Extract HTTP request & response content length from headers (#6415) 2022-08-05 10:55:47 -07:00
README.md Correct spelling of opentelemetry-exporter-logging (#6253) 2022-07-01 21:09:04 +03:00
build.gradle.kts Reorganize shared servlet code (intro to #4317) (#4785) 2021-12-06 13:49:55 +01:00

README.md

Manual Instrumentation for Spring Web MVC

Provides OpenTelemetry tracing for spring-webmvc RestControllers by leveraging spring-webmvc filters.

Quickstart

Add these dependencies to your project.

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

  • Minimum version: 3.1

Replace OPENTELEMETRY_VERSION with the latest stable release.

  • Minimum version: 1.7.0

For Maven add to your pom.xml:

<dependencies>
  <!-- opentelemetry instrumentation -->
  <dependency>
    <groupId>io.opentelemetry.instrumentation</groupId>
    <artifactId>opentelemetry-spring-webmvc-3.1</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-webmvc -->
  <!-- this artifact should already be present in your application -->
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>SPRING_VERSION</version>
  </dependency>

</dependencies>

For Gradle add to your dependencies:


// opentelemetry instrumentation
implementation("io.opentelemetry.instrumentation:opentelemetry-spring-webmvc-3.1: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-webmvc:SPRING_VERSION")

Features

SpringWebMvcTracing

SpringWebMvcTracing adds OpenTelemetry server spans to requests processed by request dispatch, on any spring servlet container. An example is shown below:

Usage in Spring Boot

Spring Boot allows servlet Filters to be registered as beans:

import io.opentelemetry.instrumentation.spring.webmvc.SpringWebMvcTracing;
import io.opentelemetry.api.trace.Tracer;

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

@Configuration
public class WebMvcTracingFilterConfig {

   @Bean
   public Filter webMvcTracingFilter(OpenTelemetry openTelemetry) {
      return SpringWebMvcTracing.create(openTelemetry).newServletFilter();
   }
}

Starter Guide

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