|
16 | 16 |
|
17 | 17 | package org.springframework.boot.actuate.autoconfigure.tracing.otlp;
|
18 | 18 |
|
| 19 | +import java.time.Duration; |
19 | 20 | import java.util.function.Supplier;
|
20 | 21 |
|
21 | 22 | import io.opentelemetry.api.metrics.MeterProvider;
|
@@ -184,6 +185,45 @@ void grpcShouldUseMeterProviderIfSet() {
|
184 | 185 | });
|
185 | 186 | }
|
186 | 187 |
|
| 188 | + @Test |
| 189 | + void shouldCustomizeHttpTransportWithOtlpHttpSpanExporterBuilderCustomizer() { |
| 190 | + Duration connectTimeout = Duration.ofMinutes(20); |
| 191 | + Duration timeout = Duration.ofMinutes(10); |
| 192 | + this.contextRunner |
| 193 | + .withBean("httpCustomizer1", OtlpHttpSpanExporterBuilderCustomizer.class, |
| 194 | + () -> (builder) -> builder.setConnectTimeout(connectTimeout)) |
| 195 | + .withBean("httpCustomizer2", OtlpHttpSpanExporterBuilderCustomizer.class, |
| 196 | + () -> (builder) -> builder.setTimeout(timeout)) |
| 197 | + .withPropertyValues("management.otlp.tracing.endpoint=http://localhost:4317/v1/traces") |
| 198 | + .run((context) -> { |
| 199 | + assertThat(context).hasSingleBean(OtlpHttpSpanExporter.class).hasSingleBean(SpanExporter.class); |
| 200 | + OtlpHttpSpanExporter exporter = context.getBean(OtlpHttpSpanExporter.class); |
| 201 | + assertThat(exporter).extracting("delegate.httpSender.client") |
| 202 | + .hasFieldOrPropertyWithValue("connectTimeoutMillis", (int) connectTimeout.toMillis()) |
| 203 | + .hasFieldOrPropertyWithValue("callTimeoutMillis", (int) timeout.toMillis()); |
| 204 | + }); |
| 205 | + } |
| 206 | + |
| 207 | + @Test |
| 208 | + void shouldCustomizeGrpcTransportWhenEnabledWithOtlpGrpcSpanExporterBuilderCustomizer() { |
| 209 | + Duration timeout = Duration.ofMinutes(10); |
| 210 | + Duration connectTimeout = Duration.ofMinutes(20); |
| 211 | + this.contextRunner |
| 212 | + .withBean("grpcCustomizer1", OtlpGrpcSpanExporterBuilderCustomizer.class, |
| 213 | + () -> (builder) -> builder.setConnectTimeout(connectTimeout)) |
| 214 | + .withBean("grpcCustomizer2", OtlpGrpcSpanExporterBuilderCustomizer.class, |
| 215 | + () -> (builder) -> builder.setTimeout(timeout)) |
| 216 | + .withPropertyValues("management.otlp.tracing.endpoint=http://localhost:4317/v1/traces", |
| 217 | + "management.otlp.tracing.transport=grpc") |
| 218 | + .run((context) -> { |
| 219 | + assertThat(context).hasSingleBean(OtlpGrpcSpanExporter.class).hasSingleBean(SpanExporter.class); |
| 220 | + OtlpGrpcSpanExporter exporter = context.getBean(OtlpGrpcSpanExporter.class); |
| 221 | + assertThat(exporter).extracting("delegate.grpcSender.client") |
| 222 | + .hasFieldOrPropertyWithValue("connectTimeoutMillis", (int) connectTimeout.toMillis()) |
| 223 | + .hasFieldOrPropertyWithValue("callTimeoutMillis", (int) timeout.toMillis()); |
| 224 | + }); |
| 225 | + } |
| 226 | + |
187 | 227 | @Configuration(proxyBeanMethods = false)
|
188 | 228 | private static final class MeterProviderConfiguration {
|
189 | 229 |
|
|
0 commit comments