@@ -75,158 +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
- [ Theory ]
193
- [ InlineData ( true , true ) ]
194
- [ InlineData ( true , false ) ]
195
- [ InlineData ( false , true ) ]
196
- [ InlineData ( false , false ) ]
197
- public async Task TestPublisherAndConsumerActivityTagsAsync ( bool useRoutingKeyAsOperationName , bool usePublisherAsParent )
198
- {
199
- RabbitMQActivitySource . UseRoutingKeyAsOperationName = useRoutingKeyAsOperationName ;
200
- RabbitMQActivitySource . TracingOptions . UsePublisherAsParent = usePublisherAsParent ;
201
- var activities = new List < Activity > ( ) ;
202
- using ActivityListener activityListener = StartActivityListener ( activities ) ;
203
- await Task . Delay ( 500 ) ;
204
-
205
- string queueName = $ "{ Guid . NewGuid ( ) } ";
206
- QueueDeclareOk q = await _channel . QueueDeclareAsync ( queueName ) ;
207
- byte [ ] sendBody = Encoding . UTF8 . GetBytes ( "hi" ) ;
208
- byte [ ] consumeBody = null ;
209
- var consumer = new AsyncEventingBasicConsumer ( _channel ) ;
210
- var consumerReceivedTcs =
211
- new TaskCompletionSource < bool > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
212
- consumer . ReceivedAsync += ( o , a ) =>
213
- {
214
- consumeBody = a . Body . ToArray ( ) ;
215
- consumerReceivedTcs . SetResult ( true ) ;
216
- return Task . CompletedTask ;
217
- } ;
218
-
219
- string consumerTag = await _channel . BasicConsumeAsync ( queueName , autoAck : true , consumer : consumer ) ;
220
- await _channel . BasicPublishAsync ( "" , q . QueueName , true , sendBody ) ;
221
-
222
- await consumerReceivedTcs . Task . WaitAsync ( TimeSpan . FromSeconds ( 5 ) ) ;
223
- Assert . True ( await consumerReceivedTcs . Task ) ;
224
-
225
- await _channel . BasicCancelAsync ( consumerTag ) ;
226
- await Task . Delay ( 500 ) ;
227
- AssertActivityData ( useRoutingKeyAsOperationName , usePublisherAsParent , queueName , activities , true ) ;
228
- }
229
-
230
78
[ Theory ]
231
79
[ InlineData ( true , true ) ]
232
80
[ InlineData ( true , false ) ]
@@ -307,11 +155,15 @@ public async Task TestPublisherWithPublicationAddressAndConsumerActivityTagsAsyn
307
155
}
308
156
309
157
[ 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 )
158
+ [ InlineData ( true , true , true ) ]
159
+ [ InlineData ( true , true , false ) ]
160
+ [ InlineData ( true , false , true ) ]
161
+ [ InlineData ( true , false , false ) ]
162
+ [ InlineData ( false , true , true ) ]
163
+ [ InlineData ( false , true , false ) ]
164
+ [ InlineData ( false , false , true ) ]
165
+ [ InlineData ( false , false , false ) ]
166
+ public async Task TestPublisherAndBasicGetActivityTagsAsync ( bool useRoutingKeyAsOperationName , bool usePublisherAsParent , bool useMessageId )
315
167
{
316
168
RabbitMQActivitySource . UseRoutingKeyAsOperationName = useRoutingKeyAsOperationName ;
317
169
RabbitMQActivitySource . TracingOptions . UsePublisherAsParent = usePublisherAsParent ;
@@ -321,18 +173,20 @@ public async Task TestPublisherAndBasicGetActivityTags(bool useRoutingKeyAsOpera
321
173
string queue = $ "queue-{ Guid . NewGuid ( ) } ";
322
174
const string msg = "for basic.get" ;
323
175
176
+ var basicProps = useMessageId ? new BasicProperties ( ) { MessageId = Guid . NewGuid ( ) . ToString ( ) } : new BasicProperties ( ) ;
177
+
324
178
try
325
179
{
326
180
await _channel . QueueDeclareAsync ( queue , false , false , false , null ) ;
327
- await _channel . BasicPublishAsync ( "" , queue , true , Encoding . UTF8 . GetBytes ( msg ) ) ;
181
+ await _channel . BasicPublishAsync ( "" , queue , true , basicProps , Encoding . UTF8 . GetBytes ( msg ) ) ;
328
182
QueueDeclareOk ok = await _channel . QueueDeclarePassiveAsync ( queue ) ;
329
183
Assert . Equal ( 1u , ok . MessageCount ) ;
330
184
BasicGetResult res = await _channel . BasicGetAsync ( queue , true ) ;
331
185
Assert . Equal ( msg , Encoding . UTF8 . GetString ( res . Body . ToArray ( ) ) ) ;
332
186
ok = await _channel . QueueDeclarePassiveAsync ( queue ) ;
333
187
Assert . Equal ( 0u , ok . MessageCount ) ;
334
188
await Task . Delay ( 500 ) ;
335
- AssertActivityData ( useRoutingKeyAsOperationName , usePublisherAsParent , queue , activities , false ) ;
189
+ AssertActivityData ( useRoutingKeyAsOperationName , usePublisherAsParent , queue , activities , false , basicProps . MessageId ) ;
336
190
}
337
191
finally
338
192
{
@@ -345,7 +199,7 @@ public async Task TestPublisherAndBasicGetActivityTags(bool useRoutingKeyAsOpera
345
199
[ InlineData ( true , false ) ]
346
200
[ InlineData ( false , true ) ]
347
201
[ InlineData ( false , false ) ]
348
- public async Task TestPublisherWithCachedStringsAndBasicGetActivityTags ( bool useRoutingKeyAsOperationName , bool usePublisherAsParent )
202
+ public async Task TestPublisherWithCachedStringsAndBasicGetActivityTagsAsync ( bool useRoutingKeyAsOperationName , bool usePublisherAsParent )
349
203
{
350
204
RabbitMQActivitySource . UseRoutingKeyAsOperationName = useRoutingKeyAsOperationName ;
351
205
RabbitMQActivitySource . TracingOptions . UsePublisherAsParent = usePublisherAsParent ;
@@ -381,7 +235,7 @@ public async Task TestPublisherWithCachedStringsAndBasicGetActivityTags(bool use
381
235
[ InlineData ( true , false ) ]
382
236
[ InlineData ( false , true ) ]
383
237
[ InlineData ( false , false ) ]
384
- public async Task TestPublisherWithPublicationAddressAndBasicGetActivityTags ( bool useRoutingKeyAsOperationName , bool usePublisherAsParent )
238
+ public async Task TestPublisherWithPublicationAddressAndBasicGetActivityTagsAsync ( bool useRoutingKeyAsOperationName , bool usePublisherAsParent )
385
239
{
386
240
RabbitMQActivitySource . UseRoutingKeyAsOperationName = useRoutingKeyAsOperationName ;
387
241
RabbitMQActivitySource . TracingOptions . UsePublisherAsParent = usePublisherAsParent ;
@@ -427,7 +281,7 @@ private static ActivityListener StartActivityListener(List<Activity> activities)
427
281
}
428
282
429
283
private void AssertActivityData ( bool useRoutingKeyAsOperationName , bool usePublisherAsParent , string queueName ,
430
- List < Activity > activityList , bool isDeliver = false )
284
+ List < Activity > activityList , bool isDeliver = false , string messageId = null )
431
285
{
432
286
string childName = isDeliver ? "deliver" : "fetch" ;
433
287
Activity [ ] activities = activityList . ToArray ( ) ;
@@ -480,6 +334,12 @@ private void AssertActivityData(bool useRoutingKeyAsOperationName, bool usePubli
480
334
AssertIntTagGreaterThanZero ( sendActivity , RabbitMQActivitySource . MessagingEnvelopeSize ) ;
481
335
AssertIntTagGreaterThanZero ( sendActivity , RabbitMQActivitySource . MessagingBodySize ) ;
482
336
AssertIntTagGreaterThanZero ( receiveActivity , RabbitMQActivitySource . MessagingBodySize ) ;
337
+
338
+ if ( messageId is not null )
339
+ {
340
+ AssertStringTagEquals ( sendActivity , RabbitMQActivitySource . MessageId , messageId ) ;
341
+ AssertStringTagEquals ( receiveActivity , RabbitMQActivitySource . MessageId , messageId ) ;
342
+ }
483
343
}
484
344
}
485
345
}
0 commit comments