[Tracer] Fix Azure Service Bus producer/consumer trace disconnect for ServiceBusProcessor#8867
[Tracer] Fix Azure Service Bus producer/consumer trace disconnect for ServiceBusProcessor#8867NachoEchevarria wants to merge 4 commits into
Conversation
Execution-Time Benchmarks Report ⏱️Execution-time results for samples comparing This PR (8867) and master. ✅ No regressions detected - check the details below Full Metrics ComparisonFakeDbCommand
HttpMessageHandler
Comparison explanationExecution-time benchmarks measure the whole time it takes to execute a program, and are intended to measure the one-off costs. Cases where the execution time results for the PR are worse than latest master results are highlighted in **red**. The following thresholds were used for comparing the execution times:
Note that these results are based on a single point-in-time result for each branch. For full results, see the dashboard. Graphs show the p99 interval based on the mean and StdDev of the test run, as well as the mean value of the run (shown as a diamond below the graph). Duration chartsFakeDbCommand (.NET Framework 4.8)gantt
title Execution time (ms) FakeDbCommand (.NET Framework 4.8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8867) - mean (69ms) : 68, 71
master - mean (72ms) : 69, 75
section Bailout
This PR (8867) - mean (73ms) : 71, 75
master - mean (74ms) : 72, 77
section CallTarget+Inlining+NGEN
This PR (8867) - mean (1,084ms) : 1034, 1134
master - mean (1,082ms) : 1039, 1124
FakeDbCommand (.NET Core 3.1)gantt
title Execution time (ms) FakeDbCommand (.NET Core 3.1)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8867) - mean (108ms) : 105, 111
master - mean (113ms) : 107, 119
section Bailout
This PR (8867) - mean (109ms) : 107, 111
master - mean (110ms) : 108, 113
section CallTarget+Inlining+NGEN
This PR (8867) - mean (776ms) : 761, 792
master - mean (781ms) : 757, 805
FakeDbCommand (.NET 6)gantt
title Execution time (ms) FakeDbCommand (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8867) - mean (99ms) : 94, 104
master - mean (96ms) : 93, 99
section Bailout
This PR (8867) - mean (97ms) : 95, 99
master - mean (98ms) : 95, 100
section CallTarget+Inlining+NGEN
This PR (8867) - mean (942ms) : 904, 980
master - mean (940ms) : 898, 983
FakeDbCommand (.NET 8)gantt
title Execution time (ms) FakeDbCommand (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8867) - mean (95ms) : 92, 97
master - mean (99ms) : 92, 105
section Bailout
This PR (8867) - mean (100ms) : 95, 105
master - mean (96ms) : 93, 100
section CallTarget+Inlining+NGEN
This PR (8867) - mean (812ms) : 774, 851
master - mean (814ms) : 781, 847
HttpMessageHandler (.NET Framework 4.8)gantt
title Execution time (ms) HttpMessageHandler (.NET Framework 4.8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8867) - mean (203ms) : 198, 208
master - mean (203ms) : 198, 208
section Bailout
This PR (8867) - mean (206ms) : 201, 210
master - mean (206ms) : 202, 210
section CallTarget+Inlining+NGEN
This PR (8867) - mean (1,205ms) : 1166, 1244
master - mean (1,210ms) : 1173, 1246
HttpMessageHandler (.NET Core 3.1)gantt
title Execution time (ms) HttpMessageHandler (.NET Core 3.1)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8867) - mean (290ms) : 283, 296
master - mean (291ms) : 283, 298
section Bailout
This PR (8867) - mean (293ms) : 286, 300
master - mean (294ms) : 289, 298
section CallTarget+Inlining+NGEN
This PR (8867) - mean (967ms) : 949, 984
master - mean (975ms) : 952, 998
HttpMessageHandler (.NET 6)gantt
title Execution time (ms) HttpMessageHandler (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8867) - mean (287ms) : 276, 297
master - mean (286ms) : 278, 294
section Bailout
This PR (8867) - mean (286ms) : 279, 293
master - mean (286ms) : 282, 290
section CallTarget+Inlining+NGEN
This PR (8867) - mean (1,167ms) : 1133, 1201
master - mean (1,171ms) : 1132, 1210
HttpMessageHandler (.NET 8)gantt
title Execution time (ms) HttpMessageHandler (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8867) - mean (280ms) : 272, 288
master - mean (284ms) : 277, 291
section Bailout
This PR (8867) - mean (282ms) : 275, 289
master - mean (284ms) : 278, 290
section CallTarget+Inlining+NGEN
This PR (8867) - mean (1,047ms) : 1004, 1091
master - mean (1,051ms) : 1005, 1097
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BenchmarksBenchmark execution time: 2026-07-03 13:59:05 Comparing candidate commit 1b289fd in PR branch Found 0 performance improvements and 1 performance regressions! Performance is the same for 71 metrics, 0 unstable metrics, 61 known flaky benchmarks, 65 flaky benchmarks without significant changes.
|
Summary of changes
Only re-inject the receive-span context into Service Bus messages when running in Azure Functions.
Reason for change
With a
ServiceBusProcessorconsumer and the Azure activity source enabled(
AZURE_EXPERIMENTAL_ENABLE_ACTIVITY_SOURCE=true+DD_TRACE_OTEL_ENABLED=true), producer andconsumer showed up as two disconnected traces (APMS-19950).
ServiceBusReceiverReceiveMessagesAsyncIntegrationunconditionally re-injected the newazure_servicebus.receivespan's context back into each received message. That re-injection existsonly for Azure Functions (where the host reads the message to parent the invocation and there is no
ServiceBusProcessor.ProcessMessageactivity). Outside Functions it overwrote the producer'straceparent, so the SDK-createdServiceBusProcessor.ProcessMessageactivity parented to our receivespan instead of the producer — splitting the trace in two.
Implementation details
Gated
ReinjectContextIntoMessagesbehindtracer.Settings.IsRunningInAzureFunctions. In Azure Functionsthe behaviour is unchanged (re-injection still runs); everywhere else the message keeps the producer's
context and
ProcessMessagereconnects to the producer trace.Test coverage
Processormode toSamples.AzureServiceBus.APM(enables the activity source, sends andprocesses one message via
ServiceBusProcessor).AzureServiceBusAPMTests.TestProcessorConnectsToProducerTrace, which asserts theservicebus.processspan shares the producer's trace. It fails without the fix and passes with it;verified locally against the Service Bus emulator on package versions 7.18.4 and 7.20.1 (full
AzureServiceBusAPMTestsclass green — no regression in send/receive/batch/schedule).AzureFunctionsMessagingTriggerTestssnapshots(unchanged) — verified in CI, since those tests require the Functions Core Tools + emulators.
Other details
Temporary customer workaround until this ships: set
DD_TRACE_AZURESERVICEBUS_ENABLED=false(keepDD_TRACE_OTEL_ENABLED=true) — trades off DSM and the customazure_servicebus.*spans for a reconnectedtrace.
DD_TRACE_AZURE_SERVICEBUS_BATCH_LINKS_ENABLED=falsedoes not work (it doesn't gate there-injection).