Browse Source

Clarify use of OpenTelemetry's environment variables

See gh-47960
pull/48068/head
Moritz Halbritter 1 month ago
parent
commit
995e8560f5
  1. 5
      documentation/spring-boot-docs/build.gradle
  2. 12
      documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/observability.adoc
  3. 33
      documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/observability/opentelemetry/environmentvariables/AutoConfiguredOpenTelemetrySdkConfiguration.java

5
documentation/spring-boot-docs/build.gradle

@ -150,9 +150,10 @@ dependencies { @@ -150,9 +150,10 @@ dependencies {
implementation("io.micrometer:micrometer-tracing")
implementation("io.micrometer:micrometer-registry-graphite")
implementation("io.micrometer:micrometer-registry-jmx")
implementation("io.opentelemetry.instrumentation:opentelemetry-logback-appender-1.0")
implementation("io.opentelemetry:opentelemetry-sdk-metrics")
implementation("io.opentelemetry:opentelemetry-exporter-otlp")
implementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
implementation("io.opentelemetry:opentelemetry-sdk-metrics")
implementation("io.opentelemetry.instrumentation:opentelemetry-logback-appender-1.0")
implementation("io.projectreactor.netty:reactor-netty-http")
implementation("jakarta.annotation:jakarta.annotation-api")
implementation("jakarta.jms:jakarta.jms-api")

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

@ -137,7 +137,17 @@ Micrometer also supports the following environment variables to configure the me @@ -137,7 +137,17 @@ Micrometer also supports the following environment variables to configure the me
* https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/#otel_exporter_otlp_headers[`OTEL_EXPORTER_OTLP_HEADERS`]
* https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/#otel_exporter_otlp_metrics_headers[`OTEL_EXPORTER_OTLP_METRICS_HEADERS`]
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.
Other environment variables as described in https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/[the OpenTelemetry documentation] are not supported.
If you want all environment variables specified by OpenTelemetry's SDK to be effective, you have to supply your own `OpenTelemetry` bean.
WARNING: Doing this will switch off Spring Boot's OpenTelemetry auto-configuration and may break the built-in observability functionality.
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:
include-code::AutoConfiguredOpenTelemetrySdkConfiguration[]
[[actuator.observability.opentelemetry.logging]]
=== Logging

33
documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/actuator/observability/opentelemetry/environmentvariables/AutoConfiguredOpenTelemetrySdkConfiguration.java

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.actuator.observability.opentelemetry.environmentvariables;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
class AutoConfiguredOpenTelemetrySdkConfiguration {
@Bean
OpenTelemetry autoConfiguredOpenTelemetrySdk() {
return AutoConfiguredOpenTelemetrySdk.initialize().getOpenTelemetrySdk();
}
}
Loading…
Cancel
Save