|
7 | 7 |
|
8 | 8 | import static org.assertj.core.api.Assertions.assertThat;
|
9 | 9 |
|
10 |
| -import io.opentelemetry.exporter.logging.LoggingSpanExporter; |
11 | 10 | import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter;
|
12 |
| -import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; |
13 |
| -import io.opentelemetry.instrumentation.spring.autoconfigure.MapConverterTestAutoConfiguration; |
14 | 11 | import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration;
|
15 |
| -import io.opentelemetry.sdk.trace.export.SpanExporter; |
16 |
| -import java.util.stream.Collectors; |
17 |
| -import org.junit.jupiter.api.AfterEach; |
18 | 12 | import org.junit.jupiter.api.DisplayName;
|
19 | 13 | import org.junit.jupiter.api.Test;
|
20 |
| -import org.mockito.Mockito; |
21 | 14 | import org.springframework.boot.autoconfigure.AutoConfigurations;
|
22 | 15 | import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
23 | 16 |
|
24 | 17 | /** Spring Boot auto configuration test for {@link OtlpSpanExporterAutoConfiguration}. */
|
25 | 18 | class OtlpSpanExporterAutoConfigurationTest {
|
26 | 19 |
|
27 |
| - private final OtlpExporterProperties otlpExporterProperties = |
28 |
| - Mockito.mock(OtlpExporterProperties.class); |
29 |
| - |
30 | 20 | private final ApplicationContextRunner contextRunner =
|
31 | 21 | new ApplicationContextRunner()
|
32 | 22 | .withConfiguration(
|
33 | 23 | AutoConfigurations.of(
|
34 |
| - OpenTelemetryAutoConfiguration.class, |
35 |
| - OtlpSpanExporterAutoConfiguration.class, |
36 |
| - MapConverterTestAutoConfiguration.class)); |
37 |
| - |
38 |
| - @AfterEach |
39 |
| - void tearDown() { |
40 |
| - Mockito.verifyNoMoreInteractions(otlpExporterProperties); |
41 |
| - } |
| 24 | + OpenTelemetryAutoConfiguration.class, OtlpSpanExporterAutoConfiguration.class)); |
42 | 25 |
|
43 | 26 | @Test
|
44 | 27 | @DisplayName("when exporters are ENABLED should initialize OtlpHttpSpanExporter bean")
|
@@ -75,110 +58,4 @@ void otlpTracesDisabledOld() {
|
75 | 58 | .withPropertyValues("otel.exporter.otlp.traces.enabled=false")
|
76 | 59 | .run(context -> assertThat(context.containsBean("otelOtlpSpanExporter")).isFalse());
|
77 | 60 | }
|
78 |
| - |
79 |
| - @Test |
80 |
| - void otlpTracesDisabled() { |
81 |
| - this.contextRunner |
82 |
| - .withPropertyValues("otel.traces.exporter=none") |
83 |
| - .run(context -> assertThat(context.containsBean("otelOtlpSpanExporter")).isFalse()); |
84 |
| - } |
85 |
| - |
86 |
| - @Test |
87 |
| - @DisplayName("when otlp enabled property is MISSING should initialize OtlpHttpSpanExporter bean") |
88 |
| - void exporterPresentByDefault() { |
89 |
| - this.contextRunner.run( |
90 |
| - context -> |
91 |
| - assertThat(context.getBean("otelOtlpSpanExporter", OtlpHttpSpanExporter.class)) |
92 |
| - .isNotNull()); |
93 |
| - } |
94 |
| - |
95 |
| - @Test |
96 |
| - @DisplayName("use http/protobuf when protocol set") |
97 |
| - void useHttp() { |
98 |
| - this.contextRunner |
99 |
| - // .withBean(OtlpExporterProperties.class, () -> otlpExporterProperties) |
100 |
| - .withPropertyValues( |
101 |
| - "otel.exporter.otlp.enabled=true", |
102 |
| - "otel.exporter.otlp.protocol=http/protobuf", |
103 |
| - "otel.exporter.otlp.endpoint=http://localhost:4317", |
104 |
| - "otel.exporter.otlp.headers.x=1", |
105 |
| - "otel.exporter.otlp.headers.y=2", |
106 |
| - "otel.exporter.otlp.timeout=1s") |
107 |
| - .run( |
108 |
| - context -> |
109 |
| - assertThat(context.getBean("otelOtlpSpanExporter", OtlpHttpSpanExporter.class)) |
110 |
| - .hasFieldOrProperty("delegate") |
111 |
| - .asString() |
112 |
| - .contains("x=OBFUSCATED, y=OBFUSCATED")); |
113 |
| - |
114 |
| - // Mockito.verify(otlpHttpSpanExporterBuilder).build(); |
115 |
| - // |
116 |
| - // Mockito.verify(otlpHttpSpanExporterBuilder).setEndpoint("http://localhost:4317/v1/traces"); |
117 |
| - // Mockito.verify(otlpHttpSpanExporterBuilder).addHeader("x", "1"); |
118 |
| - // Mockito.verify(otlpHttpSpanExporterBuilder).addHeader("y", "2"); |
119 |
| - // Mockito.verify(otlpHttpSpanExporterBuilder).setTimeout(java.time.Duration.ofSeconds(1)); |
120 |
| - // Mockito.verifyNoMoreInteractions(otlpHttpSpanExporterBuilder); |
121 |
| - } |
122 |
| - |
123 |
| - @Test |
124 |
| - @DisplayName("use http/protobuf with environment variables for headers using the MapConverter") |
125 |
| - void useHttpWithEnv() { |
126 |
| - this.contextRunner |
127 |
| - // .withBean(OtlpHttpSpanExporterBuilder.class, () -> otlpHttpSpanExporterBuilder) |
128 |
| - .withPropertyValues( |
129 |
| - "otel.exporter.otlp.enabled=true", "otel.exporter.otlp.protocol=http/protobuf") |
130 |
| - // are similar to environment variables in that they use the same converters |
131 |
| - .withSystemProperties("otel.exporter.otlp.headers=x=1,y=2") |
132 |
| - .run( |
133 |
| - context -> |
134 |
| - assertThat(context.getBean("otelOtlpSpanExporter", OtlpHttpSpanExporter.class)) |
135 |
| - .hasFieldOrProperty("delegate") |
136 |
| - .asString() |
137 |
| - .contains("x=OBFUSCATED, y=OBFUSCATED")); |
138 |
| - |
139 |
| - // Mockito.verify(otlpHttpSpanExporterBuilder).build(); |
140 |
| - // Mockito.verify(otlpHttpSpanExporterBuilder).addHeader("x", "1"); |
141 |
| - // Mockito.verify(otlpHttpSpanExporterBuilder).addHeader("y", "2"); |
142 |
| - // Mockito.verifyNoMoreInteractions(otlpHttpSpanExporterBuilder); |
143 |
| - } |
144 |
| - |
145 |
| - @Test |
146 |
| - @DisplayName("use grpc when protocol set") |
147 |
| - void useGrpc() { |
148 |
| - this.contextRunner |
149 |
| - .withPropertyValues("otel.exporter.otlp.protocol=grpc") |
150 |
| - .run( |
151 |
| - context -> |
152 |
| - assertThat(context.getBean(OtlpGrpcSpanExporter.class)) |
153 |
| - .as("Should contain the gRPC span exporter when grpc is set") |
154 |
| - .isNotNull()); |
155 |
| - } |
156 |
| - |
157 |
| - @Test |
158 |
| - @DisplayName("use http when unknown protocol set") |
159 |
| - void useHttpWhenAnUnknownProtocolIsSet() { |
160 |
| - this.contextRunner |
161 |
| - .withPropertyValues("otel.exporter.otlp.protocol=unknown") |
162 |
| - .run( |
163 |
| - context -> |
164 |
| - assertThat(context.getBean(OtlpHttpSpanExporter.class)) |
165 |
| - .as("Should contain the http span exporter when an unknown is set") |
166 |
| - .isNotNull()); |
167 |
| - } |
168 |
| - |
169 |
| - @Test |
170 |
| - @DisplayName("logging exporter can still be configured") |
171 |
| - void loggingExporter() { |
172 |
| - this.contextRunner |
173 |
| - .withBean( |
174 |
| - LoggingSpanExporter.class, |
175 |
| - LoggingSpanExporter::create, |
176 |
| - bd -> bd.setDestroyMethodName("")) |
177 |
| - .run( |
178 |
| - context -> |
179 |
| - assertThat( |
180 |
| - context.getBeanProvider(SpanExporter.class).stream() |
181 |
| - .collect(Collectors.toList())) |
182 |
| - .hasSize(2)); |
183 |
| - } |
184 | 61 | }
|
0 commit comments