Skip to content

Commit 33bcb13

Browse files
authored
Add tests to verify that OTel exporters are not used by Spring Monitor (Azure#36585)
1 parent 2f29660 commit 33bcb13

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

sdk/spring/spring-cloud-azure-starter-monitor-test/src/test/java/com/azure/SpringMonitorTest.java

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@
33
package com.azure;
44

55
import static java.util.concurrent.TimeUnit.SECONDS;
6+
import static org.assertj.core.api.Assertions.*;
67
import static org.assertj.core.api.Assertions.assertThat;
78

89
import com.azure.core.http.*;
910
import com.azure.core.http.policy.HttpPipelinePolicy;
1011
import com.azure.monitor.opentelemetry.exporter.implementation.models.*;
12+
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
13+
import io.opentelemetry.sdk.metrics.export.MetricExporter;
14+
import io.opentelemetry.sdk.trace.export.SpanExporter;
1115
import java.net.MalformedURLException;
1216
import java.net.URL;
1317
import java.util.List;
1418
import java.util.concurrent.CountDownLatch;
1519
import java.util.stream.Collectors;
16-
1720
import org.junit.jupiter.api.Test;
21+
import org.springframework.beans.factory.ObjectProvider;
1822
import org.springframework.beans.factory.annotation.Autowired;
1923
import org.springframework.boot.test.context.SpringBootTest;
2024
import org.springframework.boot.test.web.client.TestRestTemplate;
@@ -36,6 +40,15 @@ public class SpringMonitorTest {
3640

3741
@Autowired private TestRestTemplate restTemplate;
3842

43+
// See io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration
44+
@Autowired ObjectProvider<List<SpanExporter>> otelSpanExportersProvider;
45+
46+
// See io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration
47+
@Autowired ObjectProvider<List<LogRecordExporter>> otelLoggerExportersProvider;
48+
49+
// See io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration
50+
@Autowired ObjectProvider<List<MetricExporter>> otelMetricExportersProvider;
51+
3952
@Configuration(proxyBeanMethods = false)
4053
static class TestConfiguration {
4154

@@ -54,6 +67,42 @@ HttpPipeline getHttpPipeline(@Nullable HttpPipelinePolicy policy) {
5467
}
5568
}
5669

70+
@Test
71+
public void applicationContextShouldOnlyContainTheAzureSpanExporter() {
72+
List<SpanExporter> spanExporters = otelSpanExportersProvider.getIfAvailable();
73+
assertThat(spanExporters).hasSize(1);
74+
75+
SpanExporter spanExporter = spanExporters.get(0);
76+
String exporterClassName = spanExporter.getClass().getName();
77+
assertThat(exporterClassName)
78+
.isEqualTo(
79+
"com.azure.monitor.opentelemetry.exporter.AzureMonitorTraceExporter"); // AzureMonitorTraceExporter is not public
80+
}
81+
82+
@Test
83+
public void applicationContextShouldOnlyContainTheAzureLogRecordExporter() {
84+
List<LogRecordExporter> logRecordExporters = otelLoggerExportersProvider.getIfAvailable();
85+
assertThat(logRecordExporters).hasSize(1);
86+
87+
LogRecordExporter logRecordExporter = logRecordExporters.get(0);
88+
String exporterClassName = logRecordExporter.getClass().getName();
89+
assertThat(exporterClassName)
90+
.isEqualTo(
91+
"com.azure.monitor.opentelemetry.exporter.AzureMonitorLogRecordExporter"); // AzureMonitorLogRecordExporter is not public
92+
}
93+
94+
@Test
95+
public void applicationContextShouldOnlyContainTheAzureMetricExporter() {
96+
List<MetricExporter> metricExporters = otelMetricExportersProvider.getIfAvailable();
97+
assertThat(metricExporters).hasSize(1);
98+
99+
MetricExporter metricExporter = metricExporters.get(0);
100+
String exporterClassName = metricExporter.getClass().getName();
101+
assertThat(exporterClassName)
102+
.isEqualTo(
103+
"com.azure.monitor.opentelemetry.exporter.AzureMonitorMetricExporter"); // AzureMonitorMetricExporter is not public
104+
}
105+
57106
@Test
58107
public void shouldMonitor() throws InterruptedException, MalformedURLException {
59108
String response = restTemplate.getForObject(Controller.URL, String.class);

0 commit comments

Comments
 (0)