@@ -75,120 +75,6 @@ void AssertIntTagGreaterThanZero(Activity activity, string name)
7575 Assert . True ( activity . GetTagItem ( name ) is int result && result > 0 ) ;
7676 }
7777
78- [ Theory ]
79- [ InlineData ( true , true ) ]
80- [ InlineData ( true , false ) ]
81- [ InlineData ( false , true ) ]
82- [ InlineData ( false , false ) ]
83- public async Task TestPublisherAndConsumerActivityTags ( bool useRoutingKeyAsOperationName , bool usePublisherAsParent )
84- {
85- RabbitMQActivitySource . UseRoutingKeyAsOperationName = useRoutingKeyAsOperationName ;
86- RabbitMQActivitySource . TracingOptions . UsePublisherAsParent = usePublisherAsParent ;
87- var _activities = new List < Activity > ( ) ;
88- using ActivityListener activityListener = StartActivityListener ( _activities ) ;
89- await Task . Delay ( 500 ) ;
90- string queueName = $ "{ Guid . NewGuid ( ) } ";
91- QueueDeclareOk q = await _channel . QueueDeclareAsync ( queueName ) ;
92- byte [ ] sendBody = Encoding . UTF8 . GetBytes ( "hi" ) ;
93- byte [ ] consumeBody = null ;
94- var consumer = new AsyncEventingBasicConsumer ( _channel ) ;
95- var consumerReceivedTcs =
96- new TaskCompletionSource < bool > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
97- consumer . ReceivedAsync += ( o , a ) =>
98- {
99- consumeBody = a . Body . ToArray ( ) ;
100- consumerReceivedTcs . SetResult ( true ) ;
101- return Task . CompletedTask ;
102- } ;
103-
104- string consumerTag = await _channel . BasicConsumeAsync ( queueName , autoAck : true , consumer : consumer ) ;
105- await _channel . BasicPublishAsync ( "" , q . QueueName , true , sendBody ) ;
106-
107- await consumerReceivedTcs . Task . WaitAsync ( TimeSpan . FromSeconds ( 5 ) ) ;
108- Assert . True ( await consumerReceivedTcs . Task ) ;
109-
110- await _channel . BasicCancelAsync ( consumerTag ) ;
111- await Task . Delay ( 500 ) ;
112- AssertActivityData ( useRoutingKeyAsOperationName , usePublisherAsParent , queueName , _activities , true ) ;
113- }
114-
115- [ Theory ]
116- [ InlineData ( true , true ) ]
117- [ InlineData ( true , false ) ]
118- [ InlineData ( false , true ) ]
119- [ InlineData ( false , false ) ]
120- public async Task TestPublisherWithCachedStringsAndConsumerActivityTags ( bool useRoutingKeyAsOperationName , bool usePublisherAsParent )
121- {
122- RabbitMQActivitySource . UseRoutingKeyAsOperationName = useRoutingKeyAsOperationName ;
123- RabbitMQActivitySource . TracingOptions . UsePublisherAsParent = usePublisherAsParent ;
124- var _activities = new List < Activity > ( ) ;
125- using ActivityListener activityListener = StartActivityListener ( _activities ) ;
126- await Task . Delay ( 500 ) ;
127- string queueName = $ "{ Guid . NewGuid ( ) } ";
128- QueueDeclareOk q = await _channel . QueueDeclareAsync ( queueName ) ;
129- byte [ ] sendBody = Encoding . UTF8 . GetBytes ( "hi" ) ;
130- byte [ ] consumeBody = null ;
131- var consumer = new AsyncEventingBasicConsumer ( _channel ) ;
132- var consumerReceivedTcs =
133- new TaskCompletionSource < bool > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
134- consumer . ReceivedAsync += ( o , a ) =>
135- {
136- consumeBody = a . Body . ToArray ( ) ;
137- consumerReceivedTcs . SetResult ( true ) ;
138- return Task . CompletedTask ;
139- } ;
140-
141- string consumerTag = await _channel . BasicConsumeAsync ( queueName , autoAck : true , consumer : consumer ) ;
142- CachedString exchange = new CachedString ( "" ) ;
143- CachedString routingKey = new CachedString ( q . QueueName ) ;
144- await _channel . BasicPublishAsync ( exchange , routingKey , true , sendBody ) ;
145-
146- await consumerReceivedTcs . Task . WaitAsync ( TimeSpan . FromSeconds ( 5 ) ) ;
147- Assert . True ( await consumerReceivedTcs . Task ) ;
148-
149- await _channel . BasicCancelAsync ( consumerTag ) ;
150- await Task . Delay ( 500 ) ;
151- AssertActivityData ( useRoutingKeyAsOperationName , usePublisherAsParent , queueName , _activities , true ) ;
152- }
153-
154- [ Theory ]
155- [ InlineData ( true , true ) ]
156- [ InlineData ( true , false ) ]
157- [ InlineData ( false , true ) ]
158- [ InlineData ( false , false ) ]
159- public async Task TestPublisherWithPublicationAddressAndConsumerActivityTags ( bool useRoutingKeyAsOperationName , bool usePublisherAsParent )
160- {
161- RabbitMQActivitySource . UseRoutingKeyAsOperationName = useRoutingKeyAsOperationName ;
162- RabbitMQActivitySource . TracingOptions . UsePublisherAsParent = usePublisherAsParent ;
163- var _activities = new List < Activity > ( ) ;
164- using ActivityListener activityListener = StartActivityListener ( _activities ) ;
165- await Task . Delay ( 500 ) ;
166- string queueName = $ "{ Guid . NewGuid ( ) } ";
167- QueueDeclareOk q = await _channel . QueueDeclareAsync ( queueName ) ;
168- byte [ ] sendBody = Encoding . UTF8 . GetBytes ( "hi" ) ;
169- byte [ ] consumeBody = null ;
170- var consumer = new AsyncEventingBasicConsumer ( _channel ) ;
171- var consumerReceivedTcs =
172- new TaskCompletionSource < bool > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
173- consumer . ReceivedAsync += ( o , a ) =>
174- {
175- consumeBody = a . Body . ToArray ( ) ;
176- consumerReceivedTcs . SetResult ( true ) ;
177- return Task . CompletedTask ;
178- } ;
179-
180- string consumerTag = await _channel . BasicConsumeAsync ( queueName , autoAck : true , consumer : consumer ) ;
181- PublicationAddress publicationAddress = new PublicationAddress ( ExchangeType . Direct , "" , q . QueueName ) ;
182- await _channel . BasicPublishAsync ( publicationAddress , new BasicProperties ( ) , sendBody ) ;
183-
184- await consumerReceivedTcs . Task . WaitAsync ( TimeSpan . FromSeconds ( 5 ) ) ;
185- Assert . True ( await consumerReceivedTcs . Task ) ;
186-
187- await _channel . BasicCancelAsync ( consumerTag ) ;
188- await Task . Delay ( 500 ) ;
189- AssertActivityData ( useRoutingKeyAsOperationName , usePublisherAsParent , queueName , _activities , true ) ;
190- }
191-
19278 [ Theory ]
19379 [ InlineData ( true , true ) ]
19480 [ InlineData ( true , false ) ]
@@ -307,11 +193,15 @@ public async Task TestPublisherWithPublicationAddressAndConsumerActivityTagsAsyn
307193 }
308194
309195 [ Theory ]
310- [ InlineData ( true , true ) ]
311- [ InlineData ( true , false ) ]
312- [ InlineData ( false , true ) ]
313- [ InlineData ( false , false ) ]
314- public async Task TestPublisherAndBasicGetActivityTags ( bool useRoutingKeyAsOperationName , bool usePublisherAsParent )
196+ [ InlineData ( true , true , true ) ]
197+ [ InlineData ( true , true , false ) ]
198+ [ InlineData ( true , false , true ) ]
199+ [ InlineData ( true , false , false ) ]
200+ [ InlineData ( false , true , true ) ]
201+ [ InlineData ( false , true , false ) ]
202+ [ InlineData ( false , false , true ) ]
203+ [ InlineData ( false , false , false ) ]
204+ public async Task TestPublisherAndBasicGetActivityTagsAsync ( bool useRoutingKeyAsOperationName , bool usePublisherAsParent , bool useMessageId )
315205 {
316206 RabbitMQActivitySource . UseRoutingKeyAsOperationName = useRoutingKeyAsOperationName ;
317207 RabbitMQActivitySource . TracingOptions . UsePublisherAsParent = usePublisherAsParent ;
@@ -321,18 +211,20 @@ public async Task TestPublisherAndBasicGetActivityTags(bool useRoutingKeyAsOpera
321211 string queue = $ "queue-{ Guid . NewGuid ( ) } ";
322212 const string msg = "for basic.get" ;
323213
214+ var basicProps = useMessageId ? new BasicProperties ( ) { MessageId = Guid . NewGuid ( ) . ToString ( ) } : new BasicProperties ( ) ;
215+
324216 try
325217 {
326218 await _channel . QueueDeclareAsync ( queue , false , false , false , null ) ;
327- await _channel . BasicPublishAsync ( "" , queue , true , Encoding . UTF8 . GetBytes ( msg ) ) ;
219+ await _channel . BasicPublishAsync ( "" , queue , true , basicProps , Encoding . UTF8 . GetBytes ( msg ) ) ;
328220 QueueDeclareOk ok = await _channel . QueueDeclarePassiveAsync ( queue ) ;
329221 Assert . Equal ( 1u , ok . MessageCount ) ;
330222 BasicGetResult res = await _channel . BasicGetAsync ( queue , true ) ;
331223 Assert . Equal ( msg , Encoding . UTF8 . GetString ( res . Body . ToArray ( ) ) ) ;
332224 ok = await _channel . QueueDeclarePassiveAsync ( queue ) ;
333225 Assert . Equal ( 0u , ok . MessageCount ) ;
334226 await Task . Delay ( 500 ) ;
335- AssertActivityData ( useRoutingKeyAsOperationName , usePublisherAsParent , queue , activities , false ) ;
227+ AssertActivityData ( useRoutingKeyAsOperationName , usePublisherAsParent , queue , activities , false , basicProps . MessageId ) ;
336228 }
337229 finally
338230 {
@@ -345,7 +237,7 @@ public async Task TestPublisherAndBasicGetActivityTags(bool useRoutingKeyAsOpera
345237 [ InlineData ( true , false ) ]
346238 [ InlineData ( false , true ) ]
347239 [ InlineData ( false , false ) ]
348- public async Task TestPublisherWithCachedStringsAndBasicGetActivityTags ( bool useRoutingKeyAsOperationName , bool usePublisherAsParent )
240+ public async Task TestPublisherWithCachedStringsAndBasicGetActivityTagsAsync ( bool useRoutingKeyAsOperationName , bool usePublisherAsParent )
349241 {
350242 RabbitMQActivitySource . UseRoutingKeyAsOperationName = useRoutingKeyAsOperationName ;
351243 RabbitMQActivitySource . TracingOptions . UsePublisherAsParent = usePublisherAsParent ;
@@ -381,7 +273,7 @@ public async Task TestPublisherWithCachedStringsAndBasicGetActivityTags(bool use
381273 [ InlineData ( true , false ) ]
382274 [ InlineData ( false , true ) ]
383275 [ InlineData ( false , false ) ]
384- public async Task TestPublisherWithPublicationAddressAndBasicGetActivityTags ( bool useRoutingKeyAsOperationName , bool usePublisherAsParent )
276+ public async Task TestPublisherWithPublicationAddressAndBasicGetActivityTagsAsync ( bool useRoutingKeyAsOperationName , bool usePublisherAsParent )
385277 {
386278 RabbitMQActivitySource . UseRoutingKeyAsOperationName = useRoutingKeyAsOperationName ;
387279 RabbitMQActivitySource . TracingOptions . UsePublisherAsParent = usePublisherAsParent ;
@@ -427,7 +319,7 @@ private static ActivityListener StartActivityListener(List<Activity> activities)
427319 }
428320
429321 private void AssertActivityData ( bool useRoutingKeyAsOperationName , bool usePublisherAsParent , string queueName ,
430- List < Activity > activityList , bool isDeliver = false )
322+ List < Activity > activityList , bool isDeliver = false , string messageId = null )
431323 {
432324 string childName = isDeliver ? "deliver" : "fetch" ;
433325 Activity [ ] activities = activityList . ToArray ( ) ;
@@ -480,6 +372,12 @@ private void AssertActivityData(bool useRoutingKeyAsOperationName, bool usePubli
480372 AssertIntTagGreaterThanZero ( sendActivity , RabbitMQActivitySource . MessagingEnvelopeSize ) ;
481373 AssertIntTagGreaterThanZero ( sendActivity , RabbitMQActivitySource . MessagingBodySize ) ;
482374 AssertIntTagGreaterThanZero ( receiveActivity , RabbitMQActivitySource . MessagingBodySize ) ;
375+
376+ if ( messageId is not null )
377+ {
378+ AssertStringTagEquals ( sendActivity , RabbitMQActivitySource . MessageId , messageId ) ;
379+ AssertStringTagEquals ( receiveActivity , RabbitMQActivitySource . MessageId , messageId ) ;
380+ }
483381 }
484382 }
485383}
0 commit comments