Skip to content

Instantly share code, notes, and snippets.

@xsreality
Last active February 1, 2024 12:40
Show Gist options
  • Save xsreality/d8508c5ef82b05f07acb1da0485fb7dc to your computer and use it in GitHub Desktop.
Save xsreality/d8508c5ef82b05f07acb1da0485fb7dc to your computer and use it in GitHub Desktop.
Enabling tracing with Spring Cloud Sleuth and OpenTelemetry
<properties>
<spring-cloud.version>2021.0.0-M2</spring-cloud.version>
<spring-cloud-sleuth-otel.version>1.1.0-M3</spring-cloud-sleuth-otel.version>
<opentelemetry-exporter-otlp>1.7.0</opentelemetry-exporter-otlp>
<grpc-netty-shaded>1.41.0</grpc-netty-shaded>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Spring Cloud Sleuth OTel requires a Spring Cloud Sleuth OTel BOM -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-otel-dependencies</artifactId>
<version>${spring-cloud-sleuth-otel.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<!-- Sleuth with Brave tracer implementation -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
<exclusions>
<!-- Exclude Brave (the default) -->
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-brave</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Add OpenTelemetry tracer -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-otel-autoconfigure</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/io.opentelemetry/opentelemetry-exporter-otlp -->
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-otlp</artifactId>
<version>${opentelemetry-exporter-otlp}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.grpc/grpc-netty -->
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>${grpc-netty-shaded}</version>
</dependency>
<repositories>
<repository>
<id>spring-snapshots</id>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<url>https://repo.spring.io/snapshot</url>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
@xsreality
Copy link
Author

xsreality commented Oct 30, 2021

Summary:

  1. Include the Spring Cloud and Spring Cloud Sleuth OTEL BOM as dependency management.
  2. Remove the default Brave implementation (no vendor locking).
  3. Include the OpenTelemetry library.
  4. Include the OpenTelemetry exporter to send the traces and spans to a remote instrumentation backend.
  5. Include GRPC Netty Shaded (used by exporter) because there is some disagreement within Spring on providing a default GRPC implementation. See spring-projects-experimental/spring-cloud-sleuth-otel#39
  6. Since we are using unreleased versions that are not available in Maven Central, we have to include the Spring Snapshots and Milestone repositories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment