Skip to content

Conversation

@andrewlock
Copy link
Member

@andrewlock andrewlock commented Jan 13, 2026

Summary of changes

Make our ASP.NET Core's Diagnostic Observer copy Activity tags to the root span instead of the MVC span

Reason for change

This came up in a customer escalation recently, plus it just makes sense, and there's a bunch of issues

  • There isn't always an MVC span, so adding the tags there doesn't really make sense
  • Again, in the single-span observer, there's no mvc span
  • Logically there's only one activity per request, so if we're going to "associate" it with one of our spans it should be the root
  • Adding the tags at the point of mvc finish means tags could be added later (by middleware) and not copied across
  • We shouldn't add baggage as tags by default
  • We should use the TagObjects if available

Implementation details

  • Extracted the common "activity tags copying" code into the existing handler, so it's shared
  • Make the copying happen in the request end event, which is always called, and is just before the activity is stopped
  • Ensure that the current activity we're copying from is the activity we expect ("Microsoft.AspNetCore.Hosting.HttpRequestIn")
  • Use the same logic for copying tags as we have in OtlpHelpers (doing the allocation free enumeration etc)
  • Remove the no-longer needed OnMvcAfterAction from single-span observer

Test coverage

Added integration tests to confirm the tags are added to the root span as expected. Note that the .NET Core 2.1 sample doesn't reference a new-enough version of System.Diagnostics.Activity, so we can't enable the listener in that scenario. Rather than change the sample dependencies, I omitted the testing, as it's low risk, and we don't technically support it now anyway

Other details

Note that this is technically a breaking change, because we are no longer writing some tags that were written to the mvc span. However, given all the reasons above, we consider this to be a bug fix in practice.

Also, the copying behaviour is only enabled when you explicitly enable OTel integration, so the blast radius is reduced.

@github-actions github-actions bot added the area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations) label Jan 13, 2026
@pr-commenter
Copy link

pr-commenter bot commented Jan 13, 2026

Benchmarks

Benchmark execution time: 2026-01-15 12:00:02

Comparing candidate commit 39067b1 in PR branch andrew/fix-aspnetcore-activities with baseline commit 1472f1b in branch master.

Found 2 performance improvements and 10 performance regressions! Performance is the same for 160 metrics, 20 unstable metrics.

scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces net6.0

  • 🟥 execution_time [+20.451ms; +20.498ms] or [+20.485%; +20.532%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleMoreComplexBody net6.0

  • 🟩 execution_time [-17.998ms; -12.479ms] or [-8.529%; -5.913%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorMoreComplexBody netcoreapp3.1

  • 🟥 execution_time [+11.299ms; +16.617ms] or [+5.756%; +8.465%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net6.0

  • 🟥 throughput [-238.747op/s; -114.908op/s] or [-16.754%; -8.064%]

scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice net6.0

  • 🟥 execution_time [+92.065µs; +95.922µs] or [+6.479%; +6.750%]
  • 🟥 throughput [-44.585op/s; -42.736op/s] or [-6.336%; -6.073%]

scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net6.0

  • 🟥 execution_time [+231.197µs; +236.803µs] or [+22.380%; +22.922%]
  • 🟥 throughput [-181.118op/s; -176.444op/s] or [-18.710%; -18.227%]

scenario:Benchmarks.Trace.CharSliceBenchmark.OriginalCharSlice net6.0

  • 🟥 execution_time [+151.307µs; +199.839µs] or [+7.385%; +9.753%]
  • 🟥 throughput [-42.931op/s; -33.750op/s] or [-8.796%; -6.915%]

scenario:Benchmarks.Trace.DbCommandBenchmark.ExecuteNonQuery net6.0

  • 🟥 execution_time [+12.661ms; +16.937ms] or [+6.461%; +8.644%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes net6.0

  • 🟩 execution_time [-21.115ms; -15.632ms] or [-9.739%; -7.210%]

@dd-trace-dotnet-ci-bot
Copy link

dd-trace-dotnet-ci-bot bot commented Jan 13, 2026

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing This PR (8054) and master.

✅ No regressions detected - check the details below

Full Metrics Comparison

FakeDbCommand

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration68.24 ± (68.26 - 68.48) ms68.39 ± (68.42 - 68.67) ms+0.2%✅⬆️
.NET Framework 4.8 - Bailout
duration72.24 ± (72.14 - 72.39) ms72.07 ± (72.03 - 72.26) ms-0.2%
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration996.61 ± (1002.81 - 1012.49) ms1009.38 ± (1015.17 - 1025.80) ms+1.3%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms21.89 ± (21.86 - 21.91) ms21.78 ± (21.75 - 21.81) ms-0.5%
process.time_to_main_ms78.35 ± (78.20 - 78.51) ms78.91 ± (78.74 - 79.09) ms+0.7%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.90 ± (10.89 - 10.90) MB10.91 ± (10.91 - 10.92) MB+0.1%✅⬆️
runtime.dotnet.threads.count12 ± (12 - 12)12 ± (12 - 12)+0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms21.76 ± (21.74 - 21.78) ms21.80 ± (21.77 - 21.82) ms+0.2%✅⬆️
process.time_to_main_ms79.61 ± (79.51 - 79.71) ms80.12 ± (80.02 - 80.21) ms+0.6%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.93 ± (10.92 - 10.93) MB10.95 ± (10.94 - 10.95) MB+0.2%✅⬆️
runtime.dotnet.threads.count13 ± (13 - 13)13 ± (13 - 13)+0.0%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms255.09 ± (252.74 - 257.43) ms248.74 ± (245.58 - 251.91) ms-2.5%
process.time_to_main_ms466.42 ± (466.00 - 466.84) ms468.43 ± (467.86 - 469.00) ms+0.4%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.35 ± (48.33 - 48.38) MB48.40 ± (48.38 - 48.42) MB+0.1%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.1%✅⬆️
.NET 6 - Baseline
process.internal_duration_ms20.59 ± (20.56 - 20.61) ms20.82 ± (20.79 - 20.85) ms+1.1%✅⬆️
process.time_to_main_ms68.05 ± (67.94 - 68.16) ms68.50 ± (68.35 - 68.64) ms+0.7%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.63 ± (10.62 - 10.63) MB10.64 ± (10.63 - 10.64) MB+0.1%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 6 - Bailout
process.internal_duration_ms20.43 ± (20.41 - 20.46) ms20.68 ± (20.66 - 20.70) ms+1.2%✅⬆️
process.time_to_main_ms68.74 ± (68.68 - 68.80) ms69.25 ± (69.19 - 69.31) ms+0.7%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.67 ± (10.66 - 10.67) MB10.76 ± (10.74 - 10.77) MB+0.8%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms248.57 ± (247.20 - 249.95) ms251.31 ± (250.11 - 252.51) ms+1.1%✅⬆️
process.time_to_main_ms443.30 ± (442.93 - 443.68) ms446.04 ± (445.62 - 446.47) ms+0.6%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed49.16 ± (49.13 - 49.19) MB49.14 ± (49.12 - 49.17) MB-0.0%
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.0%
.NET 8 - Baseline
process.internal_duration_ms18.75 ± (18.72 - 18.78) ms18.92 ± (18.89 - 18.94) ms+0.9%✅⬆️
process.time_to_main_ms66.96 ± (66.84 - 67.08) ms67.65 ± (67.53 - 67.76) ms+1.0%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.66 ± (7.65 - 7.67) MB7.67 ± (7.66 - 7.67) MB+0.1%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 8 - Bailout
process.internal_duration_ms18.74 ± (18.72 - 18.76) ms18.87 ± (18.84 - 18.90) ms+0.7%✅⬆️
process.time_to_main_ms68.20 ± (68.14 - 68.26) ms68.57 ± (68.50 - 68.63) ms+0.5%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.75 ± (7.74 - 7.77) MB7.73 ± (7.72 - 7.74) MB-0.3%
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms178.23 ± (177.38 - 179.08) ms179.60 ± (178.91 - 180.30) ms+0.8%✅⬆️
process.time_to_main_ms427.13 ± (426.52 - 427.74) ms431.98 ± (431.42 - 432.54) ms+1.1%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed36.55 ± (36.52 - 36.57) MB36.62 ± (36.60 - 36.65) MB+0.2%✅⬆️
runtime.dotnet.threads.count27 ± (27 - 27)27 ± (27 - 27)-0.4%

HttpMessageHandler

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration193.61 ± (193.56 - 194.43) ms193.12 ± (192.92 - 193.69) ms-0.3%
.NET Framework 4.8 - Bailout
duration197.45 ± (197.34 - 198.18) ms196.68 ± (196.30 - 197.00) ms-0.4%
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1118.85 ± (1121.18 - 1129.14) ms1123.99 ± (1129.06 - 1139.72) ms+0.5%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms187.74 ± (187.34 - 188.14) ms187.83 ± (187.41 - 188.25) ms+0.0%✅⬆️
process.time_to_main_ms80.96 ± (80.75 - 81.17) ms80.78 ± (80.55 - 81.01) ms-0.2%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.07 ± (16.05 - 16.10) MB16.15 ± (16.12 - 16.17) MB+0.5%✅⬆️
runtime.dotnet.threads.count20 ± (19 - 20)20 ± (19 - 20)+0.1%✅⬆️
.NET Core 3.1 - Bailout
process.internal_duration_ms186.06 ± (185.75 - 186.37) ms187.06 ± (186.74 - 187.39) ms+0.5%✅⬆️
process.time_to_main_ms82.30 ± (82.16 - 82.45) ms82.24 ± (82.08 - 82.41) ms-0.1%
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.13 ± (16.11 - 16.16) MB16.17 ± (16.14 - 16.19) MB+0.2%✅⬆️
runtime.dotnet.threads.count21 ± (21 - 21)21 ± (21 - 21)+0.2%✅⬆️
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms436.15 ± (433.19 - 439.11) ms434.86 ± (432.15 - 437.58) ms-0.3%
process.time_to_main_ms473.25 ± (472.71 - 473.78) ms473.29 ± (472.67 - 473.92) ms+0.0%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed58.70 ± (58.59 - 58.81) MB58.68 ± (58.58 - 58.78) MB-0.0%
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)+0.0%✅⬆️
.NET 6 - Baseline
process.internal_duration_ms191.92 ± (191.52 - 192.31) ms191.85 ± (191.40 - 192.29) ms-0.0%
process.time_to_main_ms70.07 ± (69.90 - 70.24) ms70.09 ± (69.90 - 70.29) ms+0.0%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.28 ± (16.17 - 16.38) MB16.20 ± (16.08 - 16.31) MB-0.5%
runtime.dotnet.threads.count18 ± (18 - 18)18 ± (18 - 19)+0.5%✅⬆️
.NET 6 - Bailout
process.internal_duration_ms191.12 ± (190.84 - 191.40) ms190.79 ± (190.46 - 191.11) ms-0.2%
process.time_to_main_ms71.06 ± (70.95 - 71.17) ms70.64 ± (70.52 - 70.75) ms-0.6%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.07 ± (15.92 - 16.22) MB16.16 ± (16.02 - 16.30) MB+0.6%✅⬆️
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)+0.7%✅⬆️
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms449.12 ± (446.33 - 451.91) ms453.50 ± (451.16 - 455.83) ms+1.0%✅⬆️
process.time_to_main_ms450.50 ± (450.01 - 450.99) ms450.68 ± (450.18 - 451.18) ms+0.0%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed58.75 ± (58.64 - 58.87) MB58.77 ± (58.65 - 58.89) MB+0.0%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)+0.1%✅⬆️
.NET 8 - Baseline
process.internal_duration_ms189.85 ± (189.47 - 190.22) ms189.93 ± (189.65 - 190.22) ms+0.0%✅⬆️
process.time_to_main_ms69.73 ± (69.55 - 69.92) ms70.02 ± (69.82 - 70.22) ms+0.4%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.81 ± (11.78 - 11.83) MB11.75 ± (11.72 - 11.78) MB-0.5%
runtime.dotnet.threads.count18 ± (18 - 18)18 ± (18 - 18)-0.2%
.NET 8 - Bailout
process.internal_duration_ms189.18 ± (188.95 - 189.42) ms190.01 ± (189.56 - 190.47) ms+0.4%✅⬆️
process.time_to_main_ms71.07 ± (70.92 - 71.21) ms71.02 ± (70.88 - 71.16) ms-0.1%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.91 ± (11.86 - 11.97) MB11.78 ± (11.75 - 11.81) MB-1.2%
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)+0.4%✅⬆️
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms364.75 ± (363.12 - 366.39) ms365.02 ± (363.45 - 366.60) ms+0.1%✅⬆️
process.time_to_main_ms433.95 ± (433.20 - 434.71) ms434.74 ± (434.04 - 435.45) ms+0.2%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed48.16 ± (48.11 - 48.21) MB48.20 ± (48.17 - 48.23) MB+0.1%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)-0.8%
Comparison explanation

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

Duration charts
FakeDbCommand (.NET Framework 4.8)
gantt
    title Execution time (ms) FakeDbCommand (.NET Framework 4.8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8054) - mean (69ms)  : 67, 70
    master - mean (68ms)  : 67, 70

    section Bailout
    This PR (8054) - mean (72ms)  : 71, 73
    master - mean (72ms)  : 71, 73

    section CallTarget+Inlining+NGEN
    This PR (8054) - mean (1,020ms)  : 943, 1098
    master - mean (1,008ms)  : 937, 1078

Loading
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 (8054) - mean (106ms)  : 103, 109
    master - mean (105ms)  : 103, 108

    section Bailout
    This PR (8054) - mean (107ms)  : 106, 108
    master - mean (106ms)  : 105, 108

    section CallTarget+Inlining+NGEN
    This PR (8054) - mean (744ms)  : 691, 798
    master - mean (744ms)  : 704, 784

Loading
FakeDbCommand (.NET 6)
gantt
    title Execution time (ms) FakeDbCommand (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8054) - mean (94ms)  : 92, 96
    master - mean (93ms)  : 91, 96

    section Bailout
    This PR (8054) - mean (95ms)  : 94, 95
    master - mean (94ms)  : 93, 95

    section CallTarget+Inlining+NGEN
    This PR (8054) - mean (723ms)  : 697, 750
    master - mean (714ms)  : 687, 742

Loading
FakeDbCommand (.NET 8)
gantt
    title Execution time (ms) FakeDbCommand (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8054) - mean (93ms)  : 90, 96
    master - mean (92ms)  : 89, 94

    section Bailout
    This PR (8054) - mean (93ms)  : 92, 95
    master - mean (93ms)  : 92, 94

    section CallTarget+Inlining+NGEN
    This PR (8054) - mean (643ms)  : 619, 667
    master - mean (633ms)  : 619, 647

Loading
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 (8054) - mean (193ms)  : 189, 197
    master - mean (194ms)  : 189, 199

    section Bailout
    This PR (8054) - mean (197ms)  : 193, 200
    master - mean (198ms)  : 194, 202

    section CallTarget+Inlining+NGEN
    This PR (8054) - mean (1,134ms)  : 1053, 1216
    master - mean (1,125ms)  : 1067, 1183

Loading
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 (8054) - mean (277ms)  : 272, 283
    master - mean (277ms)  : 271, 283

    section Bailout
    This PR (8054) - mean (277ms)  : 273, 282
    master - mean (277ms)  : 273, 280

    section CallTarget+Inlining+NGEN
    This PR (8054) - mean (936ms)  : 893, 978
    master - mean (936ms)  : 894, 979

Loading
HttpMessageHandler (.NET 6)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8054) - mean (270ms)  : 264, 276
    master - mean (271ms)  : 262, 279

    section Bailout
    This PR (8054) - mean (269ms)  : 266, 273
    master - mean (270ms)  : 266, 275

    section CallTarget+Inlining+NGEN
    This PR (8054) - mean (931ms)  : 894, 968
    master - mean (928ms)  : 883, 973

Loading
HttpMessageHandler (.NET 8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8054) - mean (270ms)  : 266, 274
    master - mean (269ms)  : 263, 275

    section Bailout
    This PR (8054) - mean (271ms)  : 264, 278
    master - mean (270ms)  : 265, 274

    section CallTarget+Inlining+NGEN
    This PR (8054) - mean (832ms)  : 811, 852
    master - mean (830ms)  : 811, 849

Loading

@andrewlock andrewlock force-pushed the andrew/fix-aspnetcore-activities branch from f212b57 to dcb2dce Compare January 14, 2026 16:03
@andrewlock andrewlock marked this pull request as ready for review January 14, 2026 16:14
@andrewlock andrewlock requested review from a team as code owners January 14, 2026 16:14
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dcb2dce101

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 190 to 192
var span = rootScope.Span;
CopyAspNetCoreActivityTagsIfRequired(span);
var isMissingHttpStatusCode = !span.HasHttpStatusCode();

Choose a reason for hiding this comment

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

P2 Badge Ensure error flag still set when activity has status

With the activity listener enabled, ASP.NET Core’s hosting activity includes a numeric http.status_code tag. CopyAspNetCoreActivityTagsIfRequired uses OtlpHelpers.SetTagObject, which maps that to Tags.HttpStatusCode, so HasHttpStatusCode() becomes true and SetHttpStatusCode(...) is skipped. SetHttpStatusCode is the place that applies error classification (span.Error and error msg) for non-exceptional 5xx responses, so requests that set a 5xx/4xx status without throwing will no longer be marked as errors once activity tag copying runs here.

Useful? React with 👍 / 👎.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmmm, this is an interesting one 🤔 I'm not sure what we should do here. We could easily filter out some of the tags if we don't want to risk conflicts etc but I'm not sure what we should do here 🤔 cc / @bouwkast @zacharycmontoya

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we would have to exclude/filter out this tag or looking at the code could we just always call SetHttpStatusCode?

Looking at it, I think we can just call it?

internal static void SetHttpStatusCode(this Span span, int statusCode, bool isServer, MutableSettings tracerSettings)

I guess that could be a bit fragile / wasteful though

Copy link
Contributor

Choose a reason for hiding this comment

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

We could override it by calling SetHttpStatusCode even if the tag is present, but I worry that the ASP.NET Core Activity could have the new attribute name http.response.status_code, in which case we could theoretically have two tags instead of one. So I propose that we instead just filter out tag names http.status_code and http.response.status_code when copying them over.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, my concern is mainly about multiple tags and worse, conflicting tags, so filtering may make sense 👍 I wonder if there's anything else we should be filtering too, that may conflict, e.g. route tags😬

Copy link
Member Author

Choose a reason for hiding this comment

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

I added an option to OtlpHelpers.SetTagObject() to allow excluding "known" otel values, because I don't think we want to (for example) set the operation name/resource name etc.

I also explicitly avoided setting tags that we set by default as part of the standard aspnetcore pipeline, as I could see weird things going on there if, for example, they're set with a different type of value to the ones we use.

This is all a little bit awkward and fragile tbh, but it's likely better than what we have today either way 😅

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah looks good to me 👍

@andrewlock andrewlock requested a review from a team as a code owner January 15, 2026 11:06
…ome issues:

- Use the non-allocating tag enumeration
- Only set the tags if the activity is the AspNetCore activity
…d of part way through

Technically, this is a breaking change, but we consider it to primarily be a bug fix.
@andrewlock andrewlock force-pushed the andrew/fix-aspnetcore-activities branch from 43f2013 to 39067b1 Compare January 15, 2026 11:17
Copy link
Collaborator

@bouwkast bouwkast left a comment

Choose a reason for hiding this comment

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

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations) breaking-change identified-by:customer type:bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants