99import static io .opentelemetry .exporter .zipkin .ZipkinTestUtil .zipkinSpanBuilder ;
1010import static org .assertj .core .api .Assertions .assertThat ;
1111import static org .assertj .core .api .Assertions .assertThatThrownBy ;
12+ import static org .junit .jupiter .api .Assertions .assertFalse ;
13+ import static org .junit .jupiter .api .Assertions .assertTrue ;
1214import static org .mockito .Mockito .doThrow ;
1315import static org .mockito .Mockito .verify ;
1416import static org .mockito .Mockito .when ;
1517
1618import io .github .netmikey .logunit .api .LogCapturer ;
19+ import io .opentelemetry .api .internal .InstrumentationUtil ;
1720import io .opentelemetry .api .metrics .MeterProvider ;
21+ import io .opentelemetry .context .Context ;
1822import io .opentelemetry .internal .testing .slf4j .SuppressLogger ;
1923import io .opentelemetry .sdk .common .CompletableResultCode ;
2024import io .opentelemetry .sdk .testing .trace .TestSpanData ;
2327import java .time .Duration ;
2428import java .util .Collections ;
2529import java .util .concurrent .TimeUnit ;
30+ import java .util .concurrent .atomic .AtomicBoolean ;
2631import org .junit .jupiter .api .Test ;
2732import org .junit .jupiter .api .extension .ExtendWith ;
2833import org .junit .jupiter .api .extension .RegisterExtension ;
3338import zipkin2 .reporter .BytesMessageSender ;
3439import zipkin2 .reporter .Encoding ;
3540import zipkin2 .reporter .SpanBytesEncoder ;
41+ import zipkin2 .reporter .okhttp3 .OkHttpSender ;
3642
3743@ ExtendWith (MockitoExtension .class )
3844class ZipkinSpanExporterTest {
@@ -119,18 +125,18 @@ void testShutdown() throws IOException {
119125 verify (mockSender ).close ();
120126 assertThat (logs .getEvents ()).isEmpty ();
121127 assertThat (
122- exporter
123- .export (Collections .singletonList (spanBuilder ().build ()))
124- .join (10 , TimeUnit .SECONDS )
125- .isSuccess ())
128+ exporter
129+ .export (Collections .singletonList (spanBuilder ().build ()))
130+ .join (10 , TimeUnit .SECONDS )
131+ .isSuccess ())
126132 .isFalse ();
127133 assertThat (exporter .shutdown ().isSuccess ()).isTrue ();
128134 logs .assertContains ("Calling shutdown() multiple times." );
129135 }
130136
131137 @ Test
132138 @ SuppressWarnings ({"PreferJavaTimeOverload" , "deprecation" })
133- // we have to use the deprecated setEncoder overload to test it
139+ // we have to use the deprecated setEncoder overload to test it
134140 void invalidConfig () {
135141 assertThatThrownBy (() -> ZipkinSpanExporter .builder ().setReadTimeout (-1 , TimeUnit .MILLISECONDS ))
136142 .isInstanceOf (IllegalArgumentException .class )
@@ -157,7 +163,7 @@ void invalidConfig() {
157163 .hasMessage ("sender" );
158164
159165 assertThatThrownBy (
160- () -> ZipkinSpanExporter .builder ().setEncoder ((zipkin2 .codec .BytesEncoder <Span >) null ))
166+ () -> ZipkinSpanExporter .builder ().setEncoder ((zipkin2 .codec .BytesEncoder <Span >) null ))
161167 .isInstanceOf (NullPointerException .class )
162168 .hasMessage ("encoder" );
163169
@@ -244,4 +250,28 @@ void stringRepresentation() {
244250 "ZipkinSpanExporter{endpoint=http://zipkin:9411/api/v2/spans, compressionEnabled=false, readTimeoutMillis=15000}" );
245251 }
246252 }
253+
254+ @ Test
255+ void testSuppressInstrumentation () {
256+ AtomicBoolean suppressInstrumentation = new AtomicBoolean (
257+ InstrumentationUtil .shouldSuppressInstrumentation (Context .current ()));
258+
259+ assertFalse (suppressInstrumentation .get ());
260+
261+ InstrumentationUtil .suppressInstrumentation (() ->
262+ {
263+ try (BytesMessageSender sender = OkHttpSender .newBuilder ().endpoint ("https://localhost" )
264+ .encoding (Encoding .PROTO3 )
265+ .build ()) {
266+ sender .send (Collections .singletonList (new byte [0 ]));
267+ } catch (IOException e ) {
268+ //it always goes here
269+ suppressInstrumentation .set (
270+ InstrumentationUtil .shouldSuppressInstrumentation (Context .current ()));
271+ }
272+ }
273+ );
274+ assertTrue (suppressInstrumentation .get ());
275+ }
276+
247277}
0 commit comments