31
31
import org .assertj .core .api .AbstractStringAssert ;
32
32
import org .junit .jupiter .api .AfterAll ;
33
33
import org .junit .jupiter .api .BeforeAll ;
34
+ import org .junit .jupiter .api .Test ;
34
35
import org .junit .jupiter .api .extension .RegisterExtension ;
35
36
import org .junit .jupiter .params .ParameterizedTest ;
36
37
import org .junit .jupiter .params .provider .ValueSource ;
37
38
import org .springframework .amqp .core .AmqpTemplate ;
39
+ import org .springframework .amqp .core .AnonymousQueue ;
38
40
import org .springframework .amqp .core .Queue ;
39
41
import org .springframework .amqp .rabbit .annotation .RabbitListener ;
40
42
import org .springframework .boot .SpringApplication ;
45
47
import org .testcontainers .containers .GenericContainer ;
46
48
import org .testcontainers .containers .wait .strategy .Wait ;
47
49
48
- public class ContextPropagationTest {
50
+ public class SpringRabbitMqTest {
49
51
50
52
@ RegisterExtension
51
53
private static final InstrumentationExtension testing = AgentInstrumentationExtension .create ();
@@ -128,7 +130,7 @@ private static List<AttributeAssertion> getAssertions(
128
130
129
131
@ ParameterizedTest
130
132
@ ValueSource (booleans = {true , false })
131
- public void test (boolean testHeaders ) throws Exception {
133
+ public void testContextPropagation (boolean testHeaders ) throws Exception {
132
134
try (Connection connection = connectionFactory .newConnection ()) {
133
135
try (Channel ignored = connection .createChannel ()) {
134
136
testing .runWithSpan (
@@ -218,6 +220,35 @@ public void test(boolean testHeaders) throws Exception {
218
220
}
219
221
}
220
222
223
+ @ Test
224
+ public void testAnonymousQueueSpanName () throws Exception {
225
+ try (Connection connection = connectionFactory .newConnection ()) {
226
+ try (Channel ignored = connection .createChannel ()) {
227
+ String anonymousQueueName = applicationContext .getBean (AnonymousQueue .class ).getName ();
228
+ applicationContext .getBean (AmqpTemplate .class ).convertAndSend (anonymousQueueName , "test" );
229
+ applicationContext .getBean (AmqpTemplate .class ).receive (anonymousQueueName , 5000 );
230
+
231
+ testing .waitAndAssertTraces (
232
+ trace ->
233
+ trace .hasSpansSatisfyingExactly (
234
+ span -> span .hasName ("<default> publish" ),
235
+ // Verify that a constant span name is used instead of the randomly generated
236
+ // anonymous queue name
237
+ span ->
238
+ span .hasName ("<generated> process" )
239
+ .hasAttribute (
240
+ equalTo (
241
+ MessagingIncubatingAttributes
242
+ .MESSAGING_RABBITMQ_DESTINATION_ROUTING_KEY ,
243
+ anonymousQueueName ))),
244
+ trace -> trace .hasSpansSatisfyingExactly (span -> span .hasName ("basic.qos" )),
245
+ trace -> trace .hasSpansSatisfyingExactly (span -> span .hasName ("basic.consume" )),
246
+ trace -> trace .hasSpansSatisfyingExactly (span -> span .hasName ("basic.cancel" )),
247
+ trace -> trace .hasSpansSatisfyingExactly (span -> span .hasName ("basic.ack" )));
248
+ }
249
+ }
250
+ }
251
+
221
252
@ SpringBootConfiguration
222
253
@ EnableAutoConfiguration
223
254
static class ConsumerConfig {
@@ -229,6 +260,11 @@ Queue testQueue() {
229
260
return new Queue (TEST_QUEUE );
230
261
}
231
262
263
+ @ Bean
264
+ AnonymousQueue anonymousQueue () {
265
+ return new AnonymousQueue ();
266
+ }
267
+
232
268
@ RabbitListener (queues = TEST_QUEUE )
233
269
void consume (String ignored ) {
234
270
GlobalTraceUtil .runWithSpan ("consumer" , () -> {});
0 commit comments