@@ -62,23 +62,23 @@ void shouldSetEntriesToMdcFromSpanWithBaggage(AutoConfig autoConfig) {
62
62
autoConfig .get ().run ((context ) -> {
63
63
Tracer tracer = tracer (context );
64
64
Span span = createSpan (tracer );
65
+ BaggageManager baggageManager = baggageManager (context );
65
66
assertThatTracingContextIsInitialized (autoConfig );
66
67
try (Tracer .SpanInScope scope = tracer .withSpan (span .start ())) {
67
- BaggageManager baggageManager = baggageManager ( context );
68
+ assertMdcValue ( "traceId" , span . context (). traceId () );
68
69
try (BaggageInScope fo = baggageManager .createBaggageInScope (span .context (), COUNTRY_CODE , "FO" );
69
70
BaggageInScope alm = baggageManager .createBaggageInScope (span .context (), BUSINESS_PROCESS ,
70
71
"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" );
74
74
}
75
75
}
76
76
finally {
77
77
span .end ();
78
78
}
79
79
assertThatMdcContainsUnsetTraceId (autoConfig );
80
- assertThat ( MDC . get ( COUNTRY_CODE )). isNull ( );
81
- assertThat ( MDC . get ( BUSINESS_PROCESS )). isNull ( );
80
+ assertUnsetMdc ( COUNTRY_CODE );
81
+ assertUnsetMdc ( BUSINESS_PROCESS );
82
82
});
83
83
}
84
84
@@ -88,25 +88,25 @@ void shouldRemoveEntriesFromMdcForNullSpan(AutoConfig autoConfig) {
88
88
autoConfig .get ().run ((context ) -> {
89
89
Tracer tracer = tracer (context );
90
90
Span span = createSpan (tracer );
91
+ BaggageManager baggageManager = baggageManager (context );
91
92
assertThatTracingContextIsInitialized (autoConfig );
92
93
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" );
97
97
try (Tracer .SpanInScope scope2 = tracer .withSpan (null )) {
98
98
assertThatMdcContainsUnsetTraceId (autoConfig );
99
- assertThat ( MDC . get ( COUNTRY_CODE )). isNull ( );
99
+ assertUnsetMdc ( COUNTRY_CODE );
100
100
}
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" );
103
103
}
104
104
}
105
105
finally {
106
106
span .end ();
107
107
}
108
108
assertThatMdcContainsUnsetTraceId (autoConfig );
109
- assertThat ( MDC . get ( COUNTRY_CODE )). isNull ( );
109
+ assertUnsetMdc ( COUNTRY_CODE );
110
110
});
111
111
}
112
112
@@ -142,6 +142,14 @@ private void assertThatMdcContainsUnsetTraceId(AutoConfig autoConfig) {
142
142
}
143
143
}
144
144
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
+
145
153
enum AutoConfig implements Supplier <ApplicationContextRunner > {
146
154
147
155
BRAVE_DEFAULT {
0 commit comments