@@ -75,120 +75,6 @@ void AssertIntTagGreaterThanZero(Activity activity, string name)
75
75
Assert . True ( activity . GetTagItem ( name ) is int result && result > 0 ) ;
76
76
}
77
77
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
-
192
78
[ Theory ]
193
79
[ InlineData ( true , true ) ]
194
80
[ InlineData ( true , false ) ]
@@ -307,11 +193,15 @@ public async Task TestPublisherWithPublicationAddressAndConsumerActivityTagsAsyn
307
193
}
308
194
309
195
[ 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 )
315
205
{
316
206
RabbitMQActivitySource . UseRoutingKeyAsOperationName = useRoutingKeyAsOperationName ;
317
207
RabbitMQActivitySource . TracingOptions . UsePublisherAsParent = usePublisherAsParent ;
@@ -321,18 +211,20 @@ public async Task TestPublisherAndBasicGetActivityTags(bool useRoutingKeyAsOpera
321
211
string queue = $ "queue-{ Guid . NewGuid ( ) } ";
322
212
const string msg = "for basic.get" ;
323
213
214
+ var basicProps = useMessageId ? new BasicProperties ( ) { MessageId = Guid . NewGuid ( ) . ToString ( ) } : new BasicProperties ( ) ;
215
+
324
216
try
325
217
{
326
218
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 ) ) ;
328
220
QueueDeclareOk ok = await _channel . QueueDeclarePassiveAsync ( queue ) ;
329
221
Assert . Equal ( 1u , ok . MessageCount ) ;
330
222
BasicGetResult res = await _channel . BasicGetAsync ( queue , true ) ;
331
223
Assert . Equal ( msg , Encoding . UTF8 . GetString ( res . Body . ToArray ( ) ) ) ;
332
224
ok = await _channel . QueueDeclarePassiveAsync ( queue ) ;
333
225
Assert . Equal ( 0u , ok . MessageCount ) ;
334
226
await Task . Delay ( 500 ) ;
335
- AssertActivityData ( useRoutingKeyAsOperationName , usePublisherAsParent , queue , activities , false ) ;
227
+ AssertActivityData ( useRoutingKeyAsOperationName , usePublisherAsParent , queue , activities , false , basicProps . MessageId ) ;
336
228
}
337
229
finally
338
230
{
@@ -345,7 +237,7 @@ public async Task TestPublisherAndBasicGetActivityTags(bool useRoutingKeyAsOpera
345
237
[ InlineData ( true , false ) ]
346
238
[ InlineData ( false , true ) ]
347
239
[ InlineData ( false , false ) ]
348
- public async Task TestPublisherWithCachedStringsAndBasicGetActivityTags ( bool useRoutingKeyAsOperationName , bool usePublisherAsParent )
240
+ public async Task TestPublisherWithCachedStringsAndBasicGetActivityTagsAsync ( bool useRoutingKeyAsOperationName , bool usePublisherAsParent )
349
241
{
350
242
RabbitMQActivitySource . UseRoutingKeyAsOperationName = useRoutingKeyAsOperationName ;
351
243
RabbitMQActivitySource . TracingOptions . UsePublisherAsParent = usePublisherAsParent ;
@@ -381,7 +273,7 @@ public async Task TestPublisherWithCachedStringsAndBasicGetActivityTags(bool use
381
273
[ InlineData ( true , false ) ]
382
274
[ InlineData ( false , true ) ]
383
275
[ InlineData ( false , false ) ]
384
- public async Task TestPublisherWithPublicationAddressAndBasicGetActivityTags ( bool useRoutingKeyAsOperationName , bool usePublisherAsParent )
276
+ public async Task TestPublisherWithPublicationAddressAndBasicGetActivityTagsAsync ( bool useRoutingKeyAsOperationName , bool usePublisherAsParent )
385
277
{
386
278
RabbitMQActivitySource . UseRoutingKeyAsOperationName = useRoutingKeyAsOperationName ;
387
279
RabbitMQActivitySource . TracingOptions . UsePublisherAsParent = usePublisherAsParent ;
@@ -427,7 +319,7 @@ private static ActivityListener StartActivityListener(List<Activity> activities)
427
319
}
428
320
429
321
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 )
431
323
{
432
324
string childName = isDeliver ? "deliver" : "fetch" ;
433
325
Activity [ ] activities = activityList . ToArray ( ) ;
@@ -480,6 +372,12 @@ private void AssertActivityData(bool useRoutingKeyAsOperationName, bool usePubli
480
372
AssertIntTagGreaterThanZero ( sendActivity , RabbitMQActivitySource . MessagingEnvelopeSize ) ;
481
373
AssertIntTagGreaterThanZero ( sendActivity , RabbitMQActivitySource . MessagingBodySize ) ;
482
374
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
+ }
483
381
}
484
382
}
485
383
}
0 commit comments