Skip to content

Conversation

pablomartinezbernardo
Copy link
Contributor

@pablomartinezbernardo pablomartinezbernardo commented Aug 19, 2025

Summary of changes

Sample span:
image

New integration disabled by default, to be enabled with DD_TRACE_AZURESERVICEBUS_ENABLED=true

Created ServiceBusSenderSendMessagesAsyncIntegration

  • Creates a span

Created ServiceBusReceiverReceiveMessagesAsyncIntegration

  • On begin: Does nothing. On serverless message reception can block for 60s, so we wait until something is actually read
  • On end:
  1. Creates a new span extracting context from Service Bus message and parents/links accordingly. Parenting is used when all contexts are the same, span links otherwise.
  2. Rewrites the contex for all messages so they point to the span we just created

AzureFunctionsCommon changes

On service bus trigger, extracts context from service bus messages to set the parent. Given ServiceBusReceiverReceiveMessagesAsyncIntegration this should be one single context, warn otherwise.

InstrumentMessageIntegration changes

Add context to all messages.

Test coverage

Service Bus integration tests for sending, receiving and parenting

Limitations

  • Batching not included

@pr-commenter
Copy link

pr-commenter bot commented Aug 25, 2025

Benchmarks

Benchmarks Report for benchmark platform 🐌

Benchmarks for #7413 compared to master:

  • 1 benchmarks are faster, with geometric mean 1.226
  • 2 benchmarks are slower, with geometric mean 1.538
  • 6 benchmarks have fewer allocations
  • 4 benchmarks have more allocations

The following thresholds were used for comparing the benchmark speeds:

  • Mann–Whitney U test with statistical test for significance of 5%
  • Only results indicating a difference greater than 10% and 0.3 ns are considered.

Allocation changes below 0.5% are ignored.

Benchmark details

Benchmarks.Trace.ActivityBenchmark - Same speed ✔️ More allocations ⚠️

More allocations ⚠️ in #7413

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.ActivityBenchmark.StartStopWithChild‑net472 6.06 KB 6.1 KB 39 B 0.64%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartStopWithChild net6.0 10.6μs 57.7ns 332ns 0 0 0 5.49 KB
master StartStopWithChild netcoreapp3.1 13.3μs 70.6ns 346ns 0 0 0 5.7 KB
master StartStopWithChild net472 22.4μs 126ns 825ns 0.907 0.227 0 6.06 KB
#7413 StartStopWithChild net6.0 11.1μs 59.7ns 321ns 0 0 0 5.51 KB
#7413 StartStopWithChild netcoreapp3.1 13.7μs 71.4ns 350ns 0 0 0 5.71 KB
#7413 StartStopWithChild net472 22.3μs 107ns 456ns 0.877 0.329 0 6.1 KB
Benchmarks.Trace.AgentWriterBenchmark - Same speed ✔️ More allocations ⚠️

More allocations ⚠️ in #7413

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces‑net472 3.31 KB 3.35 KB 46 B 1.39%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master WriteAndFlushEnrichedTraces net6.0 932μs 247ns 957ns 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 1.03ms 54.8ns 212ns 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces net472 1.19ms 87.4ns 339ns 0 0 0 3.31 KB
#7413 WriteAndFlushEnrichedTraces net6.0 933μs 137ns 530ns 0 0 0 2.71 KB
#7413 WriteAndFlushEnrichedTraces netcoreapp3.1 1.02ms 95.7ns 358ns 0 0 0 2.7 KB
#7413 WriteAndFlushEnrichedTraces net472 1.2ms 69.9ns 242ns 0 0 0 3.35 KB
Benchmarks.Trace.Asm.AppSecBodyBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master AllCycleSimpleBody net6.0 326μs 454ns 1.76μs 0 0 0 172.08 KB
master AllCycleSimpleBody netcoreapp3.1 462μs 970ns 3.76μs 0 0 0 174.18 KB
master AllCycleSimpleBody net472 424μs 101ns 378ns 29.2 0 0 194.24 KB
master AllCycleMoreComplexBody net6.0 331μs 1.15μs 4.45μs 0 0 0 175.58 KB
master AllCycleMoreComplexBody netcoreapp3.1 506μs 1.46μs 5.66μs 0 0 0 177.6 KB
master AllCycleMoreComplexBody net472 432μs 136ns 492ns 30.2 0 0 197.76 KB
master ObjectExtractorSimpleBody net6.0 328ns 0.265ns 0.956ns 0 0 0 280 B
master ObjectExtractorSimpleBody netcoreapp3.1 402ns 2.09ns 10ns 0 0 0 272 B
master ObjectExtractorSimpleBody net472 308ns 0.0502ns 0.181ns 0.0433 0 0 281 B
master ObjectExtractorMoreComplexBody net6.0 6.23μs 31.7ns 149ns 0 0 0 3.78 KB
master ObjectExtractorMoreComplexBody netcoreapp3.1 7.74μs 36.5ns 136ns 0 0 0 3.69 KB
master ObjectExtractorMoreComplexBody net472 6.76μs 6.23ns 24.1ns 0.577 0 0 3.8 KB
#7413 AllCycleSimpleBody net6.0 320μs 1.46μs 5.67μs 0 0 0 172.07 KB
#7413 AllCycleSimpleBody netcoreapp3.1 469μs 1.58μs 6.13μs 0 0 0 174.18 KB
#7413 AllCycleSimpleBody net472 424μs 125ns 483ns 29.2 0 0 194.24 KB
#7413 AllCycleMoreComplexBody net6.0 332μs 833ns 3.23μs 0 0 0 175.58 KB
#7413 AllCycleMoreComplexBody netcoreapp3.1 480μs 1.34μs 5.2μs 0 0 0 177.6 KB
#7413 AllCycleMoreComplexBody net472 432μs 97ns 363ns 30.2 0 0 197.76 KB
#7413 ObjectExtractorSimpleBody net6.0 318ns 0.218ns 0.786ns 0 0 0 280 B
#7413 ObjectExtractorSimpleBody netcoreapp3.1 398ns 2.13ns 11.9ns 0 0 0 272 B
#7413 ObjectExtractorSimpleBody net472 310ns 0.0465ns 0.174ns 0.0445 0 0 281 B
#7413 ObjectExtractorMoreComplexBody net6.0 6.29μs 29.8ns 115ns 0 0 0 3.78 KB
#7413 ObjectExtractorMoreComplexBody netcoreapp3.1 7.71μs 33.8ns 131ns 0 0 0 3.69 KB
#7413 ObjectExtractorMoreComplexBody net472 6.71μs 2.5ns 9.35ns 0.57 0 0 3.8 KB
Benchmarks.Trace.Asm.AppSecEncoderBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EncodeArgs net6.0 76.6μs 96.5ns 361ns 0 0 0 32.4 KB
master EncodeArgs netcoreapp3.1 96.3μs 328ns 1.23μs 0 0 0 32.4 KB
master EncodeArgs net472 113μs 43.8ns 169ns 5.06 0 0 32.51 KB
master EncodeLegacyArgs net6.0 146μs 62ns 240ns 0 0 0 2.15 KB
master EncodeLegacyArgs netcoreapp3.1 196μs 202ns 782ns 0 0 0 2.14 KB
master EncodeLegacyArgs net472 261μs 46.3ns 179ns 0 0 0 2.16 KB
#7413 EncodeArgs net6.0 77.1μs 264ns 1.02μs 0 0 0 32.4 KB
#7413 EncodeArgs netcoreapp3.1 98μs 332ns 1.29μs 0 0 0 32.4 KB
#7413 EncodeArgs net472 111μs 20.4ns 79.1ns 4.96 0 0 32.51 KB
#7413 EncodeLegacyArgs net6.0 144μs 29ns 104ns 0 0 0 2.14 KB
#7413 EncodeLegacyArgs netcoreapp3.1 198μs 277ns 1.07μs 0 0 0 2.14 KB
#7413 EncodeLegacyArgs net472 262μs 13ns 48.6ns 0 0 0 2.16 KB
Benchmarks.Trace.Asm.AppSecWafBenchmark - Slower ⚠️ Same allocations ✔️

Slower ⚠️ in #7413

Benchmark diff/base Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark‑netcoreapp3.1 2.075 417,027.29 865,194.27

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master RunWafRealisticBenchmark net6.0 393μs 47.7ns 179ns 0 0 0 4.55 KB
master RunWafRealisticBenchmark netcoreapp3.1 417μs 128ns 462ns 0 0 0 4.48 KB
master RunWafRealisticBenchmark net472 431μs 76.5ns 296ns 0 0 0 4.66 KB
master RunWafRealisticBenchmarkWithAttack net6.0 287μs 51.6ns 200ns 0 0 0 2.24 KB
master RunWafRealisticBenchmarkWithAttack netcoreapp3.1 686μs 9.65μs 96.5μs 0 0 0 2.22 KB
master RunWafRealisticBenchmarkWithAttack net472 312μs 25.2ns 90.8ns 0 0 0 2.29 KB
#7413 RunWafRealisticBenchmark net6.0 393μs 36.5ns 137ns 0 0 0 4.55 KB
#7413 RunWafRealisticBenchmark netcoreapp3.1 852μs 6.99μs 69.9μs 0 0 0 4.48 KB
#7413 RunWafRealisticBenchmark net472 434μs 66.8ns 241ns 0 0 0 4.66 KB
#7413 RunWafRealisticBenchmarkWithAttack net6.0 286μs 78.2ns 303ns 0 0 0 2.24 KB
#7413 RunWafRealisticBenchmarkWithAttack netcoreapp3.1 697μs 9.48μs 94.8μs 0 0 0 2.22 KB
#7413 RunWafRealisticBenchmarkWithAttack net472 314μs 57ns 221ns 0 0 0 2.29 KB
Benchmarks.Trace.AspNetCoreBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendRequest net6.0 60.1μs 35.2ns 136ns 0 0 0 14.52 KB
master SendRequest netcoreapp3.1 71.9μs 79.9ns 299ns 0 0 0 17.42 KB
master SendRequest net472 0.00728ns 0.00251ns 0.00973ns 0 0 0 0 b
#7413 SendRequest net6.0 60.3μs 208ns 807ns 0 0 0 14.52 KB
#7413 SendRequest netcoreapp3.1 71.2μs 83ns 311ns 0 0 0 17.42 KB
#7413 SendRequest net472 0.00728ns 0.00287ns 0.0111ns 0 0 0 0 b
Benchmarks.Trace.CharSliceBenchmark - Slower ⚠️ Fewer allocations 🎉

Slower ⚠️ in #7413

Benchmark diff/base Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice‑net6.0 1.140 1,377,848.61 1,570,510.94

Fewer allocations 🎉 in #7413

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice‑net6.0 7 B 2 B -5 B -71.43%
Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool‑netcoreapp3.1 1 B 0 b -1 B -100.00%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master OriginalCharSlice net6.0 1.93ms 355ns 1.37μs 0 0 0 640.01 KB
master OriginalCharSlice netcoreapp3.1 2.09ms 3.19μs 12.4μs 0 0 0 640 KB
master OriginalCharSlice net472 2.69ms 661ns 2.47μs 100 0 0 641.95 KB
master OptimizedCharSlice net6.0 1.38ms 386ns 1.5μs 0 0 0 7 B
master OptimizedCharSlice netcoreapp3.1 1.66ms 255ns 987ns 0 0 0 1 B
master OptimizedCharSlice net472 1.99ms 568ns 2.12μs 0 0 0 0 b
master OptimizedCharSliceWithPool net6.0 811μs 24.9ns 96.5ns 0 0 0 2 B
master OptimizedCharSliceWithPool netcoreapp3.1 838μs 247ns 958ns 0 0 0 1 B
master OptimizedCharSliceWithPool net472 1.15ms 61.3ns 221ns 0 0 0 0 b
#7413 OriginalCharSlice net6.0 1.95ms 1.87μs 7.26μs 0 0 0 640.01 KB
#7413 OriginalCharSlice netcoreapp3.1 2.17ms 10.2μs 39.5μs 0 0 0 640 KB
#7413 OriginalCharSlice net472 2.72ms 149ns 537ns 100 0 0 641.95 KB
#7413 OptimizedCharSlice net6.0 1.57ms 452ns 1.75μs 0 0 0 2 B
#7413 OptimizedCharSlice netcoreapp3.1 1.72ms 383ns 1.43μs 0 0 0 1 B
#7413 OptimizedCharSlice net472 2.03ms 817ns 3.16μs 0 0 0 0 b
#7413 OptimizedCharSliceWithPool net6.0 888μs 135ns 523ns 0 0 0 2 B
#7413 OptimizedCharSliceWithPool netcoreapp3.1 808μs 46.1ns 179ns 0 0 0 0 b
#7413 OptimizedCharSliceWithPool net472 1.14ms 84.8ns 317ns 0 0 0 0 b
Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark - Same speed ✔️ Fewer allocations 🎉

Fewer allocations 🎉 in #7413

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces‑netcoreapp3.1 42.28 KB 41.95 KB -329 B -0.78%
Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces‑net472 56.59 KB 55.91 KB -682 B -1.21%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master WriteAndFlushEnrichedTraces net6.0 661μs 1.42μs 5.5μs 0 0 0 41.71 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 689μs 2.57μs 9.63μs 0 0 0 42.28 KB
master WriteAndFlushEnrichedTraces net472 991μs 4.86μs 19.4μs 8.33 0 0 56.59 KB
#7413 WriteAndFlushEnrichedTraces net6.0 698μs 1.58μs 6.14μs 0 0 0 41.76 KB
#7413 WriteAndFlushEnrichedTraces netcoreapp3.1 682μs 2.92μs 10.9μs 0 0 0 41.95 KB
#7413 WriteAndFlushEnrichedTraces net472 885μs 2.1μs 8.12μs 8.33 0 0 55.91 KB
Benchmarks.Trace.DbCommandBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master ExecuteNonQuery net6.0 1.86μs 3.43ns 13.3ns 0 0 0 1.02 KB
master ExecuteNonQuery netcoreapp3.1 2.53μs 3.67ns 14.2ns 0 0 0 1.02 KB
master ExecuteNonQuery net472 2.82μs 4.31ns 16.7ns 0.155 0.0141 0 987 B
#7413 ExecuteNonQuery net6.0 1.92μs 1.28ns 4.97ns 0 0 0 1.02 KB
#7413 ExecuteNonQuery netcoreapp3.1 2.52μs 11ns 42.5ns 0 0 0 1.02 KB
#7413 ExecuteNonQuery net472 2.72μs 3.44ns 13.3ns 0.153 0.0139 0 987 B
Benchmarks.Trace.ElasticsearchBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master CallElasticsearch net6.0 1.71μs 0.778ns 2.8ns 0 0 0 1.03 KB
master CallElasticsearch netcoreapp3.1 2.25μs 11.4ns 55.8ns 0 0 0 1.03 KB
master CallElasticsearch net472 3.5μs 2.17ns 8.11ns 0.157 0 0 1.04 KB
master CallElasticsearchAsync net6.0 1.77μs 5.53ns 20.7ns 0 0 0 1.01 KB
master CallElasticsearchAsync netcoreapp3.1 2.46μs 8.37ns 32.4ns 0 0 0 1.08 KB
master CallElasticsearchAsync net472 3.78μs 2.25ns 8.72ns 0.17 0 0 1.1 KB
#7413 CallElasticsearch net6.0 1.75μs 1.37ns 4.93ns 0 0 0 1.03 KB
#7413 CallElasticsearch netcoreapp3.1 2.21μs 10.5ns 43.4ns 0 0 0 1.03 KB
#7413 CallElasticsearch net472 3.43μs 2.4ns 9.29ns 0.154 0 0 1.04 KB
#7413 CallElasticsearchAsync net6.0 1.85μs 7.91ns 30.6ns 0 0 0 1.01 KB
#7413 CallElasticsearchAsync netcoreapp3.1 2.48μs 8.33ns 32.3ns 0 0 0 1.08 KB
#7413 CallElasticsearchAsync net472 3.74μs 5.85ns 22.7ns 0.167 0 0 1.1 KB
Benchmarks.Trace.GraphQLBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master ExecuteAsync net6.0 1.76μs 1.21ns 4.68ns 0 0 0 952 B
master ExecuteAsync netcoreapp3.1 2.29μs 2.48ns 9.28ns 0 0 0 952 B
master ExecuteAsync net472 2.42μs 0.632ns 2.45ns 0.145 0 0 915 B
#7413 ExecuteAsync net6.0 1.78μs 7.55ns 29.3ns 0 0 0 952 B
#7413 ExecuteAsync netcoreapp3.1 2.36μs 5.33ns 19.2ns 0 0 0 952 B
#7413 ExecuteAsync net472 2.41μs 1.42ns 5.49ns 0.144 0 0 915 B
Benchmarks.Trace.HttpClientBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendAsync net6.0 7.15μs 6.26ns 24.2ns 0 0 0 2.36 KB
master SendAsync netcoreapp3.1 8.21μs 25.3ns 98.1ns 0 0 0 2.9 KB
master SendAsync net472 12.2μs 10.7ns 40.1ns 0.485 0 0 3.18 KB
#7413 SendAsync net6.0 7.16μs 5.46ns 18.9ns 0 0 0 2.36 KB
#7413 SendAsync netcoreapp3.1 8.3μs 19.4ns 74.9ns 0 0 0 2.9 KB
#7413 SendAsync net472 12.1μs 8.48ns 31.7ns 0.483 0 0 3.18 KB
Benchmarks.Trace.Iast.StringAspectsBenchmark - Faster 🎉 More allocations ⚠️

Faster 🎉 in #7413

Benchmark base/diff Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark‑net6.0 1.226 475,000.00 387,500.00 multimodal

More allocations ⚠️ in #7413

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark‑netcoreapp3.1 255.16 KB 275.9 KB 20.74 KB 8.13%
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark‑net6.0 43.59 KB 44.42 KB 824 B 1.89%

Fewer allocations 🎉 in #7413

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark‑net6.0 275.33 KB 246.94 KB -28.39 KB -10.31%
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark‑net472 65.54 KB 57.34 KB -8.19 KB -12.50%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StringConcatBenchmark net6.0 48.1μs 267ns 1.58μs 0 0 0 43.59 KB
master StringConcatBenchmark netcoreapp3.1 54.4μs 705ns 6.87μs 0 0 0 43.47 KB
master StringConcatBenchmark net472 57.9μs 246ns 951ns 0 0 0 65.54 KB
master StringConcatAspectBenchmark net6.0 475μs 1.17μs 4.05μs 0 0 0 275.33 KB
master StringConcatAspectBenchmark netcoreapp3.1 487μs 1.35μs 4.88μs 0 0 0 255.16 KB
master StringConcatAspectBenchmark net472 402μs 2.12μs 15.7μs 0 0 0 278.53 KB
#7413 StringConcatBenchmark net6.0 47.9μs 269ns 1.7μs 0 0 0 44.42 KB
#7413 StringConcatBenchmark netcoreapp3.1 57.3μs 717ns 7.06μs 0 0 0 43.26 KB
#7413 StringConcatBenchmark net472 57.4μs 222ns 860ns 0 0 0 57.34 KB
#7413 StringConcatAspectBenchmark net6.0 379μs 4.78μs 47.1μs 0 0 0 246.94 KB
#7413 StringConcatAspectBenchmark netcoreapp3.1 533μs 2.18μs 9.52μs 0 0 0 275.9 KB
#7413 StringConcatAspectBenchmark net472 407μs 2.22μs 12.6μs 0 0 0 278.53 KB
Benchmarks.Trace.ILoggerBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 2.53μs 11.8ns 48.5ns 0 0 0 1.7 KB
master EnrichedLog netcoreapp3.1 3.38μs 2.64ns 10.2ns 0 0 0 1.7 KB
master EnrichedLog net472 3.91μs 2.8ns 10.8ns 0.253 0 0 1.64 KB
#7413 EnrichedLog net6.0 2.57μs 5.05ns 19.6ns 0 0 0 1.7 KB
#7413 EnrichedLog netcoreapp3.1 3.4μs 13.4ns 52ns 0 0 0 1.7 KB
#7413 EnrichedLog net472 3.99μs 3.32ns 12.9ns 0.259 0 0 1.64 KB
Benchmarks.Trace.Log4netBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 124μs 73.9ns 267ns 0 0 0 4.31 KB
master EnrichedLog netcoreapp3.1 127μs 160ns 599ns 0 0 0 4.31 KB
master EnrichedLog net472 172μs 224ns 869ns 0 0 0 4.52 KB
#7413 EnrichedLog net6.0 121μs 49.7ns 186ns 0 0 0 4.31 KB
#7413 EnrichedLog netcoreapp3.1 127μs 209ns 754ns 0 0 0 4.31 KB
#7413 EnrichedLog net472 166μs 45.7ns 177ns 0 0 0 4.51 KB
Benchmarks.Trace.NLogBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 4.77μs 20.7ns 80.4ns 0 0 0 2.26 KB
master EnrichedLog netcoreapp3.1 6.91μs 13.8ns 53.4ns 0 0 0 2.26 KB
master EnrichedLog net472 7.48μs 5.55ns 21.5ns 0.298 0 0 2.08 KB
#7413 EnrichedLog net6.0 5.14μs 4.2ns 16.3ns 0 0 0 2.26 KB
#7413 EnrichedLog netcoreapp3.1 6.75μs 19.8ns 76.8ns 0 0 0 2.26 KB
#7413 EnrichedLog net472 7.42μs 4.08ns 15.8ns 0.296 0 0 2.08 KB
Benchmarks.Trace.RedisBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendReceive net6.0 1.95μs 9.18ns 35.5ns 0 0 0 1.2 KB
master SendReceive netcoreapp3.1 2.54μs 11.6ns 44.8ns 0 0 0 1.2 KB
master SendReceive net472 3.12μs 1.52ns 5.88ns 0.188 0 0 1.2 KB
#7413 SendReceive net6.0 1.95μs 6.77ns 26.2ns 0 0 0 1.2 KB
#7413 SendReceive netcoreapp3.1 2.75μs 11.7ns 45.2ns 0 0 0 1.2 KB
#7413 SendReceive net472 3.05μs 1.09ns 4.21ns 0.184 0 0 1.2 KB
Benchmarks.Trace.SerilogBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 4.14μs 3.77ns 14.1ns 0 0 0 1.58 KB
master EnrichedLog netcoreapp3.1 5.53μs 10.4ns 40.2ns 0 0 0 1.63 KB
master EnrichedLog net472 6.86μs 9.72ns 37.7ns 0.306 0 0 2.03 KB
#7413 EnrichedLog net6.0 4.14μs 4.9ns 19ns 0 0 0 1.58 KB
#7413 EnrichedLog netcoreapp3.1 5.74μs 6.1ns 23.6ns 0 0 0 1.63 KB
#7413 EnrichedLog net472 6.4μs 8.3ns 32.2ns 0.319 0 0 2.03 KB
Benchmarks.Trace.SpanBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartFinishSpan net6.0 748ns 0.179ns 0.694ns 0 0 0 576 B
master StartFinishSpan netcoreapp3.1 950ns 0.472ns 1.83ns 0 0 0 576 B
master StartFinishSpan net472 895ns 0.0664ns 0.239ns 0.0895 0 0 578 B
master StartFinishScope net6.0 885ns 4.83ns 21.6ns 0 0 0 696 B
master StartFinishScope netcoreapp3.1 1.11μs 1.34ns 5.01ns 0 0 0 696 B
master StartFinishScope net472 1.12μs 2.85ns 11ns 0.105 0 0 658 B
#7413 StartFinishSpan net6.0 750ns 0.208ns 0.804ns 0 0 0 576 B
#7413 StartFinishSpan netcoreapp3.1 954ns 5.01ns 26ns 0 0 0 576 B
#7413 StartFinishSpan net472 922ns 0.0409ns 0.142ns 0.0913 0 0 578 B
#7413 StartFinishScope net6.0 917ns 0.326ns 1.26ns 0 0 0 696 B
#7413 StartFinishScope netcoreapp3.1 1.12μs 5.65ns 25.3ns 0 0 0 696 B
#7413 StartFinishScope net472 1.09μs 0.233ns 0.904ns 0.104 0 0 658 B
Benchmarks.Trace.TraceAnnotationsBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master RunOnMethodBegin net6.0 1.03μs 5.67ns 33.6ns 0 0 0 696 B
master RunOnMethodBegin netcoreapp3.1 1.4μs 5.31ns 20.6ns 0 0 0 696 B
master RunOnMethodBegin net472 1.37μs 1.48ns 5.73ns 0.102 0 0 658 B
#7413 RunOnMethodBegin net6.0 1.03μs 4.63ns 19.6ns 0 0 0 696 B
#7413 RunOnMethodBegin netcoreapp3.1 1.36μs 6.57ns 27.1ns 0 0 0 696 B
#7413 RunOnMethodBegin net472 1.37μs 1.19ns 4.61ns 0.103 0 0 658 B

@pablomartinezbernardo pablomartinezbernardo changed the title Pmartinez/servicebus review [Tracer] Servicebus Aug 26, 2025
@pablomartinezbernardo pablomartinezbernardo force-pushed the pmartinez/servicebus-review branch from 1234120 to 728724e Compare August 26, 2025 10:41
@dd-trace-dotnet-ci-bot
Copy link

dd-trace-dotnet-ci-bot bot commented Aug 26, 2025

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing the following branches/commits:

Execution-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 shown in red. The following thresholds were used for comparing the execution times:

  • Welch test with statistical test for significance of 5%
  • Only results indicating a difference greater than 5% and 5 ms are considered.

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).

gantt
    title Execution time (ms) FakeDbCommand (.NET Framework 4.8) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Bailout
    This PR (7413) - mean (74ms)  : 72, 76
     .   : milestone, 74,
    master - mean (72ms)  : 71, 73
     .   : milestone, 72,

    section Baseline
    This PR (7413) - mean (71ms)  : 66, 76
     .   : milestone, 71,
    master - mean (70ms)  : 63, 77
     .   : milestone, 70,

    section CallTarget+Inlining+NGEN
    This PR (7413) - mean (1,001ms)  : 973, 1029
     .   : milestone, 1001,
    master - mean (992ms)  : 968, 1017
     .   : milestone, 992,

Loading
gantt
    title Execution time (ms) FakeDbCommand (.NET Core 3.1) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Bailout
    This PR (7413) - mean (111ms)  : 108, 113
     .   : milestone, 111,
    master - mean (106ms)  : 105, 107
     .   : milestone, 106,

    section Baseline
    This PR (7413) - mean (109ms)  : 106, 112
     .   : milestone, 109,
    master - mean (106ms)  : 103, 108
     .   : milestone, 106,

    section CallTarget+Inlining+NGEN
    This PR (7413) - mean (710ms)  : 688, 732
     .   : milestone, 710,
    master - mean (703ms)  : 685, 720
     .   : milestone, 703,

Loading
gantt
    title Execution time (ms) FakeDbCommand (.NET 6) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Bailout
    This PR (7413) - mean (97ms)  : 95, 100
     .   : milestone, 97,
    master - mean (94ms)  : 93, 96
     .   : milestone, 94,

    section Baseline
    This PR (7413) - mean (96ms)  : 93, 100
     .   : milestone, 96,
    master - mean (93ms)  : 91, 95
     .   : milestone, 93,

    section CallTarget+Inlining+NGEN
    This PR (7413) - mean (665ms)  : 643, 686
     .   : milestone, 665,
    master - mean (658ms)  : 640, 677
     .   : milestone, 658,

Loading
gantt
    title Execution time (ms) FakeDbCommand (.NET 8) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Bailout
    This PR (7413) - mean (96ms)  : 94, 98
     .   : milestone, 96,
    master - mean (93ms)  : 91, 94
     .   : milestone, 93,

    section Baseline
    This PR (7413) - mean (95ms)  : 92, 98
     .   : milestone, 95,
    master - mean (92ms)  : 89, 96
     .   : milestone, 92,

    section CallTarget+Inlining+NGEN
    This PR (7413) - mean (600ms)  : 588, 611
     .   : milestone, 600,
    master - mean (593ms)  : 584, 603
     .   : milestone, 593,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET Framework 4.8) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Bailout
    This PR (7413) - mean (193ms)  : 190, 196
     .   : milestone, 193,
    master - mean (193ms)  : 186, 199
     .   : milestone, 193,

    section Baseline
    This PR (7413) - mean (189ms)  : 182, 196
     .   : milestone, 189,
    master - mean (189ms)  : 180, 197
     .   : milestone, 189,

    section CallTarget+Inlining+NGEN
    This PR (7413) - mean (1,083ms)  : 1048, 1118
     .   : milestone, 1083,
    master - mean (1,084ms)  : 1045, 1124
     .   : milestone, 1084,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET Core 3.1) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Bailout
    This PR (7413) - mean (273ms)  : 265, 281
     .   : milestone, 273,
    master - mean (272ms)  : 264, 279
     .   : milestone, 272,

    section Baseline
    This PR (7413) - mean (271ms)  : 262, 280
     .   : milestone, 271,
    master - mean (272ms)  : 263, 281
     .   : milestone, 272,

    section CallTarget+Inlining+NGEN
    This PR (7413) - mean (877ms)  : 848, 907
     .   : milestone, 877,
    master - mean (884ms)  : 844, 924
     .   : milestone, 884,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Bailout
    This PR (7413) - mean (263ms)  : 254, 272
     .   : milestone, 263,
    master - mean (266ms)  : 252, 279
     .   : milestone, 266,

    section Baseline
    This PR (7413) - mean (263ms)  : 253, 272
     .   : milestone, 263,
    master - mean (264ms)  : 257, 271
     .   : milestone, 264,

    section CallTarget+Inlining+NGEN
    This PR (7413) - mean (863ms)  : 833, 894
     .   : milestone, 863,
    master - mean (870ms)  : 836, 904
     .   : milestone, 870,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET 8) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Bailout
    This PR (7413) - mean (264ms)  : 257, 272
     .   : milestone, 264,
    master - mean (264ms)  : 258, 271
     .   : milestone, 264,

    section Baseline
    This PR (7413) - mean (265ms)  : 257, 274
     .   : milestone, 265,
    master - mean (264ms)  : 254, 274
     .   : milestone, 264,

    section CallTarget+Inlining+NGEN
    This PR (7413) - mean (778ms)  : 754, 801
     .   : milestone, 778,
    master - mean (777ms)  : 751, 803
     .   : milestone, 777,

Loading

@pablomartinezbernardo pablomartinezbernardo force-pushed the pmartinez/servicebus-review branch from 1c0262a to 8712c7c Compare August 28, 2025 15:22
@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Aug 28, 2025

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: a3510c7 | Docs | Was this helpful? Give us feedback!

@pablomartinezbernardo pablomartinezbernardo force-pushed the pmartinez/servicebus-review branch 3 times, most recently from d545c69 to 729efe5 Compare September 1, 2025 15:24
@pablomartinezbernardo pablomartinezbernardo marked this pull request as ready for review September 2, 2025 11:49
@pablomartinezbernardo pablomartinezbernardo force-pushed the pmartinez/servicebus-review branch 2 times, most recently from 5879846 to 189d026 Compare September 3, 2025 11:18

if (!areAllTheSame)
{
Log.Warning("Multiple different contexts found in ServiceBus messages. Using first context for parentship.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a valid use-case, consider lowering the log severity. Otherwise some users will get these warnings all the time and they are not actionable.

Copy link
Contributor Author

@pablomartinezbernardo pablomartinezbernardo Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a valid use-case, when messages are received by a function they should have already gone through the ReceiveMessageIntegration and have their messages reparented, so this situation means that for some reason the ReceiveMessagesIntegration was never ran, which means things will not work as expected.

Still, I'm not completely used to the usual severity of the logs, so if you still think it should be lower please say!

{
if (kvp.Key.FullName?.Equals("Microsoft.Azure.Functions.Worker.Context.Features.IFunctionBindingsFeature") == true)
{
bindingsFeature = kvp.Value?.TryDuckCast<GrpcBindingsFeatureStruct>(out var feature) == true ? feature : null;
Copy link
Member

@lucaspimentel lucaspimentel Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do this instead? Assuming TryDuckCast() sets the out parameter to null when it fails (it should).

Suggested change
bindingsFeature = kvp.Value?.TryDuckCast<GrpcBindingsFeatureStruct>(out var feature) == true ? feature : null;
kvp.Value?.TryDuckCast<GrpcBindingsFeatureStruct>(out var bindingsFeature);

(level of care: low)

Copy link
Contributor Author

@pablomartinezbernardo pablomartinezbernardo Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming TryDuckCast() sets the out parameter to null when it fails (it should).

It doesn't, it even requires non-null and the object is a nullable struct

{
if (carrier.TryGetValue(key, out var value) && value is string stringValue)
{
return new[] { stringValue };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return new[] { stringValue };
return [stringValue];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be incompatible with older net fwks right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually a C# language feature added in C# 12 so not tied to a framework-> https://andrewlock.net/behind-the-scenes-of-collection-expressions-part-1-introducing-collection-expressions-in-csharp12/

return new[] { stringValue };
}

return Enumerable.Empty<string>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return Enumerable.Empty<string>();
return [];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the other comment, this would not be compatible with older net fwks, might be missing something though 🤔

Comment on lines 10 to 11
using System.Linq;
using System.Text;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
using System.Linq;
using System.Text;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed only System.Text because of the other comments in this file

* Create consumption span
* Service bus function triggers parent to the previous span
* Service bus function spans don't contain messaging info
* Avoid reflection
# Conflicts:
#	tracer/dependabot/Datadog.Dependabot.Integrations.csproj
Comment on lines +867 to +877
{
"IntegrationName": "AzureServiceBusAPM",
"SampleProjectName": "Samples.AzureServiceBus.APM",
"NugetPackageSearchName": "Azure.Messaging.ServiceBus",
"MinVersion": "7.18.0",
"MaxVersionExclusive": "7.21.0",
"SpecificVersions": [
"7.18.*",
"7.*.*"
]
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify, we made a new one here because the sample application is different?

Comment on lines +6 to +9
using System.Collections.Generic;
using Datadog.Trace.DuckTyping;

#if !NETFRAMEWORK
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
using System.Collections.Generic;
using Datadog.Trace.DuckTyping;
#if !NETFRAMEWORK
#if !NETFRAMEWORK
using System.Collections.Generic;
using Datadog.Trace.DuckTyping;

nitpick but the usings can be moved within the preprocessor

@@ -209,6 +209,19 @@ services:
- ACCEPT_EULA=Y
- SA_PASSWORD=Strong!Passw0rd

azureservicebus-emulator:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome thanks!

return extractedContext.SpanContext;
}

private static T? TryParseJson<T>(object? jsonObj)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick but I think changing this to return a bool and have an out T? would be better (you'd need to update usages potentially) just to be more consistent with Try... functions

Suggested change
private static T? TryParseJson<T>(object? jsonObj)
private static bool TryParseJson<T>(object? jsonObj, out T? result)

// Check if all contexts are the same
var firstContext = extractedContexts[0];
var comparer = new SpanContextComparer();
var allSame = extractedContexts.All(ctx => comparer.Equals(ctx, firstContext));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance we could modify this function so we aren't doing two iterations over the contexts?
Maybe we could do a HashSet

Maybe it isn't super important though I don't know how many contexts we'd actually expect here so it may be very marginal.

var messageCount = messagesList?.Count ?? 0;

// Don't create spans when there's an exception or no messages
if (exception != null || messageCount == 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we create a span when there is an exception?

MethodName = "ReceiveMessagesAsync",
ReturnTypeName = "System.Threading.Tasks.Task`1[System.Collections.Generic.IReadOnlyList`1[Azure.Messaging.ServiceBus.ServiceBusReceivedMessage]]",
ParameterTypeNames = [ClrNames.Int32, "System.Nullable`1[System.TimeSpan]", ClrNames.Bool, ClrNames.CancellationToken],
MinimumVersion = "7.14.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want to make sure that the 7.14.0 is right (haven't checked anything just wondering)

Comment on lines +82 to +101
Scope? scope = state.Scope;

if (scope is null)
{
return returnValue;
}

try
{
if (exception != null)
{
scope.Span.SetException(exception);
}
}
finally
{
scope.Dispose();
}

return returnValue;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a helper for this that looks like

Suggested change
Scope? scope = state.Scope;
if (scope is null)
{
return returnValue;
}
try
{
if (exception != null)
{
scope.Span.SetException(exception);
}
}
finally
{
scope.Dispose();
}
return returnValue;
state.Scope.DisposeWithException(exception);
return returnValue;

@@ -17,6 +17,9 @@ internal partial class AzureServiceBusTags : OpenTelemetryTags
{
private string _spanKind;

[Tag(Trace.Tags.InstrumentationName)]
public string InstrumentationName { get; set; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to ensure it is always set (you'll need to update instances where it was being set explicitly though)

Suggested change
public string InstrumentationName { get; set; }
public string InstrumentationName => nameof(IntegrationId.AzureServiceBus);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have tests for the span links?

I'm actually not entirely sure what testing Span Links looks like though at the moment, but I'd think we would have an example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants