@@ -3,7 +3,7 @@ title: Spring Boot
3
3
linkTitle : Spring Boot
4
4
weight : 30
5
5
description : Spring instrumentation for OpenTelemetry Java
6
- cSpell:ignore : autoconfigure datasource logback springboot
6
+ cSpell:ignore : autoconfigure datasource logback springboot springframework
7
7
---
8
8
9
9
You can use the [ OpenTelemetry Java agent] ( .. ) with byte code instrumentation to
@@ -23,6 +23,85 @@ Spring Boot starter, see
23
23
24
24
## Configuration
25
25
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
+
26
105
Add the dependency given below to enable the OpenTelemetry starter.
27
106
28
107
The OpenTelemetry starter uses OpenTelemetry Spring Boot [ auto-configuration] .
@@ -41,16 +120,15 @@ auto-configuration, see the configuration [README].
41
120
<dependency >
42
121
<groupId >io.opentelemetry.instrumentation</groupId >
43
122
<artifactId >opentelemetry-spring-boot-starter</artifactId >
44
- <version >{{% param vers.instrumentation %}}-alpha</version >
45
123
</dependency >
46
124
</dependencies >
47
125
```
48
126
49
127
{{% /tab %}} {{% tab header="Gradle (` gradle.build ` )" lang=Gradle %}}
50
128
51
- ``` groovy
129
+ ``` kotlin
52
130
dependencies {
53
- implementation(' io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter:{{% param vers.instrumentation %}}-alpha' )
131
+ implementation(" io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter" )
54
132
}
55
133
```
56
134
@@ -102,16 +180,15 @@ With the datasource configuration, you need to add the following dependency:
102
180
<dependency >
103
181
<groupId >io.opentelemetry.instrumentation</groupId >
104
182
<artifactId >opentelemetry-jdbc</artifactId >
105
- <version >{{% param vers.instrumentation %}}-alpha</version >
106
183
</dependency >
107
184
</dependencies >
108
185
```
109
186
110
187
{{% /tab %}} {{% tab header="Gradle (` gradle.build ` )" lang=Gradle %}}
111
188
112
- ``` groovy
189
+ ``` kotlin
113
190
dependencies {
114
- implementation(' io.opentelemetry.instrumentation:opentelemetry-jdbc:{{% param vers.instrumentation %}}-alpha' )
191
+ implementation(" io.opentelemetry.instrumentation:opentelemetry-jdbc" )
115
192
}
116
193
```
117
194
0 commit comments