Skip to content

Commit 34c785d

Browse files
authored
Add BOM definition to the OTel starter (open-telemetry#3672)
1 parent 08e13eb commit 34c785d

File tree

2 files changed

+92
-7
lines changed

2 files changed

+92
-7
lines changed

content/en/docs/instrumentation/java/automatic/spring-boot.md

+84-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Spring Boot
33
linkTitle: Spring Boot
44
weight: 30
55
description: Spring instrumentation for OpenTelemetry Java
6-
cSpell:ignore: autoconfigure datasource logback springboot
6+
cSpell:ignore: autoconfigure datasource logback springboot springframework
77
---
88

99
You can use the [OpenTelemetry Java agent](..) with byte code instrumentation to
@@ -23,6 +23,85 @@ Spring Boot starter, see
2323

2424
## Configuration
2525

26+
### Dependency management
27+
28+
A Bill of Material
29+
([BOM](https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#bill-of-materials-bom-poms))
30+
ensures that versions of dependencies (including transitive ones) are aligned.
31+
32+
Importing the `opentelemetry-bom` and `opentelemetry-instrumentation-bom-alpha`
33+
BOMs when using the OpenTelemetry starter is important to ensure version
34+
alignment across all OpenTelemetry dependencies.
35+
36+
The following example shows how to import both BOMs using Maven:
37+
38+
```xml
39+
<dependencyManagement>
40+
<dependencies>
41+
<dependency>
42+
<groupId>io.opentelemetry</groupId>
43+
<artifactId>opentelemetry-bom</artifactId>
44+
<version>{{% param vers.otel %}}</version>
45+
<type>pom</type>
46+
</dependency>
47+
<dependency>
48+
<groupId>io.opentelemetry.instrumentation</groupId>
49+
<artifactId>opentelemetry-instrumentation-bom-alpha</artifactId>
50+
<version>{{% param vers.instrumentation %}}-alpha</version>
51+
<type>pom</type>
52+
</dependency>
53+
</dependencies>
54+
</dependencyManagement>
55+
```
56+
57+
With Gradle and Spring Boot, you have
58+
[two ways](https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/)
59+
to import a BOM.
60+
61+
You can use the Gradle’s native BOM support by adding dependencies:
62+
63+
```kotlin
64+
plugins {
65+
id("java")
66+
id("org.springframework.boot") version "3.2.O"
67+
}
68+
69+
dependencies {
70+
implementation(platform(SpringBootPlugin.BOM_COORDINATES))
71+
implementation(platform("io.opentelemetry:opentelemetry-bom:{{% param vers.otel %}}"))
72+
implementation(platform("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:{{% param vers.instrumentation %}}-alpha"))
73+
}
74+
```
75+
76+
The other way with Gradle is to use the `io.spring.dependency-management` plugin
77+
and to import the BOMs in `dependencyManagement`:
78+
79+
```kotlin
80+
plugins {
81+
id("java")
82+
id("org.springframework.boot") version "3.2.O"
83+
id("io.spring.dependency-management") version "1.1.0"
84+
}
85+
86+
dependencyManagement {
87+
imports {
88+
mavenBom("io.opentelemetry:opentelemetry-bom:{{% param vers.otel %}}")
89+
mavenBom("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:{{% param vers.instrumentation %}}-alpha")
90+
}
91+
}
92+
```
93+
94+
{{% alert title="Note" color="info" %}}
95+
96+
Be careful not to mix up the different ways of configuring things with Gradle.
97+
For example, don't use
98+
`implementation(platform("io.opentelemetry:opentelemetry-bom:{{% param vers.otel %}}"))`
99+
with the `io.spring.dependency-management` plugin.
100+
101+
{{% /alert %}}
102+
103+
### OpenTelemetry Starter dependency
104+
26105
Add the dependency given below to enable the OpenTelemetry starter.
27106

28107
The OpenTelemetry starter uses OpenTelemetry Spring Boot [auto-configuration].
@@ -41,16 +120,15 @@ auto-configuration, see the configuration [README].
41120
<dependency>
42121
<groupId>io.opentelemetry.instrumentation</groupId>
43122
<artifactId>opentelemetry-spring-boot-starter</artifactId>
44-
<version>{{% param vers.instrumentation %}}-alpha</version>
45123
</dependency>
46124
</dependencies>
47125
```
48126

49127
{{% /tab %}} {{% tab header="Gradle (`gradle.build`)" lang=Gradle %}}
50128

51-
```groovy
129+
```kotlin
52130
dependencies {
53-
implementation('io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter:{{% param vers.instrumentation %}}-alpha')
131+
implementation("io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter")
54132
}
55133
```
56134

@@ -102,16 +180,15 @@ With the datasource configuration, you need to add the following dependency:
102180
<dependency>
103181
<groupId>io.opentelemetry.instrumentation</groupId>
104182
<artifactId>opentelemetry-jdbc</artifactId>
105-
<version>{{% param vers.instrumentation %}}-alpha</version>
106183
</dependency>
107184
</dependencies>
108185
```
109186

110187
{{% /tab %}} {{% tab header="Gradle (`gradle.build`)" lang=Gradle %}}
111188

112-
```groovy
189+
```kotlin
113190
dependencies {
114-
implementation('io.opentelemetry.instrumentation:opentelemetry-jdbc:{{% param vers.instrumentation %}}-alpha')
191+
implementation("io.opentelemetry.instrumentation:opentelemetry-jdbc")
115192
}
116193
```
117194

static/refcache.json

+8
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,10 @@
15031503
"StatusCode": 200,
15041504
"LastSeen": "2023-07-26T16:17:33.996008+02:00"
15051505
},
1506+
"https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/": {
1507+
"StatusCode": 206,
1508+
"LastSeen": "2023-12-15T18:44:53.694369+01:00"
1509+
},
15061510
"https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.auto-configuration": {
15071511
"StatusCode": 206,
15081512
"LastSeen": "2023-11-14T09:30:48.194902-05:00"
@@ -4607,6 +4611,10 @@
46074611
"StatusCode": 206,
46084612
"LastSeen": "2023-06-29T16:19:11.338797-04:00"
46094613
},
4614+
"https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#bill-of-materials-bom-poms": {
4615+
"StatusCode": 206,
4616+
"LastSeen": "2023-12-15T18:44:53.040511+01:00"
4617+
},
46104618
"https://medium.com/@adri-v/lets-learn-about-the-otel-operator-s-target-allocator-47a2b1f07562": {
46114619
"StatusCode": 200,
46124620
"LastSeen": "2023-09-12T11:57:02.842574-04:00"

0 commit comments

Comments
 (0)