@@ -62,23 +62,23 @@ void shouldSetEntriesToMdcFromSpanWithBaggage(AutoConfig autoConfig) {
6262 autoConfig .get ().run ((context ) -> {
6363 Tracer tracer = tracer (context );
6464 Span span = createSpan (tracer );
65+ BaggageManager baggageManager = baggageManager (context );
6566 assertThatTracingContextIsInitialized (autoConfig );
6667 try (Tracer .SpanInScope scope = tracer .withSpan (span .start ())) {
67- BaggageManager baggageManager = baggageManager ( context );
68+ assertMdcValue ( "traceId" , span . context (). traceId () );
6869 try (BaggageInScope fo = baggageManager .createBaggageInScope (span .context (), COUNTRY_CODE , "FO" );
6970 BaggageInScope alm = baggageManager .createBaggageInScope (span .context (), BUSINESS_PROCESS ,
7071 "ALM" )) {
71- assertThat (MDC .get ("traceId" )).isEqualTo (span .context ().traceId ());
72- assertThat (MDC .get (COUNTRY_CODE )).isEqualTo ("FO" );
73- assertThat (MDC .get (BUSINESS_PROCESS )).isEqualTo ("ALM" );
72+ assertMdcValue (COUNTRY_CODE , "FO" );
73+ assertMdcValue (BUSINESS_PROCESS , "ALM" );
7474 }
7575 }
7676 finally {
7777 span .end ();
7878 }
7979 assertThatMdcContainsUnsetTraceId (autoConfig );
80- assertThat ( MDC . get ( COUNTRY_CODE )). isNull ( );
81- assertThat ( MDC . get ( BUSINESS_PROCESS )). isNull ( );
80+ assertUnsetMdc ( COUNTRY_CODE );
81+ assertUnsetMdc ( BUSINESS_PROCESS );
8282 });
8383 }
8484
@@ -88,25 +88,25 @@ void shouldRemoveEntriesFromMdcForNullSpan(AutoConfig autoConfig) {
8888 autoConfig .get ().run ((context ) -> {
8989 Tracer tracer = tracer (context );
9090 Span span = createSpan (tracer );
91+ BaggageManager baggageManager = baggageManager (context );
9192 assertThatTracingContextIsInitialized (autoConfig );
9293 try (Tracer .SpanInScope scope = tracer .withSpan (span .start ())) {
93- try (BaggageInScope fo = baggageManager (context ).createBaggageInScope (span .context (), COUNTRY_CODE ,
94- "FO" )) {
95- assertThat (MDC .get ("traceId" )).isEqualTo (span .context ().traceId ());
96- assertThat (MDC .get (COUNTRY_CODE )).isEqualTo ("FO" );
94+ assertMdcValue ("traceId" , span .context ().traceId ());
95+ try (BaggageInScope fo = baggageManager .createBaggageInScope (span .context (), COUNTRY_CODE , "FO" )) {
96+ assertMdcValue (COUNTRY_CODE , "FO" );
9797 try (Tracer .SpanInScope scope2 = tracer .withSpan (null )) {
9898 assertThatMdcContainsUnsetTraceId (autoConfig );
99- assertThat ( MDC . get ( COUNTRY_CODE )). isNull ( );
99+ assertUnsetMdc ( COUNTRY_CODE );
100100 }
101- assertThat ( MDC . get ( "traceId" )). isEqualTo ( span .context ().traceId ());
102- assertThat ( MDC . get ( COUNTRY_CODE )). isEqualTo ( "FO" );
101+ assertMdcValue ( "traceId" , span .context ().traceId ());
102+ assertMdcValue ( COUNTRY_CODE , "FO" );
103103 }
104104 }
105105 finally {
106106 span .end ();
107107 }
108108 assertThatMdcContainsUnsetTraceId (autoConfig );
109- assertThat ( MDC . get ( COUNTRY_CODE )). isNull ( );
109+ assertUnsetMdc ( COUNTRY_CODE );
110110 });
111111 }
112112
@@ -142,6 +142,14 @@ private void assertThatMdcContainsUnsetTraceId(AutoConfig autoConfig) {
142142 }
143143 }
144144
145+ private void assertUnsetMdc (String key ) {
146+ assertThat (MDC .get (key )).as ("MDC[%s]" , key ).isNull ();
147+ }
148+
149+ private void assertMdcValue (String key , String expected ) {
150+ assertThat (MDC .get (key )).as ("MDC[%s]" , key ).isEqualTo (expected );
151+ }
152+
145153 enum AutoConfig implements Supplier <ApplicationContextRunner > {
146154
147155 BRAVE_DEFAULT {
0 commit comments