Skip to content

Commit 7f971d2

Browse files
committed
Merge pull request #44789 from nosan
* pr/44789: Add tests for OtlpTracingAutoConfiguration Closes gh-44789
2 parents a6ee681 + 48b7467 commit 7f971d2

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ dependencies {
139139
testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
140140
testImplementation(testFixtures(project(":spring-boot-project:spring-boot")))
141141
testImplementation("io.micrometer:micrometer-observation-test")
142+
testImplementation("io.opentelemetry:opentelemetry-exporter-common")
142143
testImplementation("io.projectreactor:reactor-test")
143144
testImplementation("io.prometheus:prometheus-metrics-exposition-formats")
144145
testImplementation("io.r2dbc:r2dbc-h2")

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/otlp/OtlpTracingAutoConfigurationTests.java

+49-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,10 +16,15 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure.tracing.otlp;
1818

19+
import java.util.List;
20+
import java.util.function.Supplier;
21+
22+
import io.opentelemetry.exporter.internal.compression.GzipCompressor;
1923
import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter;
2024
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter;
2125
import io.opentelemetry.sdk.trace.export.SpanExporter;
2226
import okhttp3.HttpUrl;
27+
import org.assertj.core.api.InstanceOfAssertFactories;
2328
import org.junit.jupiter.api.Test;
2429

2530
import org.springframework.boot.actuate.autoconfigure.tracing.otlp.OtlpTracingConfigurations.ConnectionDetails.PropertiesOtlpTracingConnectionDetails;
@@ -64,6 +69,27 @@ void shouldSupplyBeans() {
6469
.hasSingleBean(SpanExporter.class));
6570
}
6671

72+
@Test
73+
void shouldCustomizeHttpTransportWithProperties() {
74+
this.contextRunner
75+
.withPropertyValues("management.otlp.tracing.endpoint=http://localhost:4317/v1/traces",
76+
"management.otlp.tracing.timeout=10m", "management.otlp.tracing.connect-timeout=20m",
77+
"management.otlp.tracing.compression=GZIP", "management.otlp.tracing.headers.spring=boot")
78+
.run((context) -> {
79+
assertThat(context).hasSingleBean(OtlpHttpSpanExporter.class).hasSingleBean(SpanExporter.class);
80+
OtlpHttpSpanExporter exporter = context.getBean(OtlpHttpSpanExporter.class);
81+
assertThat(exporter).extracting("delegate.httpSender.client")
82+
.hasFieldOrPropertyWithValue("connectTimeoutMillis", 1200000)
83+
.hasFieldOrPropertyWithValue("callTimeoutMillis", 600000);
84+
assertThat(exporter).extracting("delegate.httpSender.compressor").isInstanceOf(GzipCompressor.class);
85+
assertThat(exporter).extracting("delegate.httpSender.headerSupplier")
86+
.asInstanceOf(InstanceOfAssertFactories.type(Supplier.class))
87+
.satisfies((headerSupplier) -> assertThat(headerSupplier.get())
88+
.asInstanceOf(InstanceOfAssertFactories.map(String.class, List.class))
89+
.containsEntry("spring", List.of("boot")));
90+
});
91+
}
92+
6793
@Test
6894
void shouldSupplyBeansIfGrpcTransportIsEnabled() {
6995
this.contextRunner
@@ -73,6 +99,28 @@ void shouldSupplyBeansIfGrpcTransportIsEnabled() {
7399
.hasSingleBean(SpanExporter.class));
74100
}
75101

102+
@Test
103+
void shouldCustomizeGrpcTransportWithProperties() {
104+
this.contextRunner
105+
.withPropertyValues("management.otlp.tracing.endpoint=http://localhost:4317/v1/traces",
106+
"management.otlp.tracing.transport=grpc", "management.otlp.tracing.timeout=10m",
107+
"management.otlp.tracing.connect-timeout=20m", "management.otlp.tracing.compression=GZIP",
108+
"management.otlp.tracing.headers.spring=boot")
109+
.run((context) -> {
110+
assertThat(context).hasSingleBean(OtlpGrpcSpanExporter.class).hasSingleBean(SpanExporter.class);
111+
OtlpGrpcSpanExporter exporter = context.getBean(OtlpGrpcSpanExporter.class);
112+
assertThat(exporter).extracting("delegate.grpcSender.client")
113+
.hasFieldOrPropertyWithValue("connectTimeoutMillis", 1200000)
114+
.hasFieldOrPropertyWithValue("callTimeoutMillis", 600000);
115+
assertThat(exporter).extracting("delegate.grpcSender.compressor").isInstanceOf(GzipCompressor.class);
116+
assertThat(exporter).extracting("delegate.grpcSender.headersSupplier")
117+
.asInstanceOf(InstanceOfAssertFactories.type(Supplier.class))
118+
.satisfies((headerSupplier) -> assertThat(headerSupplier.get())
119+
.asInstanceOf(InstanceOfAssertFactories.map(String.class, List.class))
120+
.containsEntry("spring", List.of("boot")));
121+
});
122+
}
123+
76124
@Test
77125
void shouldNotSupplyBeansIfGlobalTracingIsDisabled() {
78126
this.contextRunner.withPropertyValues("management.tracing.enabled=false")

0 commit comments

Comments
 (0)