33package com .azure ;
44
55import static java .util .concurrent .TimeUnit .SECONDS ;
6+ import static org .assertj .core .api .Assertions .*;
67import static org .assertj .core .api .Assertions .assertThat ;
78
89import com .azure .core .http .*;
910import com .azure .core .http .policy .HttpPipelinePolicy ;
1011import 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 ;
1115import java .net .MalformedURLException ;
1216import java .net .URL ;
1317import java .util .List ;
1418import java .util .concurrent .CountDownLatch ;
1519import java .util .stream .Collectors ;
16-
1720import org .junit .jupiter .api .Test ;
21+ import org .springframework .beans .factory .ObjectProvider ;
1822import org .springframework .beans .factory .annotation .Autowired ;
1923import org .springframework .boot .test .context .SpringBootTest ;
2024import 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