Anuraag Agrawal fe41885ee6 Switch to colon notation for dependencies. (#2994) 3 سال پیش
..
src 69c2644774 Servlet 5 API, reorganize servlet modules (#2609) 4 سال پیش
README.md c6eee70660 Update to latest snapshot. (#1524) 4 سال پیش
spring-webmvc-3.1-library.gradle fe41885ee6 Switch to colon notation for dependencies. (#2994) 3 سال پیش

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: 0.8.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-exporters-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-exporters-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

WebMvcTracingFilter

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

Usage
import io.opentelemetry.instrumentation.spring.webmvc.WebMvcTracingFilter
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 WebMvcTracingFilter webMvcTracingFilter(Tracer tracer) {
      return new WebMvcTracingFilter(tracer);
   }
}

Starter Guide

Check out the opentelemetry quick start to learn more about OpenTelemetry instrumentation.