Description
Library name and version
Azure.Messaging.ServiceBus 7.18.4
Describe the bug
Use case
A worker continuously starts and stops processing on the ServiceBusProcessor.
The async MessageHandler creates activities to trace the processing of the messages received.
This creates spans in aspire dashboard / Jaeger which is wanted behaviour.
Implementation
Program.cs
// enable experimental tracing
AppContext.SetSwitch("Azure.Experimental.EnableActivitySource", true);
// enable OTEL
// this adds tracing.AddSource("Azure.Messaging.ServiceBus.*");
builder.Services.AddMyOpenTelemetry(builder.Configuration)
Worker.cs
protected override async Task ExecuteAsync(CancellationToken stoppingToken) {
while (true)
{
// start processing
await processor.StartProcessingAsync(stoppingToken);
// make sure no more messages are processed in this run
for (int i = 0; i < 10; ++i)
{
if (MessagesProcessed >= MAXMSGS)
{
break;
}
await Task.Delay(100);
}
// stop processing (give room to other threads)
await processor.StopProcessingAsync(stoppingToken);
}
}
async Task MessageHandler(ProcessMessageEventArgs args)
{
using (var act = _metricsClient.StartMessageReceivingActivity()) {
// processing logic here
await args.CompleteMessageAsync(args.Message);
}
}
Actual behaviour
The activity (ServiceBusReceiver.Receive) for effectively received messages are linked to the activity span created in the MessageHandler
. (👍)
The activity (ServiceBusReceiver.Receive) also appears with error: true and error.type: System.Threading.Tasks.TaskCanceledException due to the fact that the processor is stopped in the loop in ExecuteAsync
. (👎)
Expected behavior
Since StartProcessingAsync and StopProcessingAsync operations are normal operations, I'd expect no errors/exceptions in the traces.
Actual behavior
cfr. "Actual behaviour" in description
Reproduction Steps
cfr. "Implementation" in description
Environment
.net 9
Microsoft Visual Studio Enterprise 2022
Version 17.12.1
VisualStudio.17.Release/17.12.1+35514.174
Installed Version: Enterprise