Skip to content

Commit 995e856

Browse files
committed
Clarify use of OpenTelemetry's environment variables
See gh-47960
1 parent 6158a52 commit 995e856

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

documentation/spring-boot-docs/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,10 @@ dependencies {
150150
implementation("io.micrometer:micrometer-tracing")
151151
implementation("io.micrometer:micrometer-registry-graphite")
152152
implementation("io.micrometer:micrometer-registry-jmx")
153-
implementation("io.opentelemetry.instrumentation:opentelemetry-logback-appender-1.0")
154-
implementation("io.opentelemetry:opentelemetry-sdk-metrics")
155153
implementation("io.opentelemetry:opentelemetry-exporter-otlp")
154+
implementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
155+
implementation("io.opentelemetry:opentelemetry-sdk-metrics")
156+
implementation("io.opentelemetry.instrumentation:opentelemetry-logback-appender-1.0")
156157
implementation("io.projectreactor.netty:reactor-netty-http")
157158
implementation("jakarta.annotation:jakarta.annotation-api")
158159
implementation("jakarta.jms:jakarta.jms-api")

documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/observability.adoc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,17 @@ Micrometer also supports the following environment variables to configure the me
137137
* https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/#otel_exporter_otlp_headers[`OTEL_EXPORTER_OTLP_HEADERS`]
138138
* https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/#otel_exporter_otlp_metrics_headers[`OTEL_EXPORTER_OTLP_METRICS_HEADERS`]
139139

140-
Logging and tracing use the OpenTelemetry SDK directly, so all environment variables https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/[supported by OpenTelemetry] also work.
140+
Other environment variables as described in https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/[the OpenTelemetry documentation] are not supported.
141+
142+
If you want all environment variables specified by OpenTelemetry's SDK to be effective, you have to supply your own `OpenTelemetry` bean.
143+
144+
WARNING: Doing this will switch off Spring Boot's OpenTelemetry auto-configuration and may break the built-in observability functionality.
145+
146+
First, add a dependency to `io.opentelemetry:opentelemetry-sdk-extension-autoconfigure` to get https://opentelemetry.io/docs/languages/java/configuration/#zero-code-sdk-autoconfigure[OpenTelemetry's zero-code SDK autoconfigure module], then add this configuration:
147+
148+
include-code::AutoConfiguredOpenTelemetrySdkConfiguration[]
149+
150+
141151

142152
[[actuator.observability.opentelemetry.logging]]
143153
=== Logging
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.docs.actuator.observability.opentelemetry.environmentvariables;
18+
19+
import io.opentelemetry.api.OpenTelemetry;
20+
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
21+
22+
import org.springframework.context.annotation.Bean;
23+
import org.springframework.context.annotation.Configuration;
24+
25+
@Configuration(proxyBeanMethods = false)
26+
class AutoConfiguredOpenTelemetrySdkConfiguration {
27+
28+
@Bean
29+
OpenTelemetry autoConfiguredOpenTelemetrySdk() {
30+
return AutoConfiguredOpenTelemetrySdk.initialize().getOpenTelemetrySdk();
31+
}
32+
33+
}

0 commit comments

Comments
 (0)