Skip to content

Fix EH clause sort to handle try-in-handler nesting#8428

Merged
bouwkast merged 13 commits into
masterfrom
steven/attempt-fix-invalid-program-exception
Apr 17, 2026
Merged

Fix EH clause sort to handle try-in-handler nesting#8428
bouwkast merged 13 commits into
masterfrom
steven/attempt-fix-invalid-program-exception

Conversation

@bouwkast

@bouwkast bouwkast commented Apr 8, 2026

Copy link
Copy Markdown
Collaborator

Generated mostly by Claude

Summary of changes

Fix incorrect EH clause ordering in ILRewriter::Export() that caused InvalidProgramException when instrumenting methods with try blocks nested inside handler regions.

Reason for change

When we instrument a method, the IL rewriter may insert try/catch blocks inside the handler of an existing try/catch (e.g., debugger inserting EndMethod(SetException) inside an async state machine's outer catch, or CallTarget instrumentation wrapping handler logic). ECMA-335 II.19 requires such nested clauses to appear before the clause whose region encloses them in the EH table.

The existing sort comparator only checked try-in-try containment:

return a.m_pTryBegin->m_offset > b.m_pTryBegin->m_offset &&
       a.m_pTryEnd->m_offset < b.m_pTryEnd->m_offset;

Because the inserted clause's try region starts after the outer clause's try region ends, this check returns false. The clause stays in its appended position -- after the outer clause -- violating ECMA-335. The CLR validates EH table ordering on JIT and rejects the method with InvalidProgramException.

The comparator also violated strict weak ordering required by std::sort (transitivity of incomparability fails for sibling clauses adjacent to a nesting relationship), making its behavior undefined.

Implementation details

Replaced the inline std::sort with ILRewriter::SortEHClauses, a new static method that:

  1. Computes a nesting depth for each clause: the number of other clauses whose try or handler region strictly contains this clause's try region. This correctly detects both try-in-try and try-in-handler nesting per ECMA-335 II.19.

  2. Sorts by (depth descending, try offset ascending), which is a total order and therefore satisfies strict weak ordering. Deeper-nested clauses sort first, satisfying the ECMA-335 requirement.

The method is extracted as a static to make it directly unit-testable without requiring ICorProfilerInfo. Internal allocations use std::unique_ptr to prevent memory leaks if an allocation fails.

Test coverage

Added ILRewriterEHSortTest in Datadog.Tracer.Native.Tests with 8 Google Test cases covering:

  • Try-in-try nesting (existing behavior preserved)
  • Try-in-handler nesting (the core bug)
  • Sibling clauses (no nesting constraint, ordered by offset)
  • Three-level deep nesting
  • The exact debugger async middleware topology: 2 original Roslyn clauses + 3 debugger-inserted clauses, verifying the EndMethod(SetException) clause is ordered before the outer clause whose handler contains it
  • Single and zero clause edge cases

The OldComparatorFailsMiddlewareScenario test applies the original comparator inline against the middleware topology and asserts it produces the wrong ordering, confirming the bug is real and the new tests would catch a regression.

Added integration test in tracer/test/test-applications/integrations/Samples.TraceAnnotations/ExtremeExceptionHandling.cs that reproduces the crash. Without the fix, the test causes a CLR fatal exception.

Other details

Symptom: System.InvalidProgramException: Common Language Runtime detected an invalid program thrown on any instrumented method whose EH table contains try-in-handler nesting. Originally observed on async middleware InvokeAsync methods with Exception Replay enabled, but affects any instrumentation path that goes through ILRewriter::Export().

Linked to APMS-19196

@pr-commenter

pr-commenter Bot commented Apr 8, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-04-17 14:16:34

Comparing candidate commit c5713b9 in PR branch steven/attempt-fix-invalid-program-exception with baseline commit 0435a3a in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 27 metrics, 0 unstable metrics, 87 known flaky benchmarks.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Known flaky benchmarks

These benchmarks are marked as flaky and will not trigger a failure. Modify FLAKY_BENCHMARKS_REGEX to control which benchmarks are marked as flaky.

scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild net472

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.008%; +0.005%]
  • ignore execution_time [-1128.059µs; -90.298µs] or [-0.560%; -0.045%]
  • ignore throughput [+770.041op/s; +1179.225op/s] or [+0.913%; +1.398%]

scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild net6.0

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.006%; +0.007%]
  • ignore execution_time [-1933.774µs; +1559.472µs] or [-0.965%; +0.778%]
  • 🟩 throughput [+10325.798op/s; +12542.763op/s] or [+8.679%; +10.543%]

scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild netcoreapp3.1

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.003%; +0.007%]
  • ignore execution_time [+0.326ms; +2.496ms] or [+0.164%; +1.255%]
  • ignore throughput [-413.379op/s; +697.186op/s] or [-0.420%; +0.709%]

scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • ignore allocated_mem [-3 bytes; -2 bytes] or [-0.100%; -0.087%]
  • 🟥 execution_time [+300.819ms; +304.118ms] or [+149.277%; +150.914%]
  • ignore throughput [+16.774op/s; +20.891op/s] or [+3.018%; +3.759%]

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

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.009%; +0.002%]
  • 🟥 execution_time [+382.446ms; +385.132ms] or [+302.155%; +304.278%]
  • ignore throughput [+14.591op/s; +17.118op/s] or [+1.924%; +2.257%]

scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces netcoreapp3.1

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.009%; +0.002%]
  • 🟥 execution_time [+392.515ms; +395.039ms] or [+347.361%; +349.594%]
  • ignore throughput [-9.017op/s; -5.137op/s] or [-1.274%; -0.726%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleMoreComplexBody net472

  • 🟥 allocated_mem [+1.308KB; +1.308KB] or [+27.529%; +27.541%]
  • ignore execution_time [-196.202µs; +398.750µs] or [-0.098%; +0.199%]
  • ignore throughput [-5099.583op/s; -4601.697op/s] or [-3.968%; -3.580%]

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

  • 🟥 allocated_mem [+471 bytes; +472 bytes] or [+9.977%; +9.987%]
  • 🟩 execution_time [-15.713ms; -11.538ms] or [-7.338%; -5.389%]
  • ignore throughput [+3470.072op/s; +6293.657op/s] or [+2.533%; +4.594%]

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

  • 🟥 allocated_mem [+1.272KB; +1.272KB] or [+27.502%; +27.510%]
  • ignore execution_time [-13.096ms; -8.949ms] or [-6.236%; -4.261%]
  • ignore throughput [+137.010op/s; +2417.161op/s] or [+0.124%; +2.185%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody net472

  • 🟥 allocated_mem [+1.307KB; +1.307KB] or [+105.746%; +105.759%]
  • ignore execution_time [-1258.570µs; -503.762µs] or [-0.627%; -0.251%]
  • 🟥 throughput [-249756.774op/s; -243676.174op/s] or [-25.501%; -24.881%]

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

  • 🟥 allocated_mem [+471 bytes; +472 bytes] or [+38.558%; +38.566%]
  • 🟩 execution_time [-26.730ms; -21.882ms] or [-11.920%; -9.759%]
  • ignore throughput [-58177.033op/s; -35173.929op/s] or [-6.215%; -3.758%]

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

  • 🟥 allocated_mem [+1.272KB; +1.272KB] or [+105.292%; +105.304%]
  • ignore execution_time [-3.251ms; +1.126ms] or [-1.623%; +0.562%]
  • 🟥 throughput [-133971.845op/s; -117683.474op/s] or [-19.249%; -16.909%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorMoreComplexBody net472

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.007%; +0.003%]
  • ignore execution_time [-962.941µs; +79.061µs] or [-0.480%; +0.039%]
  • ignore throughput [-1315.477op/s; -494.675op/s] or [-0.885%; -0.333%]

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

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.004%; +0.003%]
  • ignore execution_time [+0.786ms; +4.290ms] or [+0.397%; +2.165%]
  • 🟩 throughput [+11497.394op/s; +14390.827op/s] or [+7.316%; +9.157%]

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

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.007%; +0.003%]
  • ignore execution_time [+2.391ms; +6.402ms] or [+1.219%; +3.264%]
  • 🟩 throughput [+7981.845op/s; +10632.585op/s] or [+6.359%; +8.470%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody net472

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.008%; +0.004%]
  • ignore execution_time [-295.992µs; -92.015µs] or [-0.148%; -0.046%]
  • ignore throughput [+30199.313op/s; +53730.528op/s] or [+0.919%; +1.635%]

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

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.006%; +0.008%]
  • ignore execution_time [-3.019ms; -2.120ms] or [-1.493%; -1.048%]
  • 🟩 throughput [+393972.474op/s; +416533.360op/s] or [+13.137%; +13.889%]

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

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.004%; +0.004%]
  • 🟩 execution_time [-18.817ms; -14.440ms] or [-8.674%; -6.656%]
  • 🟩 throughput [+215687.619op/s; +270279.776op/s] or [+8.561%; +10.728%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeArgs net472

  • ignore allocated_mem [+1 bytes; +4 bytes] or [+0.004%; +0.012%]
  • 🟥 execution_time [+300.290ms; +300.996ms] or [+150.045%; +150.398%]
  • ignore throughput [+193.656op/s; +210.618op/s] or [+2.139%; +2.326%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeArgs net6.0

  • ignore allocated_mem [-1 bytes; +2 bytes] or [-0.004%; +0.008%]
  • 🟥 execution_time [+299.074ms; +302.221ms] or [+150.824%; +152.411%]
  • ignore throughput [+237.698op/s; +454.369op/s] or [+1.818%; +3.475%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeArgs netcoreapp3.1

  • ignore allocated_mem [-1 bytes; +2 bytes] or [-0.004%; +0.008%]
  • 🟥 execution_time [+300.073ms; +302.624ms] or [+151.154%; +152.438%]
  • ignore throughput [+147.136op/s; +275.938op/s] or [+1.421%; +2.664%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs net472

  • ignore allocated_mem [+2 bytes; +3 bytes] or [+0.137%; +0.150%]
  • 🟥 execution_time [+296.237ms; +297.039ms] or [+145.500%; +145.894%]
  • ignore throughput [+13.600op/s; +22.643op/s] or [+0.361%; +0.600%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs net6.0

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.004%; +0.009%]
  • 🟥 execution_time [+296.315ms; +298.761ms] or [+144.858%; +146.053%]
  • ignore throughput [+124.420op/s; +164.522op/s] or [+1.808%; +2.390%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs netcoreapp3.1

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.004%; +0.009%]
  • 🟥 execution_time [+300.174ms; +301.304ms] or [+150.026%; +150.591%]
  • ignore throughput [+58.366op/s; +76.298op/s] or [+1.159%; +1.514%]

scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark net472

  • ignore allocated_mem [+0 bytes; +0 bytes] or [+nan%; +nan%]
  • ignore execution_time [+3.165µs; +6.847µs] or [+0.650%; +1.406%]
  • ignore throughput [-28.254op/s; -13.053op/s] or [-1.376%; -0.636%]

scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark net6.0

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.000%; +0.010%]
  • ignore execution_time [+15.889µs; +42.510µs] or [+3.644%; +9.750%]
  • ignore throughput [-210.167op/s; -90.382op/s] or [-9.137%; -3.929%]

scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark netcoreapp3.1

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.003%; +0.003%]
  • ignore execution_time [+7.361µs; +29.309µs] or [+1.577%; +6.280%]
  • ignore throughput [-144.909op/s; -64.214op/s] or [-6.689%; -2.964%]

scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack net472

  • ignore allocated_mem [+0 bytes; +0 bytes] or [+nan%; +nan%]
  • ignore execution_time [-5.768µs; -1.916µs] or [-1.557%; -0.517%]
  • ignore throughput [+14.697op/s; +42.508op/s] or [+0.544%; +1.574%]

scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack net6.0

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.003%; +0.007%]
  • 🟥 execution_time [+23.361µs; +47.162µs] or [+7.458%; +15.056%]
  • 🟥 throughput [-436.482op/s; -236.657op/s] or [-13.606%; -7.377%]

scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack netcoreapp3.1

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.003%; +0.003%]
  • ignore execution_time [-14.144µs; +8.210µs] or [-3.869%; +2.246%]
  • ignore throughput [-94.991op/s; +38.338op/s] or [-3.409%; +1.376%]

scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest net472

  • ignore allocated_mem [+0 bytes; +0 bytes] or [+nan%; +nan%]
  • 🟥 execution_time [+299.887ms; +300.530ms] or [+149.674%; +149.995%]
  • ignore throughput [-1794255.570op/s; -1227851.094op/s] or [-0.899%; -0.615%]

scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest net6.0

  • ignore allocated_mem [+79 bytes; +81 bytes] or [+0.442%; +0.453%]
  • 🟥 execution_time [+410.351ms; +415.196ms] or [+445.863%; +451.128%]
  • 🟩 throughput [+1030.454op/s; +1163.448op/s] or [+8.467%; +9.560%]

scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest netcoreapp3.1

  • ignore allocated_mem [+20 bytes; +22 bytes] or [+0.099%; +0.110%]
  • 🟥 execution_time [+368.460ms; +372.325ms] or [+279.768%; +282.703%]
  • 🟩 throughput [+642.140op/s; +840.914op/s] or [+6.216%; +8.141%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • ignore allocated_mem [+2.485KB; +2.490KB] or [+4.416%; +4.424%]
  • unstable execution_time [+312.010ms; +379.214ms] or [+143.459%; +174.359%]
  • 🟥 throughput [-468.812op/s; -415.884op/s] or [-42.479%; -37.683%]

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

  • ignore allocated_mem [-1.270KB; -1.268KB] or [-2.995%; -2.990%]
  • unstable execution_time [+200.374ms; +333.571ms] or [+85.391%; +142.154%]
  • 🟥 throughput [-746.762op/s; -663.299op/s] or [-49.809%; -44.242%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces netcoreapp3.1

  • ignore allocated_mem [+1.819KB; +1.822KB] or [+4.294%; +4.301%]
  • 🟥 execution_time [+334.180ms; +342.717ms] or [+199.878%; +204.985%]
  • 🟥 throughput [-408.908op/s; -373.715op/s] or [-28.472%; -26.021%]

scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice net472

  • ignore allocated_mem [+0 bytes; +0 bytes] or [+nan%; +nan%]
  • ignore execution_time [-79.159µs; -57.794µs] or [-3.984%; -2.908%]
  • ignore throughput [+15.521op/s; +21.187op/s] or [+3.084%; +4.210%]

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

  • ignore allocated_mem [+0 bytes; +0 bytes] or [+nan%; +nan%]
  • ignore execution_time [-52.155µs; -41.715µs] or [-3.583%; -2.866%]
  • ignore throughput [+20.494op/s; +25.661op/s] or [+2.983%; +3.735%]

scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice netcoreapp3.1

  • ignore allocated_mem [+0 bytes; +0 bytes] or [+nan%; +nan%]
  • ignore execution_time [-136.058µs; -73.572µs] or [-4.733%; -2.559%]
  • ignore throughput [+8.515op/s; +21.598op/s] or [+2.448%; +6.208%]

scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net472

  • ignore allocated_mem [+0 bytes; +0 bytes] or [+nan%; +nan%]
  • ignore execution_time [-12.216µs; -3.597µs] or [-1.055%; -0.311%]
  • ignore throughput [+3.020op/s; +9.384op/s] or [+0.350%; +1.086%]

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

  • ignore allocated_mem [+0 bytes; +0 bytes] or [+nan%; +nan%]
  • ignore execution_time [-40.403µs; -13.002µs] or [-3.747%; -1.206%]
  • ignore throughput [+14.357op/s; +41.542op/s] or [+1.548%; +4.479%]

scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool netcoreapp3.1

  • ignore allocated_mem [+0 bytes; +0 bytes] or [+nan%; +nan%]
  • 🟥 execution_time [+107.578µs; +132.459µs] or [+5.763%; +7.096%]
  • 🟥 throughput [-35.063op/s; -28.753op/s] or [-6.545%; -5.367%]

scenario:Benchmarks.Trace.CharSliceBenchmark.OriginalCharSlice net472

  • ignore allocated_mem [-43 bytes; +21 bytes] or [-0.007%; +0.003%]
  • ignore execution_time [+41.800µs; +57.636µs] or [+1.633%; +2.251%]
  • ignore throughput [-8.514op/s; -6.195op/s] or [-2.180%; -1.586%]

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

  • ignore allocated_mem [-38 bytes; +46 bytes] or [-0.006%; +0.007%]
  • 🟩 execution_time [-191.324µs; -152.142µs] or [-9.692%; -7.707%]
  • 🟩 throughput [+44.390op/s; +55.130op/s] or [+8.763%; +10.883%]

scenario:Benchmarks.Trace.CharSliceBenchmark.OriginalCharSlice netcoreapp3.1

  • ignore allocated_mem [-42 bytes; +23 bytes] or [-0.007%; +0.004%]
  • ignore execution_time [-341.203µs; -153.107µs] or [-8.653%; -3.883%]
  • 🟩 throughput [+12.767op/s; +36.757op/s] or [+5.035%; +14.494%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch net472

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.001%; +0.008%]
  • 🟥 execution_time [+303.312ms; +304.423ms] or [+152.742%; +153.301%]
  • ignore throughput [+4015.676op/s; +5798.447op/s] or [+1.292%; +1.866%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch net6.0

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.006%; +0.004%]
  • 🟥 execution_time [+301.900ms; +311.522ms] or [+151.283%; +156.104%]
  • ignore throughput [+19645.442op/s; +29255.925op/s] or [+3.097%; +4.612%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch netcoreapp3.1

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.006%; +0.004%]
  • 🟥 execution_time [+301.799ms; +305.124ms] or [+151.611%; +153.281%]
  • ignore throughput [+14303.433op/s; +21902.759op/s] or [+3.013%; +4.614%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync net472

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.008%; +0.004%]
  • 🟥 execution_time [+303.041ms; +305.795ms] or [+152.177%; +153.560%]
  • ignore throughput [+10258.951op/s; +12185.147op/s] or [+3.437%; +4.082%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync net6.0

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.007%; +0.006%]
  • 🟥 execution_time [+299.531ms; +301.661ms] or [+148.105%; +149.158%]
  • ignore throughput [-4769.733op/s; +1868.694op/s] or [-0.768%; +0.301%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync netcoreapp3.1

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.006%; +0.004%]
  • 🟥 execution_time [+303.078ms; +306.660ms] or [+153.613%; +155.429%]
  • ignore throughput [-4405.784op/s; +3759.941op/s] or [-0.951%; +0.812%]

scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync net472

  • ignore allocated_mem [+0 bytes; +1 bytes] or [+0.108%; +0.119%]
  • 🟥 execution_time [+300.881ms; +302.677ms] or [+151.015%; +151.917%]
  • ignore throughput [-10012.604op/s; -5098.939op/s] or [-2.598%; -1.323%]

scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync net6.0

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.006%; +0.006%]
  • 🟥 execution_time [+300.730ms; +313.847ms] or [+149.887%; +156.424%]
  • 🟩 throughput [+52013.398op/s; +63003.418op/s] or [+10.328%; +12.510%]

scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync netcoreapp3.1

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.006%; +0.006%]
  • 🟥 execution_time [+301.046ms; +305.743ms] or [+149.768%; +152.104%]
  • ignore throughput [-11806.030op/s; -5328.344op/s] or [-2.795%; -1.261%]

scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog net472

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.003%; +0.006%]
  • ignore execution_time [-665.873µs; +194.939µs] or [-0.331%; +0.097%]
  • ignore throughput [-8554.185op/s; -7386.550op/s] or [-3.440%; -2.970%]

scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog net6.0

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.005%; +0.003%]
  • 🟩 execution_time [-16.102ms; -12.463ms] or [-7.487%; -5.795%]
  • 🟩 throughput [+22990.497op/s; +29638.169op/s] or [+6.307%; +8.131%]

scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog netcoreapp3.1

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.004%; +0.008%]
  • ignore execution_time [-0.865ms; +3.056ms] or [-0.434%; +1.533%]
  • ignore throughput [+6330.076op/s; +12134.985op/s] or [+2.311%; +4.430%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark net472

  • ignore allocated_mem [-4.459KB; -4.431KB] or [-1.623%; -1.613%]
  • unstable execution_time [+10.868µs; +52.550µs] or [+2.685%; +12.980%]
  • ignore throughput [-269.162op/s; -61.209op/s] or [-10.831%; -2.463%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark net6.0

  • 🟩 allocated_mem [-20.469KB; -20.449KB] or [-7.467%; -7.459%]
  • unstable execution_time [-41.390µs; +11.546µs] or [-8.180%; +2.282%]
  • ignore throughput [-32.331op/s; +152.309op/s] or [-1.613%; +7.600%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark netcoreapp3.1

  • ignore allocated_mem [+780 bytes; +797 bytes] or [+0.285%; +0.291%]
  • ignore execution_time [-49.339µs; +6.632µs] or [-8.550%; +1.149%]
  • ignore throughput [-10.085op/s; +141.565op/s] or [-0.576%; +8.088%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark net472

  • ignore allocated_mem [-2 bytes; +2 bytes] or [-0.005%; +0.006%]
  • ignore execution_time [+0.488µs; +1.957µs] or [+0.845%; +3.390%]
  • ignore throughput [-551.594op/s; -139.047op/s] or [-3.183%; -0.802%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark net6.0

  • ignore allocated_mem [-4 bytes; +0 bytes] or [-0.010%; -0.001%]
  • unstable execution_time [+7.691µs; +12.259µs] or [+18.180%; +28.977%]
  • 🟥 throughput [-5227.856op/s; -3390.309op/s] or [-22.008%; -14.272%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark netcoreapp3.1

  • ignore allocated_mem [-1 bytes; +1 bytes] or [-0.002%; +0.002%]
  • unstable execution_time [-13.408µs; -6.174µs] or [-20.802%; -9.579%]
  • 🟩 throughput [+1549.399op/s; +3067.983op/s] or [+9.506%; +18.823%]

scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog net472

  • ignore allocated_mem [+3 bytes; +4 bytes] or [+0.084%; +0.094%]
  • 🟥 execution_time [+302.198ms; +303.840ms] or [+152.748%; +153.578%]
  • ignore throughput [-99.027op/s; -75.824op/s] or [-1.655%; -1.267%]

scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog net6.0

  • ignore allocated_mem [+0 bytes; +1 bytes] or [+0.017%; +0.027%]
  • 🟥 execution_time [+301.806ms; +304.008ms] or [+153.618%; +154.739%]
  • ignore throughput [-90.449op/s; -14.726op/s] or [-1.122%; -0.183%]

scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog netcoreapp3.1

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.005%; +0.005%]
  • 🟥 execution_time [+300.373ms; +302.754ms] or [+150.374%; +151.566%]
  • ignore throughput [-120.044op/s; -54.202op/s] or [-1.529%; -0.690%]

scenario:Benchmarks.Trace.RedisBenchmark.SendReceive net472

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.005%; +0.005%]
  • ignore execution_time [-489.465µs; +377.865µs] or [-0.244%; +0.188%]
  • ignore throughput [-12687.247op/s; -9246.150op/s] or [-3.512%; -2.560%]

scenario:Benchmarks.Trace.RedisBenchmark.SendReceive net6.0

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.004%; +0.007%]
  • ignore execution_time [-258.630µs; +414.122µs] or [-0.129%; +0.207%]
  • 🟩 throughput [+45611.138op/s; +48142.565op/s] or [+8.633%; +9.112%]

scenario:Benchmarks.Trace.RedisBenchmark.SendReceive netcoreapp3.1

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.004%; +0.006%]
  • ignore execution_time [+1.922ms; +5.578ms] or [+0.974%; +2.827%]
  • ignore throughput [+3023.594op/s; +11562.703op/s] or [+0.716%; +2.737%]

scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog net472

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.005%; +0.006%]
  • 🟥 execution_time [+301.462ms; +303.200ms] or [+150.252%; +151.118%]
  • ignore throughput [-1925.332op/s; -896.149op/s] or [-1.271%; -0.592%]

scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog net6.0

  • ignore allocated_mem [+0 bytes; +0 bytes] or [+0.000%; +0.009%]
  • 🟥 execution_time [+299.292ms; +305.330ms] or [+150.290%; +153.322%]
  • ignore throughput [+3635.592op/s; +6673.402op/s] or [+1.581%; +2.902%]

scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog netcoreapp3.1

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.004%; +0.003%]
  • 🟥 execution_time [+302.419ms; +304.571ms] or [+153.367%; +154.459%]
  • ignore throughput [+3692.027op/s; +5743.013op/s] or [+2.079%; +3.235%]

scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore net472

  • ignore allocated_mem [+0 bytes; +0 bytes] or [+nan%; +nan%]
  • 🟥 execution_time [+299.212ms; +299.766ms] or [+149.248%; +149.525%]
  • 🟩 throughput [+61214024.242op/s; +61461878.814op/s] or [+44.580%; +44.760%]

scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore net6.0

  • ignore allocated_mem [+70 bytes; +72 bytes] or [+0.410%; +0.420%]
  • 🟥 execution_time [+426.140ms; +429.794ms] or [+529.981%; +534.525%]
  • 🟩 throughput [+933.236op/s; +1104.579op/s] or [+7.214%; +8.539%]

scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore netcoreapp3.1

  • ignore allocated_mem [+0 bytes; +0 bytes] or [+nan%; +nan%]
  • 🟥 execution_time [+299.560ms; +300.460ms] or [+149.413%; +149.863%]
  • ignore throughput [-1164497.975op/s; +1304234.354op/s] or [-0.516%; +0.578%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope net472

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.005%; +0.006%]
  • ignore execution_time [+195.987µs; +546.412µs] or [+0.098%; +0.273%]
  • ignore throughput [-1549.675op/s; +1345.107op/s] or [-0.173%; +0.150%]

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

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.005%; +0.007%]
  • ignore execution_time [-4.596ms; -3.497ms] or [-2.251%; -1.713%]
  • 🟩 throughput [+93416.404op/s; +101276.865op/s] or [+8.722%; +9.456%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope netcoreapp3.1

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.003%; +0.006%]
  • ignore execution_time [+0.579ms; +4.710ms] or [+0.293%; +2.383%]
  • 🟩 throughput [+56180.591op/s; +75658.891op/s] or [+6.503%; +8.757%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishSpan net472

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.000%; +0.009%]
  • ignore execution_time [+0.800ms; +1.464ms] or [+0.400%; +0.732%]
  • ignore throughput [-11629.508op/s; -8488.525op/s] or [-1.065%; -0.777%]

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

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.004%; +0.004%]
  • ignore execution_time [+6.041ms; +10.146ms] or [+3.147%; +5.286%]
  • 🟩 throughput [+69581.215op/s; +99919.533op/s] or [+5.386%; +7.734%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishSpan netcoreapp3.1

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.001%; +0.008%]
  • ignore execution_time [-5.374ms; -3.878ms] or [-2.640%; -1.905%]
  • 🟩 throughput [+100614.852op/s; +109355.562op/s] or [+9.993%; +10.861%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes net472

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.008%; +0.002%]
  • ignore execution_time [-1318.065µs; -76.524µs] or [-0.656%; -0.038%]
  • ignore throughput [+14163.333op/s; +17126.409op/s] or [+3.156%; +3.816%]

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

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.004%; +0.009%]
  • ignore execution_time [-596.497µs; +1094.992µs] or [-0.298%; +0.547%]
  • 🟩 throughput [+56308.820op/s; +61104.946op/s] or [+10.225%; +11.096%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes netcoreapp3.1

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.006%; +0.004%]
  • ignore execution_time [+0.119ms; +4.191ms] or [+0.060%; +2.106%]
  • 🟩 throughput [+22947.010op/s; +32764.111op/s] or [+5.136%; +7.334%]

scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin net472

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.005%; +0.006%]
  • ignore execution_time [-1006.190µs; -85.907µs] or [-0.501%; -0.043%]
  • ignore throughput [-17590.943op/s; -14334.447op/s] or [-2.575%; -2.098%]

scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin net6.0

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.005%; +0.007%]
  • ignore execution_time [-1085.418µs; +2408.265µs] or [-0.543%; +1.205%]
  • 🟩 throughput [+59878.233op/s; +77517.440op/s] or [+6.690%; +8.661%]

scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin netcoreapp3.1

  • ignore allocated_mem [+0 bytes; +0 bytes] or [-0.005%; +0.005%]
  • ignore execution_time [+1.381ms; +5.264ms] or [+0.701%; +2.674%]
  • ignore throughput [+29961.094op/s; +44585.860op/s] or [+4.183%; +6.225%]

@bouwkast

bouwkast commented Apr 8, 2026

Copy link
Copy Markdown
Collaborator Author

Closing this as I just thought it would be easier to share this as a PR form than not, if this is valuable can always pick it back up but we don't know if this actually solves anything.

@bouwkast bouwkast closed this Apr 8, 2026
@bouwkast bouwkast reopened this Apr 9, 2026
@dd-trace-dotnet-ci-bot

dd-trace-dotnet-ci-bot Bot commented Apr 9, 2026

Copy link
Copy Markdown

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing This PR (8428) 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
duration72.88 ± (72.85 - 73.33) ms75.11 ± (74.69 - 75.33) ms+3.1%✅⬆️
.NET Framework 4.8 - Bailout
duration79.54 ± (79.19 - 79.81) ms77.91 ± (77.80 - 78.33) ms-2.1%
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1076.07 ± (1076.67 - 1086.20) ms1079.30 ± (1080.40 - 1088.47) ms+0.3%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms22.71 ± (22.65 - 22.77) ms22.69 ± (22.62 - 22.76) ms-0.1%
process.time_to_main_ms86.27 ± (85.90 - 86.65) ms85.98 ± (85.63 - 86.33) ms-0.3%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.85 ± (10.84 - 10.85) MB10.91 ± (10.90 - 10.91) MB+0.5%✅⬆️
runtime.dotnet.threads.count12 ± (12 - 12)12 ± (12 - 12)+0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms22.65 ± (22.59 - 22.70) ms22.25 ± (22.21 - 22.28) ms-1.8%
process.time_to_main_ms87.47 ± (87.20 - 87.75) ms85.40 ± (85.20 - 85.60) ms-2.4%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.94 ± (10.94 - 10.94) MB10.94 ± (10.93 - 10.94) MB-0.0%
runtime.dotnet.threads.count13 ± (13 - 13)13 ± (13 - 13)+0.0%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms229.72 ± (228.67 - 230.77) ms230.83 ± (229.65 - 232.02) ms+0.5%✅⬆️
process.time_to_main_ms530.04 ± (528.66 - 531.41) ms532.18 ± (530.43 - 533.94) ms+0.4%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.60 ± (48.58 - 48.63) MB48.40 ± (48.36 - 48.43) MB-0.4%
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.0%
.NET 6 - Baseline
process.internal_duration_ms21.46 ± (21.40 - 21.51) ms21.17 ± (21.12 - 21.21) ms-1.4%
process.time_to_main_ms74.55 ± (74.27 - 74.84) ms72.97 ± (72.76 - 73.19) ms-2.1%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.61 ± (10.61 - 10.61) MB10.61 ± (10.61 - 10.61) MB+0.0%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 6 - Bailout
process.internal_duration_ms21.49 ± (21.43 - 21.55) ms21.08 ± (21.04 - 21.12) ms-1.9%
process.time_to_main_ms76.71 ± (76.46 - 76.96) ms74.20 ± (74.01 - 74.38) ms-3.3%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.72 ± (10.72 - 10.72) MB10.73 ± (10.73 - 10.74) MB+0.1%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms384.41 ± (382.38 - 386.44) ms384.75 ± (382.90 - 386.61) ms+0.1%✅⬆️
process.time_to_main_ms526.18 ± (524.90 - 527.47) ms534.41 ± (532.96 - 535.87) ms+1.6%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed49.84 ± (49.81 - 49.87) MB50.05 ± (50.02 - 50.08) MB+0.4%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)-0.0%
.NET 8 - Baseline
process.internal_duration_ms19.69 ± (19.64 - 19.75) ms19.90 ± (19.84 - 19.96) ms+1.1%✅⬆️
process.time_to_main_ms74.17 ± (73.91 - 74.44) ms75.33 ± (75.00 - 75.66) ms+1.6%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.66 ± (7.66 - 7.67) MB7.66 ± (7.65 - 7.66) MB-0.1%
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 8 - Bailout
process.internal_duration_ms19.42 ± (19.38 - 19.46) ms19.61 ± (19.57 - 19.64) ms+0.9%✅⬆️
process.time_to_main_ms73.78 ± (73.59 - 73.96) ms74.38 ± (74.19 - 74.57) ms+0.8%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.71 ± (7.70 - 7.71) MB7.71 ± (7.71 - 7.71) MB+0.1%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms304.69 ± (302.00 - 307.38) ms302.26 ± (299.91 - 304.61) ms-0.8%
process.time_to_main_ms491.01 ± (489.76 - 492.27) ms491.85 ± (490.55 - 493.14) ms+0.2%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed37.01 ± (36.99 - 37.04) MB36.98 ± (36.96 - 37.01) MB-0.1%
runtime.dotnet.threads.count27 ± (27 - 27)27 ± (27 - 27)+0.2%✅⬆️

HttpMessageHandler

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration206.46 ± (206.42 - 207.34) ms210.19 ± (210.02 - 210.95) ms+1.8%✅⬆️
.NET Framework 4.8 - Bailout
duration211.26 ± (210.93 - 211.74) ms214.65 ± (214.30 - 215.12) ms+1.6%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1210.98 ± (1211.30 - 1218.83) ms1223.87 ± (1222.41 - 1229.06) ms+1.1%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms201.27 ± (200.86 - 201.68) ms204.13 ± (203.71 - 204.54) ms+1.4%✅⬆️
process.time_to_main_ms88.36 ± (88.05 - 88.67) ms89.88 ± (89.58 - 90.19) ms+1.7%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.01 ± (15.99 - 16.03) MB15.88 ± (15.87 - 15.90) MB-0.8%
runtime.dotnet.threads.count20 ± (20 - 20)20 ± (20 - 20)+0.5%✅⬆️
.NET Core 3.1 - Bailout
process.internal_duration_ms200.21 ± (199.81 - 200.61) ms203.87 ± (203.41 - 204.33) ms+1.8%✅⬆️
process.time_to_main_ms88.80 ± (88.58 - 89.02) ms90.99 ± (90.74 - 91.23) ms+2.5%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.07 ± (16.05 - 16.10) MB15.96 ± (15.93 - 15.98) MB-0.7%
runtime.dotnet.threads.count21 ± (21 - 21)21 ± (21 - 21)+0.2%✅⬆️
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms414.81 ± (413.61 - 416.00) ms418.66 ± (417.46 - 419.86) ms+0.9%✅⬆️
process.time_to_main_ms546.19 ± (544.99 - 547.38) ms551.96 ± (550.76 - 553.16) ms+1.1%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed59.29 ± (59.24 - 59.34) MB59.40 ± (59.36 - 59.44) MB+0.2%✅⬆️
runtime.dotnet.threads.count30 ± (30 - 30)30 ± (29 - 30)-0.6%
.NET 6 - Baseline
process.internal_duration_ms209.16 ± (208.64 - 209.68) ms211.19 ± (210.79 - 211.58) ms+1.0%✅⬆️
process.time_to_main_ms77.57 ± (77.29 - 77.86) ms79.01 ± (78.74 - 79.28) ms+1.9%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.23 ± (16.21 - 16.26) MB16.18 ± (16.15 - 16.20) MB-0.4%
runtime.dotnet.threads.count19 ± (19 - 19)20 ± (19 - 20)+1.1%✅⬆️
.NET 6 - Bailout
process.internal_duration_ms207.36 ± (206.97 - 207.74) ms209.51 ± (209.16 - 209.85) ms+1.0%✅⬆️
process.time_to_main_ms78.16 ± (77.91 - 78.41) ms79.34 ± (79.15 - 79.53) ms+1.5%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.29 ± (16.26 - 16.31) MB16.21 ± (16.18 - 16.23) MB-0.5%
runtime.dotnet.threads.count20 ± (20 - 20)21 ± (21 - 21)+1.9%✅⬆️
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms599.37 ± (596.24 - 602.49) ms601.44 ± (598.90 - 603.99) ms+0.3%✅⬆️
process.time_to_main_ms543.77 ± (542.61 - 544.93) ms549.65 ± (548.47 - 550.83) ms+1.1%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed61.56 ± (61.45 - 61.67) MB61.77 ± (61.68 - 61.86) MB+0.3%✅⬆️
runtime.dotnet.threads.count31 ± (31 - 31)31 ± (31 - 31)+0.2%✅⬆️
.NET 8 - Baseline
process.internal_duration_ms205.50 ± (205.05 - 205.96) ms208.69 ± (208.21 - 209.16) ms+1.5%✅⬆️
process.time_to_main_ms76.17 ± (75.94 - 76.40) ms77.64 ± (77.39 - 77.90) ms+1.9%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.58 ± (11.55 - 11.60) MB11.57 ± (11.55 - 11.59) MB-0.0%
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)+0.4%✅⬆️
.NET 8 - Bailout
process.internal_duration_ms204.87 ± (204.47 - 205.28) ms207.61 ± (207.23 - 207.99) ms+1.3%✅⬆️
process.time_to_main_ms77.17 ± (76.96 - 77.38) ms78.64 ± (78.44 - 78.83) ms+1.9%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.66 ± (11.64 - 11.68) MB11.66 ± (11.65 - 11.68) MB+0.0%✅⬆️
runtime.dotnet.threads.count20 ± (20 - 20)20 ± (20 - 20)-0.4%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms527.95 ± (523.07 - 532.84) ms534.82 ± (528.33 - 541.31) ms+1.3%✅⬆️
process.time_to_main_ms509.63 ± (508.64 - 510.63) ms512.55 ± (511.66 - 513.44) ms+0.6%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed50.69 ± (50.63 - 50.75) MB50.80 ± (50.73 - 50.87) MB+0.2%✅⬆️
runtime.dotnet.threads.count30 ± (30 - 30)30 ± (30 - 30)+0.1%✅⬆️
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 (8428) - mean (75ms)  : 70, 80
    master - mean (73ms)  : 70, 77

    section Bailout
    This PR (8428) - mean (78ms)  : 74, 82
    master - mean (80ms)  : 75, 84

    section CallTarget+Inlining+NGEN
    This PR (8428) - mean (1,084ms)  : 1027, 1142
    master - mean (1,081ms)  : 1009, 1154

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 (8428) - mean (116ms)  : 109, 123
    master - mean (116ms)  : 110, 122

    section Bailout
    This PR (8428) - mean (114ms)  : 111, 118
    master - mean (117ms)  : 111, 123

    section CallTarget+Inlining+NGEN
    This PR (8428) - mean (798ms)  : 776, 820
    master - mean (798ms)  : 771, 824

Loading
FakeDbCommand (.NET 6)
gantt
    title Execution time (ms) FakeDbCommand (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8428) - mean (101ms)  : 95, 106
    master - mean (103ms)  : 97, 109

    section Bailout
    This PR (8428) - mean (101ms)  : 99, 104
    master - mean (105ms)  : 100, 110

    section CallTarget+Inlining+NGEN
    This PR (8428) - mean (947ms)  : 916, 979
    master - mean (940ms)  : 907, 972

Loading
FakeDbCommand (.NET 8)
gantt
    title Execution time (ms) FakeDbCommand (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8428) - mean (103ms)  : 97, 109
    master - mean (102ms)  : 96, 108

    section Bailout
    This PR (8428) - mean (102ms)  : 99, 104
    master - mean (101ms)  : 99, 103

    section CallTarget+Inlining+NGEN
    This PR (8428) - mean (826ms)  : 786, 865
    master - mean (827ms)  : 782, 872

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 (8428) - mean (210ms)  : 206, 215
    master - mean (207ms)  : 202, 212

    section Bailout
    This PR (8428) - mean (215ms)  : 211, 219
    master - mean (211ms)  : 207, 215

    section CallTarget+Inlining+NGEN
    This PR (8428) - mean (1,226ms)  : 1176, 1275
    master - mean (1,215ms)  : 1159, 1271

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 (8428) - mean (304ms)  : 297, 311
    master - mean (299ms)  : 292, 306

    section Bailout
    This PR (8428) - mean (304ms)  : 297, 311
    master - mean (298ms)  : 291, 305

    section CallTarget+Inlining+NGEN
    This PR (8428) - mean (1,012ms)  : 980, 1044
    master - mean (998ms)  : 960, 1035

Loading
HttpMessageHandler (.NET 6)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8428) - mean (299ms)  : 293, 305
    master - mean (296ms)  : 288, 304

    section Bailout
    This PR (8428) - mean (298ms)  : 293, 302
    master - mean (294ms)  : 287, 301

    section CallTarget+Inlining+NGEN
    This PR (8428) - mean (1,182ms)  : 1146, 1217
    master - mean (1,175ms)  : 1140, 1210

Loading
HttpMessageHandler (.NET 8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8428) - mean (297ms)  : 289, 305
    master - mean (292ms)  : 286, 299

    section Bailout
    This PR (8428) - mean (297ms)  : 292, 301
    master - mean (293ms)  : 288, 298

    section CallTarget+Inlining+NGEN
    This PR (8428) - mean (1,084ms)  : 990, 1177
    master - mean (1,073ms)  : 992, 1154

Loading

@anna-git anna-git added area:native-library Automatic instrumentation native C++ code (Datadog.Trace.ClrProfiler.Native) labels Apr 10, 2026
anna-git added a commit that referenced this pull request Apr 10, 2026
## Summary of changes

This reproduces the crash [described in this
README](https://github.com/DataDog/dd-trace-dotnet/blob/82cc4cf0e29478fd2fdc41afdf764a2abf662199/repro/APMS-19196/README.md)
on linux x64 arch.

Aim is to merge to #8428
First tested it's crashing on master 
<img width="2830" height="851" alt="image"
src="https://github.com/user-attachments/assets/96e882fa-308e-44b6-8116-c93c7d5b7bb2"
/>


## Reason for change

## Implementation details

## Test coverage

## Other details
<!-- Fixes #{issue} -->


<!--  ⚠️ Note:

Where possible, please obtain 2 approvals prior to merging. Unless
CODEOWNERS specifies otherwise, for external teams it is typically best
to have one review from a team member, and one review from apm-dotnet.
Trivial changes do not require 2 reviews.

MergeQueue is NOT enabled in this repository. If you have write access
to the repo, the PR has 1-2 approvals (see above), and all of the
required checks have passed, you can use the Squash and Merge button to
merge the PR. If you don't have write access, or you need help, reach
out in the #apm-dotnet channel in Slack.
-->
@github-actions

github-actions Bot commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Snapshots difference summary

The following differences have been observed in committed snapshots. It is meant to help the reviewer.
The diff is simplistic, so please check some files anyway while we improve it.

3 occurrences of :

+  },
+  {
+    TraceId: Id_1,
+    SpanId: Id_62,
+    Name: trace.annotation,
+    Resource: ExtremeExceptionHandling.DeepNestedExceptionHandlingSync,
+    Service: Samples.TraceAnnotations,
+    ParentId: Id_2,
+    Tags: {
+      component: trace,
+      env: integration_tests,
+      language: dotnet,
+      version: 1.0.0
+    }
+  },
+  {
+    TraceId: Id_1,
+    SpanId: Id_63,
+    Name: trace.annotation,
+    Resource: ExtremeExceptionHandling.SameTryMultipleCatch,
+    Service: Samples.TraceAnnotations,
+    ParentId: Id_2,
+    Tags: {
+      component: trace,
+      env: integration_tests,
+      language: dotnet,
+      version: 1.0.0
+    }
+  },
+  {
+    TraceId: Id_1,
+    SpanId: Id_64,
+    Name: trace.annotation,
+    Resource: ExtremeExceptionHandling.SameTryMultipleCatch,
+    Service: Samples.TraceAnnotations,
+    ParentId: Id_2,
+    Tags: {
+      component: trace,
+      env: integration_tests,
+      language: dotnet,
+      version: 1.0.0
+    }
+  },
+  {
+    TraceId: Id_1,
+    SpanId: Id_65,
+    Name: trace.annotation,
+    Resource: ExtremeExceptionHandling.SameTryMultipleCatch,
+    Service: Samples.TraceAnnotations,
+    ParentId: Id_2,
+    Tags: {
+      component: trace,
+      env: integration_tests,
+      language: dotnet,
+      version: 1.0.0
+    }
+  },
+  {
+    TraceId: Id_1,
+    SpanId: Id_66,
+    Name: trace.annotation,
+    Resource: ExtremeExceptionHandling.FilterAndTypedCatch,
+    Service: Samples.TraceAnnotations,
+    ParentId: Id_2,
+    Tags: {
+      component: trace,
+      env: integration_tests,
+      language: dotnet,
+      version: 1.0.0
+    }
+  },
+  {
+    TraceId: Id_1,
+    SpanId: Id_67,
+    Name: trace.annotation,
+    Resource: ExtremeExceptionHandling.FilterAndTypedCatch,
+    Service: Samples.TraceAnnotations,
+    ParentId: Id_2,
+    Tags: {
+      component: trace,
+      env: integration_tests,
+      language: dotnet,
+      version: 1.0.0
+    }
+  },
+  {
+    TraceId: Id_1,
+    SpanId: Id_68,
+    Name: trace.annotation,
+    Resource: ExtremeExceptionHandling.FilterAndTypedCatch,
+    Service: Samples.TraceAnnotations,
+    ParentId: Id_2,
+    Tags: {
+      component: trace,
+      env: integration_tests,
+      language: dotnet,
+      version: 1.0.0
+    }

3 occurrences of :

+  },
+  {
+    TraceId: Id_1,
+    SpanId: Id_62,
+    Name: trace.annotation,
+    Resource: ExtremeExceptionHandling.DeepNestedExceptionHandlingSync,
+    Service: Samples.TraceAnnotations.VersionMismatch.AfterFeature,
+    ParentId: Id_2,
+    Tags: {
+      component: trace,
+      env: integration_tests,
+      language: dotnet,
+      version: 1.0.0
+    }
+  },
+  {
+    TraceId: Id_1,
+    SpanId: Id_63,
+    Name: trace.annotation,
+    Resource: ExtremeExceptionHandling.SameTryMultipleCatch,
+    Service: Samples.TraceAnnotations.VersionMismatch.AfterFeature,
+    ParentId: Id_2,
+    Tags: {
+      component: trace,
+      env: integration_tests,
+      language: dotnet,
+      version: 1.0.0
+    }
+  },
+  {
+    TraceId: Id_1,
+    SpanId: Id_64,
+    Name: trace.annotation,
+    Resource: ExtremeExceptionHandling.SameTryMultipleCatch,
+    Service: Samples.TraceAnnotations.VersionMismatch.AfterFeature,
+    ParentId: Id_2,
+    Tags: {
+      component: trace,
+      env: integration_tests,
+      language: dotnet,
+      version: 1.0.0
+    }
+  },
+  {
+    TraceId: Id_1,
+    SpanId: Id_65,
+    Name: trace.annotation,
+    Resource: ExtremeExceptionHandling.SameTryMultipleCatch,
+    Service: Samples.TraceAnnotations.VersionMismatch.AfterFeature,
+    ParentId: Id_2,
+    Tags: {
+      component: trace,
+      env: integration_tests,
+      language: dotnet,
+      version: 1.0.0
+    }
+  },
+  {
+    TraceId: Id_1,
+    SpanId: Id_66,
+    Name: trace.annotation,
+    Resource: ExtremeExceptionHandling.FilterAndTypedCatch,
+    Service: Samples.TraceAnnotations.VersionMismatch.AfterFeature,
+    ParentId: Id_2,
+    Tags: {
+      component: trace,
+      env: integration_tests,
+      language: dotnet,
+      version: 1.0.0
+    }
+  },
+  {
+    TraceId: Id_1,
+    SpanId: Id_67,
+    Name: trace.annotation,
+    Resource: ExtremeExceptionHandling.FilterAndTypedCatch,
+    Service: Samples.TraceAnnotations.VersionMismatch.AfterFeature,
+    ParentId: Id_2,
+    Tags: {
+      component: trace,
+      env: integration_tests,
+      language: dotnet,
+      version: 1.0.0
+    }
+  },
+  {
+    TraceId: Id_1,
+    SpanId: Id_68,
+    Name: trace.annotation,
+    Resource: ExtremeExceptionHandling.FilterAndTypedCatch,
+    Service: Samples.TraceAnnotations.VersionMismatch.AfterFeature,
+    ParentId: Id_2,
+    Tags: {
+      component: trace,
+      env: integration_tests,
+      language: dotnet,
+      version: 1.0.0
+    }

3 occurrences of :

+  },
+  {
+    TraceId: Id_1,
+    SpanId: Id_62,
+    Name: trace.annotation,
+    Resource: ExtremeExceptionHandling.DeepNestedExceptionHandlingSync,
+    Service: Samples.TraceAnnotations.VersionMismatch.BeforeFeature,
+    ParentId: Id_2,
+    Tags: {
+      component: trace,
+      env: integration_tests,
+      language: dotnet,
+      version: 1.0.0
+    }
+  },
+  {
+    TraceId: Id_1,
+    SpanId: Id_63,
+    Name: trace.annotation,
+    Resource: ExtremeExceptionHandling.SameTryMultipleCatch,
+    Service: Samples.TraceAnnotations.VersionMismatch.BeforeFeature,
+    ParentId: Id_2,
+    Tags: {
+      component: trace,
+      env: integration_tests,
+      language: dotnet,
+      version: 1.0.0
+    }
+  },
+  {
+    TraceId: Id_1,
+    SpanId: Id_64,
+    Name: trace.annotation,
+    Resource: ExtremeExceptionHandling.SameTryMultipleCatch,
+    Service: Samples.TraceAnnotations.VersionMismatch.BeforeFeature,
+    ParentId: Id_2,
+    Tags: {
+      component: trace,
+      env: integration_tests,
+      language: dotnet,
+      version: 1.0.0
+    }
+  },
+  {
+    TraceId: Id_1,
+    SpanId: Id_65,
+    Name: trace.annotation,
+    Resource: ExtremeExceptionHandling.SameTryMultipleCatch,
+    Service: Samples.TraceAnnotations.VersionMismatch.BeforeFeature,
+    ParentId: Id_2,
+    Tags: {
+      component: trace,
+      env: integration_tests,
+      language: dotnet,
+      version: 1.0.0
+    }
+  },
+  {
+    TraceId: Id_1,
+    SpanId: Id_66,
+    Name: trace.annotation,
+    Resource: ExtremeExceptionHandling.FilterAndTypedCatch,
+    Service: Samples.TraceAnnotations.VersionMismatch.BeforeFeature,
+    ParentId: Id_2,
+    Tags: {
+      component: trace,
+      env: integration_tests,
+      language: dotnet,
+      version: 1.0.0
+    }
+  },
+  {
+    TraceId: Id_1,
+    SpanId: Id_67,
+    Name: trace.annotation,
+    Resource: ExtremeExceptionHandling.FilterAndTypedCatch,
+    Service: Samples.TraceAnnotations.VersionMismatch.BeforeFeature,
+    ParentId: Id_2,
+    Tags: {
+      component: trace,
+      env: integration_tests,
+      language: dotnet,
+      version: 1.0.0
+    }
+  },
+  {
+    TraceId: Id_1,
+    SpanId: Id_68,
+    Name: trace.annotation,
+    Resource: ExtremeExceptionHandling.FilterAndTypedCatch,
+    Service: Samples.TraceAnnotations.VersionMismatch.BeforeFeature,
+    ParentId: Id_2,
+    Tags: {
+      component: trace,
+      env: integration_tests,
+      language: dotnet,
+      version: 1.0.0
+    }

@bouwkast bouwkast added the AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos label Apr 10, 2026
@bouwkast
bouwkast marked this pull request as ready for review April 13, 2026 14:59
@bouwkast
bouwkast requested review from a team as code owners April 13, 2026 14:59
@bouwkast
bouwkast requested a review from link04 April 13, 2026 14:59

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

Copy link
Copy Markdown

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: 6b6b9a4b4b

ℹ️ 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 thread tracer/test/Datadog.Tracer.Native.Tests/il_rewriter_eh_sort_test.cpp Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes EH clause ordering in ILRewriter::Export() to correctly handle clauses whose try region is nested inside another clause’s handler region, preventing CLR InvalidProgramException during JIT validation (APMS-19196).

Changes:

  • Replaces the previous EH std::sort comparator with ILRewriter::SortEHClauses, sorting by computed nesting depth (try-in-try and try-in-handler) with a strict weak ordering.
  • Adds native unit tests for EH sorting plus a managed “extreme EH” integration scenario to reproduce the crash.
  • Updates integration test expectations/snapshots to account for the additional traced method.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tracer/src/Datadog.Tracer.Native/il_rewriter.cpp Uses new SortEHClauses in Export() and implements depth-based EH sorting.
tracer/src/Datadog.Tracer.Native/il_rewriter.h Declares ILRewriter::SortEHClauses for reuse/unit testing.
tracer/test/Datadog.Tracer.Native.Tests/il_rewriter_eh_sort_test.cpp Adds gtest coverage for try-in-try and try-in-handler ordering, including a repro of the old comparator failure.
tracer/test/Datadog.Tracer.Native.Tests/Datadog.Tracer.Native.Tests.vcxproj Includes the new native test source in the VS project.
tracer/test/Datadog.Tracer.Native.Tests/Datadog.Tracer.Native.Tests.vcxproj.filters Adds the new native test source to filters for VS organization.
tracer/test/Datadog.Tracer.Native.Tests/CMakeLists.txt Includes the new test source in the CMake test target.
tracer/test/test-applications/integrations/Samples.TraceAnnotations/ExtremeExceptionHandling.cs Adds a managed method with deep EH nesting used as a regression repro.
tracer/test/test-applications/integrations/Samples.TraceAnnotations/ProgramHelpers.cs Executes the new extreme EH scenario as part of the sample run.
tracer/test/test-applications/integrations/Samples.TraceAnnotations.VersionMismatch.BeforeFeature/Samples.TraceAnnotations.VersionMismatch.BeforeFeature.csproj Ensures the new managed file is compiled into the version-mismatch sample.
tracer/test/test-applications/integrations/Samples.TraceAnnotations.VersionMismatch.AfterFeature/Samples.TraceAnnotations.VersionMismatch.AfterFeature.csproj Ensures the new managed file is compiled into the version-mismatch sample.
tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/TraceAnnotationsTests.cs Updates expected span count and sets DD_TRACE_METHODS to trace the new sync repro method.
tracer/test/snapshots/TraceAnnotationsAutomaticOnlyTests._.Net.verified.txt Snapshot updated for added span from the extreme EH method.
tracer/test/snapshots/TraceAnnotationsAutomaticOnlyTests._.DotNet.verified.txt Snapshot updated for added span from the extreme EH method.
tracer/test/snapshots/TraceAnnotationsAutomaticOnlyTests._.Core.verified.txt Snapshot updated for added span from the extreme EH method.
tracer/test/snapshots/TraceAnnotationsVersionMismatchAfterFeatureTests._.Net.verified.txt Snapshot updated for added span from the extreme EH method.
tracer/test/snapshots/TraceAnnotationsVersionMismatchAfterFeatureTests._.DotNet.verified.txt Snapshot updated for added span from the extreme EH method.
tracer/test/snapshots/TraceAnnotationsVersionMismatchAfterFeatureTests._.Core.verified.txt Snapshot updated for added span from the extreme EH method.
tracer/test/snapshots/TraceAnnotationsVersionMismatchBeforeFeatureTests._.Net.verified.txt Snapshot updated for added span from the extreme EH method.
tracer/test/snapshots/TraceAnnotationsVersionMismatchBeforeFeatureTests._.DotNet.verified.txt Snapshot updated for added span from the extreme EH method.
tracer/test/snapshots/TraceAnnotationsVersionMismatchBeforeFeatureTests._.Core.verified.txt Snapshot updated for added span from the extreme EH method.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1 to +14
#include "pch.h"

#include "../../src/Datadog.Tracer.Native/il_rewriter.h"

// Helper to build a doubly-linked chain of ILInstr nodes with specified offsets.
// Returns a heap-allocated array; the caller must delete[].
// Each node's m_pNext and m_pPrev are wired up in sequence. The last node's
// m_pNext points to a sentinel (the first node acts as its own sentinel for
// handler-end calculations via m_pHandlerEnd->m_pNext).
static ILInstr* MakeInstrChain(const std::vector<unsigned>& offsets)
{
auto n = offsets.size();
auto* instrs = new ILInstr[n];
memset(instrs, 0, n * sizeof(ILInstr));

Copilot AI Apr 13, 2026

Copy link

Choose a reason for hiding this comment

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

This test file uses std::vector, std::sort, and memset but does not include the corresponding standard headers. With the current pch.h (only gtest + CLR headers), this will not compile on a clean build. Add explicit includes for the headers you use (e.g., , , ).

Copilot uses AI. Check for mistakes.
Comment on lines +5 to +21
// Helper to build a doubly-linked chain of ILInstr nodes with specified offsets.
// Returns a heap-allocated array; the caller must delete[].
// Each node's m_pNext and m_pPrev are wired up in sequence. The last node's
// m_pNext points to a sentinel (the first node acts as its own sentinel for
// handler-end calculations via m_pHandlerEnd->m_pNext).
static ILInstr* MakeInstrChain(const std::vector<unsigned>& offsets)
{
auto n = offsets.size();
auto* instrs = new ILInstr[n];
memset(instrs, 0, n * sizeof(ILInstr));
for (size_t i = 0; i < n; i++)
{
instrs[i].m_offset = offsets[i];
instrs[i].m_pPrev = (i > 0) ? &instrs[i - 1] : &instrs[n - 1];
instrs[i].m_pNext = (i < n - 1) ? &instrs[i + 1] : &instrs[0];
}
return instrs;

Copilot AI Apr 13, 2026

Copy link

Choose a reason for hiding this comment

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

MakeInstrChain builds a circular list (last->next points back to the first node), but the comment describes a sentinel node for handler-end calculations. This can be misleading, and it also doesn’t model ILRewriter’s real list where the last instruction’s m_pNext points to a dedicated sentinel with m_offset == code size (important when a handler ends at the end of the method). Consider either updating the comment to reflect the circular list, or creating an explicit sentinel node in the helper to better match production semantics.

Copilot uses AI. Check for mistakes.

@NachoEchevarria NachoEchevarria left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks!

@anna-git anna-git left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Added a few comments, after trying to wrap my head around it 😅
From what I understand, the new algorithm does:

  1. calculate depth of each exception handling clause
  2. create a blank array the size of the clauses
  3. compare eh clause's depth 2 by 2 and reorder indices according to it
    a. if they have different depths, sort the new indices array according to it, putting the deeper depth first (ecma rule)
    b. if depths are the same, either sort by try begin offset
    c. either the offsets are the same, then just keep the original order

Comment thread tracer/src/Datadog.Tracer.Native/il_rewriter.cpp
Comment thread tracer/src/Datadog.Tracer.Native/il_rewriter.cpp
Comment thread tracer/src/Datadog.Tracer.Native/il_rewriter.cpp
Comment thread tracer/src/Datadog.Tracer.Native/il_rewriter.cpp
Comment thread tracer/test/Datadog.Tracer.Native.Tests/il_rewriter_eh_sort_test.cpp Outdated
#include "pch.h"

#include "../../src/Datadog.Tracer.Native/il_rewriter.h"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot complaining about this:

Suggested change
#include <cstring>
#include <vector>

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think it should be resolved now

Comment on lines +7 to +9
// Each node's m_pNext and m_pPrev are wired up in sequence. The last node's
// m_pNext points to a sentinel (the first node acts as its own sentinel for
// handler-end calculations via m_pHandlerEnd->m_pNext).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Each node's m_pNext and m_pPrev are wired up in sequence. The last node's
// m_pNext points to a sentinel (the first node acts as its own sentinel for
// handler-end calculations via m_pHandlerEnd->m_pNext).
// For simplicity, nodes are linked in a ring (last points to first). This is not production IL layout; it avoids a separate sentinel while keeping every node with a valid successor.
// SortEHClauses uses m_pHandlerEnd->m_pNext->m_offset as the exclusive end of a handler region (same convention as ILRewriter::ImportEH).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added thanks!

@bouwkast
bouwkast force-pushed the steven/attempt-fix-invalid-program-exception branch from 50011b0 to 4a0d151 Compare April 15, 2026 11:40

@andrewlock andrewlock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What I understand of it makes sense 😅 :blindfold:

Comment on lines +866 to +869
unsigned jTryBegin = pEH[j].m_pTryBegin->m_offset;
unsigned jTryEnd = pEH[j].m_pTryEnd->m_offset;
unsigned jHandlerBegin = pEH[j].m_pHandlerBegin->m_offset;
unsigned jHandlerEnd = pEH[j].m_pHandlerEnd->m_pNext->m_offset;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

tiny nit: might be slightly easier to follow by extracting EHClause targetEH = pEH[j]

Comment on lines +46 to +51
// clauses[0]: outer -- try [10,80), handler [80,90)
clauses[0].m_Flags = COR_ILEXCEPTION_CLAUSE_NONE;
clauses[0].m_pTryBegin = FindInstr(instrs, 8, 10);
clauses[0].m_pTryEnd = FindInstr(instrs, 8, 80);
clauses[0].m_pHandlerBegin = FindInstr(instrs, 8, 80);
clauses[0].m_pHandlerEnd = FindInstr(instrs, 8, 85); // last instr in handler

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not gonna lie, I find this completely impenetrable 😅

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

😰

Should I remove these tests? I don't want someone thinking in the future that these were thoughtfully designed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Meh, keep them I guess, I just can't verify them 😅

}

/// <summary>
/// Synchronous method with 9 levels of nested try/catch/finally.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does it really need 9 levels?! 😅 Also, should we try to exercise any of the other cases here, e.g. multiple catch clauses, try-catch inside a catch block etc?

@anna-git anna-git Apr 16, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's very sensitive to levels 😅 In my tests, removing levels would stop the crash, adding complexity with await tasks and nesting wouldn't cause the crash to reappear.. but we could think of having another endpoint with other levels of complexity in other PRs🤔

Originally we had this 🤯 :

var id = Interlocked.Increment(ref _counter);

After many attempts, claude managed to get to a simplified version that would still crash:

If you remove just one level it stops crashing.

I don't know if we want to test the most complex version or the simplified one here. maybe we should take the most complex one

@anna-git anna-git left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you!

@tonyredondo tonyredondo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would an extra test before merging.

Reason:

  • I do not see a concrete bug in the new sorting algorithm.
  • The sorter now explicitly relies on preserving the original order when multiple handlers share the same try.
  • That order is semantically important, because exception dispatch uses the first matching handler.

A minimal test will ensure us that the exception order is preserved inside the same try:

using System;

public static class EhOrderingDemo
{
    public static int SameTryMultipleCatch(Exception ex)
    {
        try
        {
            throw ex;
        }
        catch (ArgumentNullException)
        {
            return 1;
        }
        catch (InvalidOperationException)
        {
            return 2;
        }
        catch (Exception)
        {
            return 3;
        }
    }

    public static void Main()
    {
        Console.WriteLine(SameTryMultipleCatch(new ArgumentNullException()));   // expected: 1
        Console.WriteLine(SameTryMultipleCatch(new InvalidOperationException())); // expected: 2
        Console.WriteLine(SameTryMultipleCatch(new Exception()));               // expected: 3
    }
}

@tonyredondo

Copy link
Copy Markdown
Member

I would an extra test before merging.

Reason:

  • I do not see a concrete bug in the new sorting algorithm.
  • The sorter now explicitly relies on preserving the original order when multiple handlers share the same try.
  • That order is semantically important, because exception dispatch uses the first matching handler.

A minimal test will ensure us that the exception order is preserved inside the same try:

using System;

public static class EhOrderingDemo
{
    public static int SameTryMultipleCatch(Exception ex)
    {
        try
        {
            throw ex;
        }
        catch (ArgumentNullException)
        {
            return 1;
        }
        catch (InvalidOperationException)
        {
            return 2;
        }
        catch (Exception)
        {
            return 3;
        }
    }

    public static void Main()
    {
        Console.WriteLine(SameTryMultipleCatch(new ArgumentNullException()));   // expected: 1
        Console.WriteLine(SameTryMultipleCatch(new InvalidOperationException())); // expected: 2
        Console.WriteLine(SameTryMultipleCatch(new Exception()));               // expected: 3
    }
}

Also maybe we should add an exception filter test case as well

@bouwkast
bouwkast enabled auto-merge (squash) April 16, 2026 20:16
bouwkast and others added 13 commits April 17, 2026 09:07
## Summary of changes

This reproduces the crash [described in this
README](https://github.com/DataDog/dd-trace-dotnet/blob/82cc4cf0e29478fd2fdc41afdf764a2abf662199/repro/APMS-19196/README.md)
on linux x64 arch.

Aim is to merge to #8428
First tested it's crashing on master 
<img width="2830" height="851" alt="image"
src="https://github.com/user-attachments/assets/96e882fa-308e-44b6-8116-c93c7d5b7bb2"
/>


## Reason for change

## Implementation details

## Test coverage

## Other details
<!-- Fixes #{issue} -->


<!--  ⚠️ Note:

Where possible, please obtain 2 approvals prior to merging. Unless
CODEOWNERS specifies otherwise, for external teams it is typically best
to have one review from a team member, and one review from apm-dotnet.
Trivial changes do not require 2 reviews.

MergeQueue is NOT enabled in this repository. If you have write access
to the repo, the PR has 1-2 approvals (see above), and all of the
required checks have passed, you can use the Squash and Merge button to
merge the PR. If you don't have write access, or you need help, reach
out in the #apm-dotnet channel in Slack.
-->
Add original index as final tiebreaker so std::sort does not
reorder catch/filter handlers that share the same try region.
Without this, multiple catch blocks for the same try can be
silently swapped, changing which handler the runtime evaluates
first.
Extract IsProperlyContained helper, use explicit types, add braces
on all control flow, and use named variables in the sort comparator
to match surrounding native code style.
Verify that when multiple catch handlers share the same try region,
the sort preserves the compiler's original order. This matters because
the CLR dispatches to the first matching handler.

Requested by @tonyredondo in PR review.
Verify that filter clauses mixed with typed catches preserve original
order when sharing the same try region. The runtime evaluates filters
sequentially, so reordering would change exception dispatch semantics.

Requested by @tonyredondo in PR comment.
Add end-to-end tests that verify multi-catch and filter clause ordering
is preserved after instrumentation. The methods are instrumented via
DD_TRACE_METHODS and self-validate by asserting each exception type
dispatches to the correct handler.

Covers both Tony's multi-catch scenario and the filter clause scenario.
@bouwkast
bouwkast force-pushed the steven/attempt-fix-invalid-program-exception branch from 20515be to c5713b9 Compare April 17, 2026 13:07
@bouwkast
bouwkast merged commit ecfd2c4 into master Apr 17, 2026
139 checks passed
@bouwkast
bouwkast deleted the steven/attempt-fix-invalid-program-exception branch April 17, 2026 14:48
@github-actions github-actions Bot added this to the vNext-v3 milestone Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos area:native-library Automatic instrumentation native C++ code (Datadog.Trace.ClrProfiler.Native) identified-by:crashtracking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants