From 61a26ba7b8c02cd16b176f9935375aa976fe98a7 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Fri, 14 Jun 2024 11:03:36 +0200 Subject: [PATCH] Small spring fixes (#4677) Co-authored-by: Trask Stalnaker Co-authored-by: Fabrizio Ferri-Benedetti --- .../en/docs/languages/java/instrumentation.md | 34 +++++++++++++++++++ .../spring-boot-starter/getting-started.md | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/content/en/docs/languages/java/instrumentation.md b/content/en/docs/languages/java/instrumentation.md index 686f7d2cc15d..7050d917311e 100644 --- a/content/en/docs/languages/java/instrumentation.md +++ b/content/en/docs/languages/java/instrumentation.md @@ -687,6 +687,23 @@ import io.opentelemetry.api.GlobalOpenTelemetry; Tracer tracer = GlobalOpenTelemetry.getTracer("application"); ``` +If you are using Spring Boot, you can add the following bean to your +`@SpringBootApplication` class - to acquire a `Tracer` as in the +[Spring Boot starter](#acquiring-a-tracer-in-spring-boot-starter) section below: + +```java +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.GlobalOpenTelemetry; + +@Configuration +public class OpenTelemetryConfig { + @Bean + public OpenTelemetry openTelemetry() { + return GlobalOpenTelemetry.get(); + } +} +``` + ### Acquiring a tracer in Spring Boot starter If you are using the [Spring Boot starter], you can acquire a `Tracer` from the @@ -1257,6 +1274,23 @@ import io.opentelemetry.api.GlobalOpenTelemetry; Meter meter = GlobalOpenTelemetry.getMeter("application"); ``` +If you are using Spring Boot, you can add the following bean to your +`@SpringBootApplication` class - to acquire a `Meter` as in the +[Spring Boot starter](#acquiring-a-meter-in-spring-boot-starter) section below: + +```java +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.GlobalOpenTelemetry; + +@Configuration +public class OpenTelemetryConfig { + @Bean + public OpenTelemetry openTelemetry() { + return GlobalOpenTelemetry.get(); + } +} +``` + ### Acquiring a meter in Spring Boot starter If you are using the [Spring Boot starter], you can acquire a `Meter` from the diff --git a/content/en/docs/zero-code/java/spring-boot-starter/getting-started.md b/content/en/docs/zero-code/java/spring-boot-starter/getting-started.md index eba5b9332a8b..8d2da55ea72d 100644 --- a/content/en/docs/zero-code/java/spring-boot-starter/getting-started.md +++ b/content/en/docs/zero-code/java/spring-boot-starter/getting-started.md @@ -13,7 +13,7 @@ application. For the pros and cons, see [Java zero-code instrumentation](..). ### Compatibility -The OpenTelemetry Spring Boot starter works with Spring Boot 2.6+ and 3.0+, and +The OpenTelemetry Spring Boot starter works with Spring Boot 2.6+ and 3.1+, and Spring Boot native image applications. The [opentelemetry-java-examples/spring-native](https://github.com/open-telemetry/opentelemetry-java-examples/tree/main/spring-native) repository contains an example of a Spring Boot Native image application