Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ testing {
dependencies {
implementation(project())
implementation("io.opentelemetry:opentelemetry-sdk")
implementation("io.opentelemetry:opentelemetry-exporter-otlp")
implementation("org.springframework.boot:spring-boot-starter-test:$springBootVersion") {
exclude("org.junit.vintage", "junit-vintage-engine")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -62,6 +63,24 @@ private static Map<String, String> extractSpringProperties(ConfigurableEnvironme
if (Objects.equals(property, "")) {
property = null; // spring returns empty string for yaml null
}
if (propertyName.contains("[")) {
// fix override via env var or system property
// see
// https://docs.spring.io/spring-boot/reference/features/external-config.html#features.external-config.typesafe-configuration-properties.relaxed-binding
// For example, the configuration property my.service[0].other would use an
// environment variable named MY_SERVICE_0_OTHER.
String envVarName =
propertyName
.replace("[", "_")
.replace("]", "")
.replace(".", "_")
.toUpperCase(Locale.ROOT);
String envVarValue = environment.getProperty(envVarName);
if (envVarValue != null) {
property = envVarValue;
}
}

props.put(propertyName.substring("otel.".length()), property);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,23 @@ void shouldNotLoadInstrumentationWhenExplicitlyDisabled() {
"otel.instrumentation/development.java.spring_web.enabled=false")
.run(context -> assertThat(context).doesNotHaveBean("otelRestTemplateBeanPostProcessor"));
}

@Test
void envVarOverride() {
this.contextRunner
// this is typically set via env var
// OTEL_TRACER_PROVIDER_PROCESSORS_0_BATCH_EXPORTER_OTLP_HTTP_ENDPOINT
.withSystemProperties(
"OTEL_TRACER_PROVIDER_PROCESSORS_0_BATCH_EXPORTER_OTLP_HTTP_ENDPOINT=http://custom:4318/v1/traces")
.run(
context ->
assertThat(context)
.getBean(OpenTelemetry.class)
.isNotNull()
.satisfies(
c ->
assertThat(c.toString())
.contains(
"OtlpHttpSpanExporter{endpoint=http://custom:4318/v1/traces")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ otel:
# "file_format" serves as opt-in to the new file format
file_format: "1.0-rc.1"

tracer_provider:
processors:
- batch:
exporter:
otlp_http:
endpoint: http://localhost:4318/v1/traces # to test that we can use env vars in declarative config

# very lightweight test to make sure the declarative config is loaded
# the full config is tested in smoke-tests-otel-starter/spring-boot-2/src/testDeclarativeConfig
instrumentation/development:
Expand Down
Loading