opentelemetry-java-instrume.../instrumentation/spring/spring-web-3.1/library
Mateusz Rzeszutek 4e3f19d469
Enable span suppression by SpanKey by default (#5779)
* Enable span suppression by SpanKey by default

* fix HTTP tests (probably)

* add exception for camel

* remove suppression tests from @WithSpan instrumentations

* remove suppression tests from @WithSpan instrumentation; spring boot autoconfigure

* fix twilio tests

* fix netty-based HTTP clients, remove AWS SDK 1.11 unit test

* fix elasticsearch tests

* codenarc

* spotless

* fix AWS SDK 1.11 tests

* remove a TODO

* code review comments

* fix merge conflict

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
2022-04-19 14:13:09 -07:00
..
src Enable span suppression by SpanKey by default (#5779) 2022-04-19 14:13:09 -07:00
README.md Rename library entrypoints to Telemetry (#5624) 2022-03-22 14:39:23 +09:00
build.gradle.kts Migrate Guava tests to Java (#5668) 2022-03-24 14:14:09 +09:00

README.md

Manual Instrumentation for Spring-Web

Provides OpenTelemetry instrumentation for Spring's RestTemplate.

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.4.0

For Maven add to your pom.xml:


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

  <!-- provides opentelemetry-sdk -->
  <dependency>
    <groupId>io.opentelemetry</groupId>
    <artifactId>opentelemetry-exporters-logging</artifactId>
    <version>OPENTELEMETRY_VERSION</version>
  </dependency>

  <!-- required to instrument spring-web -->
  <!-- this artifact should already be present in your application -->
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>SPRING_VERSION</version>
  </dependency>

</dependencies>

For Gradle add to your dependencies:

implementation("io.opentelemetry.instrumentation:opentelemetry-spring-web-3.1:OPENTELEMETRY_VERSION")
implementation("io.opentelemetry:opentelemetry-exporters-logging:OPENTELEMETRY_VERSION")

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

Features

Telemetry-producing ClientHttpRequestInterceptor implementation

SpringWebTelemetry allows creating a custom ClientHttpRequestInterceptor that produces telemetry for HTTP requests sent using a RestTemplate. Example:

Usage

import io.opentelemetry.instrumentation.spring.web.SpringWebTelemetry;
import io.opentelemetry.api.OpenTelemetry;

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

@Configuration
public class RestTemplateConfig {

  @Bean
  public RestTemplate restTemplate(OpenTelemetry openTelemetry) {

    RestTemplate restTemplate = new RestTemplate();
    SpringWebTelemetry telemetry = SpringWebTelemetry.create(openTelemetry);
    restTemplate.getInterceptors().add(telemetry.newInterceptor());

    return restTemplate;
  }
}

Starter Guide

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