Set resource name after exception in OnEndRequest method#8439
Conversation
Execution-Time Benchmarks Report ⏱️Execution-time results for samples comparing This PR (8439) 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 (8439) - mean (72ms) : 68, 75
master - mean (71ms) : 69, 73
section Bailout
This PR (8439) - mean (76ms) : 74, 78
master - mean (76ms) : 73, 79
section CallTarget+Inlining+NGEN
This PR (8439) - mean (1,062ms) : 1021, 1103
master - mean (1,062ms) : 1019, 1105
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 (8439) - mean (112ms) : 108, 115
master - mean (112ms) : 109, 116
section Bailout
This PR (8439) - mean (114ms) : 111, 118
master - mean (114ms) : 112, 117
section CallTarget+Inlining+NGEN
This PR (8439) - mean (784ms) : 763, 804
master - mean (784ms) : 761, 807
FakeDbCommand (.NET 6)gantt
title Execution time (ms) FakeDbCommand (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8439) - mean (100ms) : 96, 103
master - mean (100ms) : 96, 103
section Bailout
This PR (8439) - mean (101ms) : 98, 105
master - mean (100ms) : 97, 102
section CallTarget+Inlining+NGEN
This PR (8439) - mean (937ms) : 906, 969
master - mean (930ms) : 890, 971
FakeDbCommand (.NET 8)gantt
title Execution time (ms) FakeDbCommand (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8439) - mean (98ms) : 95, 102
master - mean (98ms) : 94, 102
section Bailout
This PR (8439) - mean (100ms) : 96, 103
master - mean (99ms) : 96, 103
section CallTarget+Inlining+NGEN
This PR (8439) - mean (815ms) : 777, 853
master - mean (819ms) : 780, 859
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 (8439) - mean (208ms) : 203, 214
master - mean (206ms) : 201, 211
section Bailout
This PR (8439) - mean (210ms) : 207, 214
master - mean (210ms) : 206, 213
section CallTarget+Inlining+NGEN
This PR (8439) - mean (1,216ms) : 1159, 1273
master - mean (1,207ms) : 1169, 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 (8439) - mean (296ms) : 289, 303
master - mean (297ms) : 289, 305
section Bailout
This PR (8439) - mean (297ms) : 290, 304
master - mean (299ms) : 293, 306
section CallTarget+Inlining+NGEN
This PR (8439) - mean (976ms) : 945, 1006
master - mean (1,002ms) : 964, 1040
HttpMessageHandler (.NET 6)gantt
title Execution time (ms) HttpMessageHandler (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8439) - mean (289ms) : 282, 296
master - mean (292ms) : 286, 297
section Bailout
This PR (8439) - mean (289ms) : 283, 295
master - mean (293ms) : 288, 297
section CallTarget+Inlining+NGEN
This PR (8439) - mean (1,169ms) : 1133, 1204
master - mean (1,167ms) : 1124, 1210
HttpMessageHandler (.NET 8)gantt
title Execution time (ms) HttpMessageHandler (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8439) - mean (288ms) : 282, 295
master - mean (289ms) : 283, 296
section Bailout
This PR (8439) - mean (289ms) : 283, 295
master - mean (290ms) : 284, 296
section CallTarget+Inlining+NGEN
This PR (8439) - mean (1,053ms) : 994, 1113
master - mean (1,067ms) : 971, 1162
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BenchmarksBenchmark execution time: 2026-04-15 11:22:05 Comparing candidate commit c5672d7 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 27 metrics, 0 unstable metrics, 87 known flaky benchmarks.
|
andrewlock
left a comment
There was a problem hiding this comment.
If we can avoid it, I'd really rather we didn't do this, as it increases allocations bunch 🙁 Is there really no way to detect the disconnection? Given that we presumably still close the span (otherwise you wouldn't see them returned), I'm assuming OnEndRequest() still runs? Or is it catching an error in the Exception handler here (and if so, could we move the pre-emptive resource name calculation here instead?)
Maybe we can move the logic to OnEndRequest by adding a finally block? Something like: Line 415: |
When no resource-based sampling rules are configured, the resource name is only set in OnEndRequest. If an exception occurs before the resource name logic runs (e.g. in security/IAST processing), the resource name remains null and defaults to the operation name "aspnet.request" in Span.Finish(). This fix adds a fallback in the OnEndRequest finally block to set the resource name before scope disposal. Fixes APMS-19184 Co-authored-by: Anna <[email protected]>
3a84935 to
1227ccf
Compare
andrewlock
left a comment
There was a problem hiding this comment.
Thanks @NachoEchevarria, I think this is a good solution, but you may also need to do it on line 266 too?
We also need to make sure this works with "inferred proxy scopes" too - I haven't looked into it to see if that would be affected 🙂
Good catch! Done! About proxies, AzureApiManagementSpanFactory and AwsApiGatewaySpanFactory set ResourceName at creation time (lines 41 and 40 respectively). So proxy spans already have their resource name set before they reach |
andrewlock
left a comment
There was a problem hiding this comment.
LGTM in general, but you have some build errors! Approving assuming that you apply these changes one way or another 🙂
Co-authored-by: Andrew Lock <[email protected]>
Co-authored-by: Andrew Lock <[email protected]>
When no resource-based sampling rules are configured, the resource name was only set in OnEndRequest. If OnEndRequest doesn't complete (e.g., client disconnect), the resource name remained null and defaulted to the operation name aspnet.request in Span.Finish(). This fix ensures the resource name is always set early in OnBeginRequest. Fixes APMS-19184
Made-with: Cursor
Summary of changes
Reason for change
https://datadoghq.atlassian.net/browse/APMS-19184
Implementation details
Test coverage
Other details