From 4be920f520c03f8fd1e501b47dfc3378248ea8ff Mon Sep 17 00:00:00 2001 From: Bruce Bujon Date: Thu, 7 Dec 2023 14:01:49 +0100 Subject: [PATCH] Fix manual instrumentation with Spring Boot app --- .../en/docs/instrumentation/java/manual.md | 88 +++++++++++-------- 1 file changed, 49 insertions(+), 39 deletions(-) diff --git a/content/en/docs/instrumentation/java/manual.md b/content/en/docs/instrumentation/java/manual.md index 24322a5f999b..f01afb33e7c1 100644 --- a/content/en/docs/instrumentation/java/manual.md +++ b/content/en/docs/instrumentation/java/manual.md @@ -190,22 +190,39 @@ You should get a list of 12 numbers in your browser window, for example: For both library and app instrumentation, the first step is to install the dependencies for the OpenTelemetry API. +### Dependency management + +A Bill of Material +([BOM](https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#bill-of-materials-bom-poms)) +ensures that versions of dependencies (including transitive ones) are aligned. +Importing the `opentelemetry-bom` BOM is important to ensure version alignment +across all OpenTelemetry dependencies. + {{< tabpane text=true >}} {{% tab Gradle %}} -```kotlin { hl_lines=3 } +```kotlin { hl_lines=["1-5",9] } + imports { + mavenBom("io.dependencyManagement { +opentelemetry:opentelemetry-bom:{{% param vers.otel %}}") + } +} + dependencies { implementation("org.springframework.boot:spring-boot-starter-web"); - implementation("io.opentelemetry:opentelemetry-api:{{% param vers.otel %}}"); + implementation("io.opentelemetry:opentelemetry-api"); } ``` -Throughout this documentation you will add dependencies. For a full list of -artifact coordinates, see [releases]. For semantic convention releases, see -[semantic-conventions-java]. +If you are not using Spring and its `io.spring.dependency-management` dependency +managemnt plugin, install the OpenTelemetry BOM and API using Gradle depenencies +only. -[releases]: https://github.com/open-telemetry/opentelemetry-java#releases -[semantic-conventions-java]: - https://github.com/open-telemetry/semantic-conventions-java/releases +```kotlin +dependencies { + implementation(platform("io.opentelemetry:opentelemetry-bom:{{% param vers.otel %}}")); + implementation("io.opentelemetry:opentelemetry-api"); +} +``` {{% /tab %}} {{% tab Maven %}} @@ -233,24 +250,32 @@ artifact coordinates, see [releases]. For semantic convention releases, see {{% /tab %}} {{% /tabpane %}} +Throughout this documentation you will add dependencies. For a full list of +artifact coordinates, see [releases]. For semantic convention releases, see +[semantic-conventions-java]. + +[releases]: https://github.com/open-telemetry/opentelemetry-java#releases +[semantic-conventions-java]: + https://github.com/open-telemetry/semantic-conventions-java/releases + ### Initialize the SDK {{% alert title="Note" color="info" %}} If you’re instrumenting a library, **skip this step**. {{% /alert %}} -If you instrument a Java app, install the dependencies for the OpenTelemetry -SDK. +If you instrument a Java app, install the dependencies for the OpenTelemetry SDK +in addition to the dependencies for the OpenTelemetry API. {{< tabpane text=true >}} {{% tab Gradle %}} -```kotlin { hl_lines="4-8" } +```kotlin { hl_lines="4-7" } dependencies { implementation("org.springframework.boot:spring-boot-starter-web"); - implementation("io.opentelemetry:opentelemetry-api:{{% param vers.otel %}}"); - implementation("io.opentelemetry:opentelemetry-sdk:{{% param vers.otel %}}"); - implementation("io.opentelemetry:opentelemetry-sdk-metrics:{{% param vers.otel %}}"); - implementation("io.opentelemetry:opentelemetry-exporter-logging:{{% param vers.otel %}}"); - implementation("io.opentelemetry:opentelemetry-semconv:{{% param vers.otel %}}-alpha"); + implementation("io.opentelemetry:opentelemetry-api"); + implementation("io.opentelemetry:opentelemetry-sdk"); + implementation("io.opentelemetry:opentelemetry-sdk-metrics"); + implementation("io.opentelemetry:opentelemetry-exporter-logging"); + implementation("io.opentelemetry:opentelemetry-semconv:{{% param vers.semconv %}}-alpha"); } ``` @@ -258,22 +283,7 @@ dependencies { ```xml - - - - io.opentelemetry - opentelemetry-bom - {{% param vers.otel %}} - pom - import - - - - - io.opentelemetry - opentelemetry-api - io.opentelemetry opentelemetry-sdk @@ -312,16 +322,16 @@ To use auto-configuration add the following dependency to your application: {{< tabpane text=true >}} {{% tab Gradle %}} -```kotlin { hl_lines="9-10" } +```kotlin { hl_lines="8-9" } dependencies { implementation("org.springframework.boot:spring-boot-starter-web"); - implementation("io.opentelemetry:opentelemetry-api:{{% param vers.otel %}}"); - implementation("io.opentelemetry:opentelemetry-sdk:{{% param vers.otel %}}"); - implementation("io.opentelemetry:opentelemetry-sdk-metrics:{{% param vers.otel %}}"); - implementation("io.opentelemetry:opentelemetry-exporter-logging:{{% param vers.otel %}}"); - implementation("io.opentelemetry.semconv:opentelemetry-semconv:{{% param vers.semconv %}}-alpha") - implementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:{{% param vers.otel %}}"); - implementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi:{{% param vers.otel %}}"); + implementation("io.opentelemetry:opentelemetry-api"); + implementation("io.opentelemetry:opentelemetry-sdk"); + implementation("io.opentelemetry:opentelemetry-sdk-metrics"); + implementation("io.opentelemetry:opentelemetry-exporter-logging"); + implementation("io.opentelemetry.semconv:opentelemetry-semconv:{{% param vers.semconv %}}-alpha"); + implementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure"); + implementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi"); } ```