opentelemetry-java-instrume.../instrumentation/spring/spring-web-3.1/library
Trask Stalnaker 63a2383905
Split NetAttributesExtractor into NetClientAttributesExtractor and NetServerAttributesExtractor (#4287)
* Net Extractors

* Either request or response but not both

* Fix merge conflicts

* Separate by OnStart/OnEnd

* PeerServiceAttributes

* Fix test

* Restructure to client/server

* Fix merge conflict in main

* more

* peer.service

* Feedback

* peer.service is only for clients

* Fix merge conflict

* rename

* Armeria

* peer.service is only for clients

* rename

* WIP

* Sync Dubbo with Armeria

* More Dubbo and Armeria

* gRPC

* Revert some Dubbo changes

* more peer.service

* Fix test

* Fix merge

* Fixes
2021-10-07 15:40:15 -07:00
..
src Split NetAttributesExtractor into NetClientAttributesExtractor and NetServerAttributesExtractor (#4287) 2021-10-07 15:40:15 -07:00
README.md Spring web instrumenter 2 (#3731) 2021-07-30 09:28:27 -07:00
build.gradle.kts Migrate instrumentation gradle files to kotlin (#3414) 2021-06-28 17:27:12 +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

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

Usage

import io.opentelemetry.instrumentation.spring.web.SpringWebTracing;
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();
    SpringWebTracing springWebTracing = SpringWebTracing.create(openTelemetry);
    restTemplate.getInterceptors().add(springWebTracing.newInterceptor());

    return restTemplate;
  }
}

Starter Guide

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