31
31
import org .slf4j .MDC ;
32
32
33
33
import org .springframework .boot .actuate .autoconfigure .opentelemetry .OpenTelemetryAutoConfiguration ;
34
+ import org .springframework .boot .actuate .autoconfigure .tracing .OpenTelemetryEventPublisherApplicationListener .EventPublisherBeansContextWrapper ;
34
35
import org .springframework .boot .autoconfigure .AutoConfigurations ;
35
36
import org .springframework .boot .test .context .runner .ApplicationContextRunner ;
36
37
import org .springframework .boot .testsupport .classpath .ForkedClassPath ;
37
38
import org .springframework .context .ApplicationContext ;
39
+ import org .springframework .context .ApplicationContextInitializer ;
40
+ import org .springframework .context .ConfigurableApplicationContext ;
38
41
39
42
import static org .assertj .core .api .Assertions .assertThat ;
40
43
@@ -55,6 +58,7 @@ class BaggagePropagationIntegrationTests {
55
58
@ BeforeEach
56
59
@ AfterEach
57
60
void setup () {
61
+ EventPublisherBeansContextWrapper .addWrapperIfNecessary ();
58
62
MDC .clear ();
59
63
}
60
64
@@ -155,27 +159,32 @@ private void assertMdcValue(String key, String expected) {
155
159
enum AutoConfig implements Supplier <ApplicationContextRunner > {
156
160
157
161
BRAVE_DEFAULT {
162
+
158
163
@ Override
159
164
public ApplicationContextRunner get () {
160
165
return new ApplicationContextRunner ()
161
166
.withConfiguration (AutoConfigurations .of (BraveAutoConfiguration .class ))
162
167
.withPropertyValues ("management.tracing.baggage.remote-fields=x-vcap-request-id,country-code,bp" ,
163
168
"management.tracing.baggage.correlation.fields=country-code,bp" );
164
169
}
170
+
165
171
},
166
172
167
173
OTEL_DEFAULT {
174
+
168
175
@ Override
169
176
public ApplicationContextRunner get () {
170
- return new ApplicationContextRunner ().withConfiguration ( AutoConfigurations . of (
171
- OpenTelemetryAutoConfiguration .class ,
172
- org .springframework .boot .actuate .autoconfigure .tracing .OpenTelemetryAutoConfiguration .class ))
177
+ return new ApplicationContextRunner ().withInitializer ( new OtelApplicationContextInitializer ())
178
+ . withConfiguration ( AutoConfigurations . of ( OpenTelemetryAutoConfiguration .class ,
179
+ org .springframework .boot .actuate .autoconfigure .tracing .OpenTelemetryAutoConfiguration .class ))
173
180
.withPropertyValues ("management.tracing.baggage.remote-fields=x-vcap-request-id,country-code,bp" ,
174
181
"management.tracing.baggage.correlation.fields=country-code,bp" );
175
182
}
183
+
176
184
},
177
185
178
186
BRAVE_W3C {
187
+
179
188
@ Override
180
189
public ApplicationContextRunner get () {
181
190
return new ApplicationContextRunner ()
@@ -184,21 +193,25 @@ public ApplicationContextRunner get() {
184
193
"management.tracing.baggage.remote-fields=x-vcap-request-id,country-code,bp" ,
185
194
"management.tracing.baggage.correlation.fields=country-code,bp" );
186
195
}
196
+
187
197
},
188
198
189
199
OTEL_W3C {
200
+
190
201
@ Override
191
202
public ApplicationContextRunner get () {
192
- return new ApplicationContextRunner ().withConfiguration ( AutoConfigurations . of (
193
- OpenTelemetryAutoConfiguration .class ,
194
- org .springframework .boot .actuate .autoconfigure .tracing .OpenTelemetryAutoConfiguration .class ))
203
+ return new ApplicationContextRunner ().withInitializer ( new OtelApplicationContextInitializer ())
204
+ . withConfiguration ( AutoConfigurations . of ( OpenTelemetryAutoConfiguration .class ,
205
+ org .springframework .boot .actuate .autoconfigure .tracing .OpenTelemetryAutoConfiguration .class ))
195
206
.withPropertyValues ("management.tracing.propagation.type=W3C" ,
196
207
"management.tracing.baggage.remote-fields=x-vcap-request-id,country-code,bp" ,
197
208
"management.tracing.baggage.correlation.fields=country-code,bp" );
198
209
}
210
+
199
211
},
200
212
201
213
BRAVE_B3 {
214
+
202
215
@ Override
203
216
public ApplicationContextRunner get () {
204
217
return new ApplicationContextRunner ()
@@ -207,9 +220,11 @@ public ApplicationContextRunner get() {
207
220
"management.tracing.baggage.remote-fields=x-vcap-request-id,country-code,bp" ,
208
221
"management.tracing.baggage.correlation.fields=country-code,bp" );
209
222
}
223
+
210
224
},
211
225
212
226
BRAVE_B3_MULTI {
227
+
213
228
@ Override
214
229
public ApplicationContextRunner get () {
215
230
return new ApplicationContextRunner ()
@@ -218,40 +233,47 @@ public ApplicationContextRunner get() {
218
233
"management.tracing.baggage.remote-fields=x-vcap-request-id,country-code,bp" ,
219
234
"management.tracing.baggage.correlation.fields=country-code,bp" );
220
235
}
236
+
221
237
},
222
238
223
239
OTEL_B3 {
240
+
224
241
@ Override
225
242
public ApplicationContextRunner get () {
226
- return new ApplicationContextRunner ().withConfiguration ( AutoConfigurations . of (
227
- OpenTelemetryAutoConfiguration .class ,
228
- org .springframework .boot .actuate .autoconfigure .tracing .OpenTelemetryAutoConfiguration .class ))
243
+ return new ApplicationContextRunner ().withInitializer ( new OtelApplicationContextInitializer ())
244
+ . withConfiguration ( AutoConfigurations . of ( OpenTelemetryAutoConfiguration .class ,
245
+ org .springframework .boot .actuate .autoconfigure .tracing .OpenTelemetryAutoConfiguration .class ))
229
246
.withPropertyValues ("management.tracing.propagation.type=B3" ,
230
247
"management.tracing.baggage.remote-fields=x-vcap-request-id,country-code,bp" ,
231
248
"management.tracing.baggage.correlation.fields=country-code,bp" );
232
249
}
250
+
233
251
},
234
252
235
253
OTEL_B3_MULTI {
254
+
236
255
@ Override
237
256
public ApplicationContextRunner get () {
238
- return new ApplicationContextRunner ().withConfiguration ( AutoConfigurations . of (
239
- OpenTelemetryAutoConfiguration .class ,
240
- org .springframework .boot .actuate .autoconfigure .tracing .OpenTelemetryAutoConfiguration .class ))
257
+ return new ApplicationContextRunner ().withInitializer ( new OtelApplicationContextInitializer ())
258
+ . withConfiguration ( AutoConfigurations . of ( OpenTelemetryAutoConfiguration .class ,
259
+ org .springframework .boot .actuate .autoconfigure .tracing .OpenTelemetryAutoConfiguration .class ))
241
260
.withPropertyValues ("management.tracing.propagation.type=B3_MULTI" ,
242
261
"management.tracing.baggage.remote-fields=x-vcap-request-id,country-code,bp" ,
243
262
"management.tracing.baggage.correlation.fields=country-code,bp" );
244
263
}
264
+
245
265
},
246
266
247
267
BRAVE_LOCAL_FIELDS {
268
+
248
269
@ Override
249
270
public ApplicationContextRunner get () {
250
271
return new ApplicationContextRunner ()
251
272
.withConfiguration (AutoConfigurations .of (BraveAutoConfiguration .class ))
252
273
.withPropertyValues ("management.tracing.baggage.local-fields=country-code,bp" ,
253
274
"management.tracing.baggage.correlation.fields=country-code,bp" );
254
275
}
276
+
255
277
};
256
278
257
279
boolean isOtel () {
@@ -264,4 +286,14 @@ boolean isBrave() {
264
286
265
287
}
266
288
289
+ static class OtelApplicationContextInitializer
290
+ implements ApplicationContextInitializer <ConfigurableApplicationContext > {
291
+
292
+ @ Override
293
+ public void initialize (ConfigurableApplicationContext applicationContext ) {
294
+ applicationContext .addApplicationListener (new OpenTelemetryEventPublisherApplicationListener ());
295
+ }
296
+
297
+ }
298
+
267
299
}
0 commit comments