Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a native logger for critical failures in the loader (#5929 -> v2) #5939

Merged
merged 1 commit into from
Aug 28, 2024

Conversation

andrewlock
Copy link
Member

Summary of changes

Wrap the call to the managed loader in a try/catch, and use a native logger to log the exception if any.

Reason for change

There's already a try/catch in the managed loader, but in some situations we can fail before even getting there (if jitting the method failed, for instance because of a trimmed runtime). Also, the managed loader logger can fail.

Implementation details

This PR adds a try/catch in the code emitted to load the managed loader. In the catch clause, we call a native logging function, with a direct unmanaged calli call to its address.

Because we have now this outer catch block, I removed the IsInSsi logic which isn't needed anymore.

Other details

Backport of #5929

## Summary of changes

Wrap the call to the managed loader in a try/catch, and use a native
logger to log the exception if any.

## Reason for change

There's already a try/catch in the managed loader, but in some
situations we can fail before even getting there (if jitting the method
failed, for instance because of a trimmed runtime). Also, the managed
loader logger can fail.

## Implementation details

This PR adds a try/catch in the code emitted to load the managed loader.
In the catch clause, we call a native logging function, with a direct
unmanaged `calli` call to its address.

Because we have now this outer catch block, I removed the `IsInSsi`
logic which isn't needed anymore.
@andrewlock andrewlock added the area:native-library Automatic instrumentation native C++ code (Datadog.Trace.ClrProfiler.Native) label Aug 23, 2024
@andrewlock andrewlock requested review from a team as code owners August 23, 2024 15:33
Copy link
Contributor

@daniel-romano-DD daniel-romano-DD left a comment

Choose a reason for hiding this comment

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

👍

@datadog-ddstaging
Copy link

datadog-ddstaging bot commented Aug 23, 2024

Datadog Report

Branch report: kevin/error_loader-v2
Commit report: 068c13e
Test service: dd-trace-dotnet

✅ 0 Failed, 354339 Passed, 2540 Skipped, 24h 12m 11.72s Total Time

@andrewlock
Copy link
Member Author

Execution-Time Benchmarks Report ⏱️

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

Execution-time benchmarks measure the whole time it takes to execute a program. And are intended to measure the one-off costs. Cases where the execution time results for the PR are worse than latest master results are shown in red. The following thresholds were used for comparing the execution times:

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

Note that these results are based on a single point-in-time result for each branch. For full results, see the dashboard.

Graphs show the p99 interval based on the mean and StdDev of the test run, as well as the mean value of the run (shown as a diamond below the graph).

gantt
    title Execution time (ms) FakeDbCommand (.NET Framework 4.6.2) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (5939) - mean (74ms)  : 64, 84
     .   : milestone, 74,

    section CallTarget+Inlining+NGEN
    This PR (5939) - mean (1,027ms)  : 1009, 1044
     .   : milestone, 1027,

Loading
gantt
    title Execution time (ms) FakeDbCommand (.NET Core 3.1) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (5939) - mean (110ms)  : 107, 113
     .   : milestone, 110,

    section CallTarget+Inlining+NGEN
    This PR (5939) - mean (709ms)  : 684, 734
     .   : milestone, 709,

Loading
gantt
    title Execution time (ms) FakeDbCommand (.NET 6) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (5939) - mean (94ms)  : 91, 96
     .   : milestone, 94,

    section CallTarget+Inlining+NGEN
    This PR (5939) - mean (667ms)  : 646, 689
     .   : milestone, 667,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET Framework 4.6.2) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (5939) - mean (190ms)  : 188, 193
     .   : milestone, 190,

    section CallTarget+Inlining+NGEN
    This PR (5939) - mean (1,115ms)  : 1095, 1135
     .   : milestone, 1115,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET Core 3.1) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (5939) - mean (276ms)  : 271, 281
     .   : milestone, 276,

    section CallTarget+Inlining+NGEN
    This PR (5939) - mean (877ms)  : 857, 898
     .   : milestone, 877,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (5939) - mean (266ms)  : 260, 272
     .   : milestone, 266,

    section CallTarget+Inlining+NGEN
    This PR (5939) - mean (864ms)  : 847, 881
     .   : milestone, 864,

Loading

@andrewlock
Copy link
Member Author

Benchmarks Report for tracer 🐌

Benchmarks for #5939 compared to master:

  • 2 benchmarks are slower, with geometric mean 1.164
  • All benchmarks have the same allocations

The following thresholds were used for comparing the benchmark speeds:

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

Allocation changes below 0.5% are ignored.

Benchmark details

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

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartStopWithChild net6.0 7.69μs 43.4ns 310ns 0.0145 0.00727 0 5.42 KB
master StartStopWithChild netcoreapp3.1 9.85μs 52.3ns 272ns 0.0197 0.00983 0 5.62 KB
master StartStopWithChild net472 16.5μs 82.9ns 531ns 1.03 0.307 0.105 6.07 KB
#5939 StartStopWithChild net6.0 7.54μs 32.4ns 117ns 0.0114 0.0038 0 5.43 KB
#5939 StartStopWithChild netcoreapp3.1 9.75μs 52.4ns 277ns 0.0198 0.00494 0 5.61 KB
#5939 StartStopWithChild net472 16.1μs 69.2ns 268ns 1.02 0.289 0.0964 6.07 KB
Benchmarks.Trace.AgentWriterBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master WriteAndFlushEnrichedTraces net6.0 455μs 312ns 1.21μs 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 669μs 408ns 1.53μs 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces net472 836μs 541ns 2.02μs 0.417 0 0 3.3 KB
#5939 WriteAndFlushEnrichedTraces net6.0 477μs 212ns 822ns 0 0 0 2.7 KB
#5939 WriteAndFlushEnrichedTraces netcoreapp3.1 662μs 371ns 1.44μs 0 0 0 2.7 KB
#5939 WriteAndFlushEnrichedTraces net472 844μs 488ns 1.89μs 0.419 0 0 3.3 KB
Benchmarks.Trace.AspNetCoreBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendRequest net6.0 191μs 1.01μs 7.63μs 0.187 0 0 18.45 KB
master SendRequest netcoreapp3.1 220μs 1.19μs 10.4μs 0.222 0 0 20.61 KB
master SendRequest net472 0.00193ns 0.000701ns 0.00271ns 0 0 0 0 b
#5939 SendRequest net6.0 194μs 1.13μs 10.1μs 0.18 0 0 18.45 KB
#5939 SendRequest netcoreapp3.1 211μs 1.14μs 8.07μs 0.21 0 0 20.61 KB
#5939 SendRequest net472 0.000802ns 0.000353ns 0.00137ns 0 0 0 0 b
Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master WriteAndFlushEnrichedTraces net6.0 576μs 2.37μs 10.8μs 0.573 0 0 41.71 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 697μs 3.94μs 26.8μs 0.332 0 0 41.73 KB
master WriteAndFlushEnrichedTraces net472 869μs 4μs 16μs 8.25 2.6 0.434 53.36 KB
#5939 WriteAndFlushEnrichedTraces net6.0 581μs 2.82μs 12μs 0.556 0 0 41.74 KB
#5939 WriteAndFlushEnrichedTraces netcoreapp3.1 658μs 3.33μs 14.9μs 0.324 0 0 41.67 KB
#5939 WriteAndFlushEnrichedTraces net472 864μs 3.44μs 12.9μs 8.39 2.52 0.419 53.29 KB
Benchmarks.Trace.DbCommandBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master ExecuteNonQuery net6.0 1.22μs 1.26ns 4.88ns 0.0141 0 0 1.02 KB
master ExecuteNonQuery netcoreapp3.1 1.68μs 1.06ns 4.12ns 0.0134 0 0 1.02 KB
master ExecuteNonQuery net472 2.01μs 2.21ns 8.58ns 0.156 0 0 987 B
#5939 ExecuteNonQuery net6.0 1.32μs 0.814ns 3.15ns 0.0145 0 0 1.02 KB
#5939 ExecuteNonQuery netcoreapp3.1 1.69μs 1.49ns 5.17ns 0.0139 0 0 1.02 KB
#5939 ExecuteNonQuery net472 2.07μs 2.16ns 8.08ns 0.156 0 0 987 B
Benchmarks.Trace.ElasticsearchBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master CallElasticsearch net6.0 1.17μs 0.506ns 1.89ns 0.0135 0 0 976 B
master CallElasticsearch netcoreapp3.1 1.47μs 0.565ns 2.11ns 0.0134 0 0 976 B
master CallElasticsearch net472 2.45μs 1.19ns 4.14ns 0.158 0 0 995 B
master CallElasticsearchAsync net6.0 1.29μs 0.487ns 1.82ns 0.0129 0 0 952 B
master CallElasticsearchAsync netcoreapp3.1 1.67μs 1.01ns 3.77ns 0.0133 0 0 1.02 KB
master CallElasticsearchAsync net472 2.56μs 1.51ns 5.66ns 0.167 0 0 1.05 KB
#5939 CallElasticsearch net6.0 1.2μs 4.45ns 17.2ns 0.0137 0 0 976 B
#5939 CallElasticsearch netcoreapp3.1 1.53μs 0.663ns 2.48ns 0.013 0 0 976 B
#5939 CallElasticsearch net472 2.5μs 1.99ns 7.71ns 0.158 0 0 995 B
#5939 CallElasticsearchAsync net6.0 1.32μs 0.792ns 2.96ns 0.0131 0 0 952 B
#5939 CallElasticsearchAsync netcoreapp3.1 1.66μs 0.628ns 2.35ns 0.0141 0 0 1.02 KB
#5939 CallElasticsearchAsync net472 2.48μs 1.39ns 5.2ns 0.167 0 0 1.05 KB
Benchmarks.Trace.GraphQLBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master ExecuteAsync net6.0 1.29μs 1.03ns 4.01ns 0.0136 0 0 952 B
master ExecuteAsync netcoreapp3.1 1.52μs 1.27ns 4.76ns 0.0128 0 0 952 B
master ExecuteAsync net472 1.79μs 0.964ns 3.61ns 0.145 0 0 915 B
#5939 ExecuteAsync net6.0 1.26μs 0.695ns 2.6ns 0.0132 0 0 952 B
#5939 ExecuteAsync netcoreapp3.1 1.52μs 0.652ns 2.44ns 0.0129 0 0 952 B
#5939 ExecuteAsync net472 1.76μs 1.17ns 4.53ns 0.145 0 0 915 B
Benchmarks.Trace.HttpClientBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendAsync net6.0 4.13μs 1.69ns 6.31ns 0.0311 0 0 2.22 KB
master SendAsync netcoreapp3.1 5.08μs 1.83ns 7.09ns 0.0356 0 0 2.76 KB
master SendAsync net472 7.92μs 8.94ns 34.6ns 0.498 0 0 3.15 KB
#5939 SendAsync net6.0 4.13μs 0.938ns 3.51ns 0.0311 0 0 2.22 KB
#5939 SendAsync netcoreapp3.1 5.28μs 1.76ns 6.58ns 0.037 0 0 2.76 KB
#5939 SendAsync net472 7.75μs 2.12ns 8.21ns 0.497 0 0 3.15 KB
Benchmarks.Trace.ILoggerBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 1.48μs 0.987ns 3.82ns 0.0231 0 0 1.64 KB
master EnrichedLog netcoreapp3.1 2.37μs 1.04ns 3.88ns 0.0225 0 0 1.64 KB
master EnrichedLog net472 2.77μs 1.52ns 5.69ns 0.249 0 0 1.57 KB
#5939 EnrichedLog net6.0 1.55μs 1.08ns 4.03ns 0.0234 0 0 1.64 KB
#5939 EnrichedLog netcoreapp3.1 2.25μs 1.48ns 5.55ns 0.0214 0 0 1.64 KB
#5939 EnrichedLog net472 2.61μs 1.72ns 5.97ns 0.249 0 0 1.57 KB
Benchmarks.Trace.Log4netBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 116μs 148ns 575ns 0.0584 0 0 4.28 KB
master EnrichedLog netcoreapp3.1 121μs 261ns 1.01μs 0 0 0 4.28 KB
master EnrichedLog net472 150μs 260ns 1.01μs 0.67 0.223 0 4.46 KB
#5939 EnrichedLog net6.0 113μs 180ns 696ns 0.0567 0 0 4.28 KB
#5939 EnrichedLog netcoreapp3.1 119μs 185ns 692ns 0.0613 0 0 4.28 KB
#5939 EnrichedLog net472 152μs 358ns 1.39μs 0.676 0.225 0 4.46 KB
Benchmarks.Trace.NLogBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 2.98μs 0.767ns 2.87ns 0.0311 0 0 2.2 KB
master EnrichedLog netcoreapp3.1 4.19μs 1.95ns 7.29ns 0.0294 0 0 2.2 KB
master EnrichedLog net472 4.84μs 0.795ns 2.87ns 0.32 0 0 2.02 KB
#5939 EnrichedLog net6.0 3.02μs 0.964ns 3.61ns 0.0303 0 0 2.2 KB
#5939 EnrichedLog netcoreapp3.1 4.07μs 1.24ns 4.79ns 0.0285 0 0 2.2 KB
#5939 EnrichedLog net472 4.86μs 0.836ns 3.24ns 0.319 0 0 2.02 KB
Benchmarks.Trace.RedisBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendReceive net6.0 1.33μs 1.3ns 5.04ns 0.016 0 0 1.14 KB
master SendReceive netcoreapp3.1 1.74μs 0.728ns 2.62ns 0.0156 0 0 1.14 KB
master SendReceive net472 2.21μs 1.04ns 4.04ns 0.183 0.0011 0 1.16 KB
#5939 SendReceive net6.0 1.36μs 0.545ns 2.11ns 0.0162 0 0 1.14 KB
#5939 SendReceive netcoreapp3.1 1.73μs 1.2ns 4.64ns 0.0156 0 0 1.14 KB
#5939 SendReceive net472 2.16μs 1.51ns 5.84ns 0.183 0 0 1.16 KB
Benchmarks.Trace.SerilogBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 2.74μs 0.858ns 3.21ns 0.0219 0 0 1.6 KB
master EnrichedLog netcoreapp3.1 3.83μs 2ns 7.75ns 0.021 0 0 1.65 KB
master EnrichedLog net472 4.44μs 2.7ns 10.5ns 0.323 0 0 2.04 KB
#5939 EnrichedLog net6.0 2.76μs 0.643ns 2.41ns 0.0222 0 0 1.6 KB
#5939 EnrichedLog netcoreapp3.1 3.95μs 1.39ns 5.2ns 0.0219 0 0 1.65 KB
#5939 EnrichedLog net472 4.35μs 2.59ns 10ns 0.322 0 0 2.04 KB
Benchmarks.Trace.SpanBenchmark - Slower ⚠️ Same allocations ✔️

Slower ⚠️ in #5939

Benchmark diff/base Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.SpanBenchmark.StartFinishSpan‑netcoreapp3.1 1.190 559.95 666.25
Benchmarks.Trace.SpanBenchmark.StartFinishSpan‑net472 1.139 581.05 661.71

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartFinishSpan net6.0 408ns 0.917ns 3.55ns 0.00808 0 0 576 B
master StartFinishSpan netcoreapp3.1 560ns 0.289ns 1.12ns 0.00766 0 0 576 B
master StartFinishSpan net472 581ns 0.615ns 2.22ns 0.0917 0 0 578 B
master StartFinishScope net6.0 487ns 0.474ns 1.77ns 0.00969 0 0 696 B
master StartFinishScope netcoreapp3.1 732ns 0.497ns 1.92ns 0.00924 0 0 696 B
master StartFinishScope net472 947ns 2.16ns 8.08ns 0.104 0 0 658 B
#5939 StartFinishSpan net6.0 434ns 0.567ns 2.12ns 0.00812 0 0 576 B
#5939 StartFinishSpan netcoreapp3.1 666ns 0.45ns 1.68ns 0.00779 0 0 576 B
#5939 StartFinishSpan net472 662ns 0.353ns 1.37ns 0.0916 0 0 578 B
#5939 StartFinishScope net6.0 532ns 0.213ns 0.796ns 0.00967 0 0 696 B
#5939 StartFinishScope netcoreapp3.1 734ns 0.701ns 2.72ns 0.00918 0 0 696 B
#5939 StartFinishScope net472 854ns 0.447ns 1.67ns 0.104 0 0 658 B
Benchmarks.Trace.TraceAnnotationsBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master RunOnMethodBegin net6.0 674ns 0.341ns 1.32ns 0.00973 0 0 696 B
master RunOnMethodBegin netcoreapp3.1 958ns 1.64ns 6.13ns 0.00948 0 0 696 B
master RunOnMethodBegin net472 1.14μs 5.01ns 19.4ns 0.104 0 0 658 B
#5939 RunOnMethodBegin net6.0 661ns 0.262ns 1.02ns 0.00978 0 0 696 B
#5939 RunOnMethodBegin netcoreapp3.1 900ns 0.354ns 1.37ns 0.00956 0 0 696 B
#5939 RunOnMethodBegin net472 1.07μs 0.958ns 3.58ns 0.104 0 0 658 B

@andrewlock andrewlock merged commit ee07297 into release/2.x Aug 28, 2024
60 of 65 checks passed
@andrewlock andrewlock deleted the kevin/error_loader-v2 branch August 28, 2024 08:33
@github-actions github-actions bot added this to the vNext-v2 milestone Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:native-library Automatic instrumentation native C++ code (Datadog.Trace.ClrProfiler.Native)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants