7373 *
7474 */
7575@ SpringJUnitConfig
76- @ RabbitAvailable (queues = { "observation.testQ1" , "observation.testQ2" })
76+ @ RabbitAvailable (queues = {"observation.testQ1" , "observation.testQ2" })
7777@ DirtiesContext
7878public class ObservationTests {
7979
8080 @ Test
8181 void endToEnd (@ Autowired Listener listener , @ Autowired RabbitTemplate template ,
8282 @ Autowired SimpleTracer tracer , @ Autowired RabbitListenerEndpointRegistry rler ,
8383 @ Autowired MeterRegistry meterRegistry )
84- throws InterruptedException {
84+ throws InterruptedException {
8585
8686 template .convertAndSend ("observation.testQ1" , "test" );
8787 assertThat (listener .latch1 .await (10 , TimeUnit .SECONDS )).isTrue ();
@@ -110,13 +110,14 @@ void endToEnd(@Autowired Listener listener, @Autowired RabbitTemplate template,
110110 .containsAllEntriesOf (
111111 Map .of ("spring.rabbit.listener.id" , "obs2" , "foo" , "some foo value" , "bar" , "some bar value" ));
112112 assertThat (span .getName ()).isEqualTo ("observation.testQ2 receive" );
113+
113114 template .setObservationConvention (new DefaultRabbitTemplateObservationConvention () {
114115
115116 @ Override
116117 public KeyValues getLowCardinalityKeyValues (RabbitMessageSenderContext context ) {
117118 return super .getLowCardinalityKeyValues (context ).and ("foo" , "bar" )
118- .and ("messaging.destination.name" , context .getExchange ())
119- .and ("messaging.rabbitmq.destination.routing_key" , context .getRoutingKey ());
119+ .and ("messaging.destination.name" , context .getExchange ())
120+ .and ("messaging.rabbitmq.destination.routing_key" , context .getRoutingKey ());
120121 }
121122
122123 });
@@ -211,16 +212,18 @@ MeterRegistry meterRegistry() {
211212
212213 @ Bean
213214 ObservationRegistry observationRegistry (Tracer tracer , Propagator propagator , MeterRegistry meterRegistry ) {
214- TestObservationRegistry observationRegistry = TestObservationRegistry .create ();
215+ TestObservationRegistry observationRegistry = TestObservationRegistry .builder ()
216+ .validateObservationsWithTheSameNameHavingTheSameSetOfLowCardinalityKeys (false )
217+ .build ();
215218 observationRegistry .observationConfig ().observationHandler (
216- // Composite will pick the first matching handler
217- new ObservationHandler .FirstMatchingCompositeObservationHandler (
218- // This is responsible for creating a child span on the sender side
219- new PropagatingSenderTracingObservationHandler <>(tracer , propagator ),
220- // This is responsible for creating a span on the receiver side
221- new PropagatingReceiverTracingObservationHandler <>(tracer , propagator ),
222- // This is responsible for creating a default span
223- new DefaultTracingObservationHandler (tracer )))
219+ // Composite will pick the first matching handler
220+ new ObservationHandler .FirstMatchingCompositeObservationHandler (
221+ // This is responsible for creating a child span on the sender side
222+ new PropagatingSenderTracingObservationHandler <>(tracer , propagator ),
223+ // This is responsible for creating a span on the receiver side
224+ new PropagatingReceiverTracingObservationHandler <>(tracer , propagator ),
225+ // This is responsible for creating a default span
226+ new DefaultTracingObservationHandler (tracer )))
224227 .observationHandler (new DefaultMeterObservationHandler (meterRegistry ));
225228 return observationRegistry ;
226229 }
@@ -244,7 +247,7 @@ public <C> void inject(TraceContext context, @Nullable C carrier, Setter<C> sett
244247 }
245248
246249 // This is called on the consumer side when the message is consumed
247- // Normally we would use tools like Extractor from tracing but for tests we are just manually creating a span
250+ // Normally we would use tools like Extractor from tracing, but for tests we are just manually creating a span
248251 @ Override
249252 public <C > Span .Builder extract (C carrier , Getter <C > getter ) {
250253 String foo = getter .get (carrier , "foo" );
0 commit comments