Skip to content

Commit 15656d2

Browse files
committed
improve test
1 parent 17c6c24 commit 15656d2

File tree

1 file changed

+55
-37
lines changed
  • instrumentation/spring/spring-boot-autoconfigure/src/testDeclarativeConfig/java/io/opentelemetry/instrumentation/spring/autoconfigure

1 file changed

+55
-37
lines changed

instrumentation/spring/spring-boot-autoconfigure/src/testDeclarativeConfig/java/io/opentelemetry/instrumentation/spring/autoconfigure/DeclarativeConfigTest.java

Lines changed: 55 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,68 @@ void customOpenTelemetry() {
5555
@Test
5656
@DisplayName(
5757
"when Application Context DOES NOT contain OpenTelemetry bean should initialize openTelemetry")
58+
void initializeProvidersAndOpenTelemetry() {
59+
this.contextRunner.run(
60+
context ->
61+
assertThat(context)
62+
.getBean("openTelemetry", OpenTelemetry.class)
63+
.isNotNull()
64+
.satisfies(
65+
o -> {
66+
ExtendedDeclarativeConfigProperties config =
67+
DeclarativeConfigUtil.getInstrumentationConfig(o, "foo");
68+
assertThat(config.getString("string_key")).isEqualTo("string_value");
69+
assertThat(config.getBoolean("bool_key")).isTrue();
70+
assertThat(config.getDouble("double_key")).isEqualTo(3.14);
71+
assertThat(config.getLong("int_key")).isEqualTo(42);
72+
}));
73+
}
74+
75+
@Test
76+
@SetEnvironmentVariable(
77+
key = "OTEL_INSTRUMENTATION/DEVELOPMENT_JAVA_FOO_STRING_KEY",
78+
value = "new_value")
79+
@SetEnvironmentVariable(
80+
key = "OTEL_INSTRUMENTATION/DEVELOPMENT_JAVA_FOO_BOOL_KEY",
81+
value = "false")
82+
@SetEnvironmentVariable(key = "OTEL_INSTRUMENTATION/DEVELOPMENT_JAVA_FOO_INT_KEY", value = "43")
83+
@SetEnvironmentVariable(
84+
key = "OTEL_INSTRUMENTATION/DEVELOPMENT_JAVA_FOO_DOUBLE_KEY",
85+
value = "4.14")
86+
@SetEnvironmentVariable(
87+
key = "OTEL_TRACER_PROVIDER_PROCESSORS_0_BATCH_EXPORTER_OTLP_HTTP_ENDPOINT",
88+
value = "http://custom:4318/v1/traces")
89+
void envVarOverrideSpringStyle() {
90+
this.contextRunner.run(
91+
context ->
92+
assertThat(context)
93+
.getBean(OpenTelemetry.class)
94+
.isNotNull()
95+
.satisfies(
96+
o -> {
97+
ExtendedDeclarativeConfigProperties config =
98+
DeclarativeConfigUtil.getInstrumentationConfig(o, "foo");
99+
assertThat(config.getString("string_key")).isEqualTo("new_value");
100+
assertThat(config.getBoolean("bool_key")).isFalse();
101+
assertThat(config.getDouble("double_key")).isEqualTo(4.14);
102+
assertThat(config.getLong("int_key")).isEqualTo(43);
103+
104+
assertThat(o.toString())
105+
.contains("OtlpHttpSpanExporter{endpoint=http://custom:4318/v1/traces");
106+
}));
107+
}
108+
109+
@Test
58110
@SetEnvironmentVariable(key = "STRING_ENV", value = "string_value")
59111
@SetEnvironmentVariable(key = "BOOL_ENV", value = "true")
60112
@SetEnvironmentVariable(key = "INT_ENV", value = "42")
61113
@SetEnvironmentVariable(key = "DOUBLE_ENV", value = "3.14")
62-
void initializeProvidersAndOpenTelemetry() {
114+
@SetEnvironmentVariable(key = "OTEL_EXPORTER_OTLP_ENDPOINT", value = "http://custom:4318")
115+
void envVarOverrideOtelStyle() {
63116
this.contextRunner.run(
64117
context ->
65118
assertThat(context)
66-
.getBean("openTelemetry", OpenTelemetry.class)
119+
.getBean(OpenTelemetry.class)
67120
.isNotNull()
68121
.satisfies(
69122
o -> {
@@ -151,39 +204,4 @@ void shouldNotLoadInstrumentationWhenExplicitlyDisabled() {
151204
"otel.instrumentation/development.java.spring_web.enabled=false")
152205
.run(context -> assertThat(context).doesNotHaveBean("otelRestTemplateBeanPostProcessor"));
153206
}
154-
155-
@Test
156-
void envVarOverrideSpringStyle() {
157-
this.contextRunner
158-
// this is typically set via env var
159-
.withSystemProperties(
160-
"OTEL_TRACER_PROVIDER_PROCESSORS_0_BATCH_EXPORTER_OTLP_HTTP_ENDPOINT=http://custom:4318/v1/traces")
161-
.run(
162-
context ->
163-
assertThat(context)
164-
.getBean(OpenTelemetry.class)
165-
.isNotNull()
166-
.satisfies(
167-
c ->
168-
assertThat(c.toString())
169-
.contains(
170-
"OtlpHttpSpanExporter{endpoint=http://custom:4318/v1/traces")));
171-
}
172-
173-
@Test
174-
void envVarOverrideOtelStyle() {
175-
this.contextRunner
176-
// this is typically set via env var
177-
.withSystemProperties("OTEL_EXPORTER_OTLP_ENDPOINT=http://custom:4318")
178-
.run(
179-
context ->
180-
assertThat(context)
181-
.getBean(OpenTelemetry.class)
182-
.isNotNull()
183-
.satisfies(
184-
c ->
185-
assertThat(c.toString())
186-
.contains(
187-
"OtlpHttpSpanExporter{endpoint=http://custom:4318/v1/traces")));
188-
}
189207
}

0 commit comments

Comments
 (0)