Skip to content

[Crashtracking] Implement support for Windows#6088

Merged
kevingosse merged 17 commits into
masterfrom
kevin/crashtracking_windows
Oct 3, 2024
Merged

[Crashtracking] Implement support for Windows#6088
kevingosse merged 17 commits into
masterfrom
kevin/crashtracking_windows

Conversation

@kevingosse

@kevingosse kevingosse commented Sep 26, 2024

Copy link
Copy Markdown
Contributor

Summary of changes

Add crashtracking support for Windows.

At the moment, only x64 is supported. Supporting x86 would require to include a 32-bit version of dd-dotnet in the package.

Reason for change

Until now, crashtracking only supported Linux. There are many crashes (due to either netfx or IIS) that only occur on Windows.

Implementation details

Crashtracking on Windows relies on WER.

When the native loader is loaded, we use WerRegisterRuntimeExceptionModule to register it as a crash handler. Note that .NET also registers a crash handler, and they're invoked by order of registration. To be invoked first, we unregister the .NET crash handler, register our own, then re-register the .NET crash handler.

The .NET crash handler is in the DAC (mscordawks.dll for .NET Framework, mscordaccore.dll for .NET Core). The context argument is set to the address of clr.dll/coreclr.dll in memory (this is important because WerUnregisterRuntimeExceptionModule fails if the context value is different).

When a crash occurs, Windows freezes the process and launches WerFault.exe. In WerFault, the crash handler is loaded and given a chance to inspect the crash (using the exported OutOfProcessExceptionEventCallback function). We invoke dd-dotnet to inspect the process and generate the crash report.

The environment variables of the crashing process are not propagated to WerFault.exe. Because we need them (for instance, to know the location of the agent), we make a copy of all the DD_* environment variables and give the address of that copy as the "context" argument of WerRegisterRuntimeExceptionModule. When OutOfProcessExceptionEventCallback is invoked in WerFault.exe, we use ReadProcessMemory to read the saved environment variables from the crashing process, and set them for dd-dotnet.

Test coverage

Reusing the existing crashtracking tests.

Other details

More information on WER: https://minidump.net/windows-error-reporting/

https://datadoghq.atlassian.net/browse/APMSP-1388

@kevingosse
kevingosse force-pushed the kevin/crashtracking_windows branch from 5afcd6f to 92d35d8 Compare September 27, 2024 11:51
@datadog-ddstaging

datadog-ddstaging Bot commented Sep 27, 2024

Copy link
Copy Markdown

Datadog Report

Branch report: kevin/crashtracking_windows
Commit report: 4748156
Test service: dd-trace-dotnet

✅ 0 Failed, 368206 Passed, 2357 Skipped, 18h 1m 26.83s Total Time
❄️ 2 New Flaky

New Flaky Tests (2)

  • HttpClient_SubmitsTraces - Datadog.Trace.ClrProfiler.IntegrationTests.HttpMessageHandlerTests - Last Failure

    Expand for error
     
     Expected var integration = latestIntegrations {empty} to contain key "CurlHandler".), but no such item was found.t found False.
    
  • HttpClient_SubmitsTraces - Datadog.Trace.ClrProfiler.IntegrationTests.HttpMessageHandlerTests - Last Failure

    Expand for error
     
     Expected var integration = latestIntegrations {empty} to contain key "CurlHandler".), but no such item was found.t found False.
    

@andrewlock

andrewlock commented Sep 27, 2024

Copy link
Copy Markdown
Member

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 (6088) - mean (71ms)  : 67, 74
     .   : milestone, 71,
    master - mean (70ms)  : 68, 73
     .   : milestone, 70,

    section CallTarget+Inlining+NGEN
    This PR (6088) - mean (1,108ms)  : 1089, 1126
     .   : milestone, 1108,
    master - mean (1,110ms)  : 1090, 1131
     .   : milestone, 1110,

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

    section CallTarget+Inlining+NGEN
    This PR (6088) - mean (775ms)  : 760, 790
     .   : milestone, 775,
    master - mean (775ms)  : 755, 795
     .   : milestone, 775,

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

    section CallTarget+Inlining+NGEN
    This PR (6088) - mean (730ms)  : 714, 746
     .   : milestone, 730,
    master - mean (732ms)  : 717, 747
     .   : milestone, 732,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET Framework 4.6.2) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6088) - mean (191ms)  : 186, 195
     .   : milestone, 191,
    master - mean (190ms)  : 187, 192
     .   : milestone, 190,

    section CallTarget+Inlining+NGEN
    This PR (6088) - mean (1,200ms)  : 1182, 1218
     .   : milestone, 1200,
    master - mean (1,201ms)  : 1178, 1224
     .   : milestone, 1201,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET Core 3.1) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6088) - mean (276ms)  : 271, 282
     .   : milestone, 276,
    master - mean (275ms)  : 272, 279
     .   : milestone, 275,

    section CallTarget+Inlining+NGEN
    This PR (6088) - mean (940ms)  : 917, 963
     .   : milestone, 940,
    master - mean (939ms)  : 924, 955
     .   : milestone, 939,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6088) - mean (264ms)  : 261, 268
     .   : milestone, 264,
    master - mean (265ms)  : 261, 269
     .   : milestone, 265,

    section CallTarget+Inlining+NGEN
    This PR (6088) - mean (922ms)  : 903, 942
     .   : milestone, 922,
    master - mean (926ms)  : 907, 946
     .   : milestone, 926,

Loading

@andrewlock

andrewlock commented Sep 27, 2024

Copy link
Copy Markdown
Member

Benchmarks Report for tracer 🐌

Benchmarks for #6088 compared to master:

  • All benchmarks have the same speed
  • 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.58μs 42ns 266ns 0.0148 0.00742 0 5.42 KB
master StartStopWithChild netcoreapp3.1 9.87μs 54.2ns 343ns 0.0191 0.00957 0 5.61 KB
master StartStopWithChild net472 16.2μs 42.6ns 165ns 1.01 0.3 0.0893 6.06 KB
#6088 StartStopWithChild net6.0 7.81μs 45ns 357ns 0.0157 0.00783 0 5.43 KB
#6088 StartStopWithChild netcoreapp3.1 10μs 55.9ns 367ns 0.0251 0.01 0 5.62 KB
#6088 StartStopWithChild net472 16.3μs 47.5ns 178ns 1.01 0.282 0.0805 6.05 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 487μs 726ns 2.81μs 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 645μs 308ns 1.15μs 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces net472 834μs 736ns 2.85μs 0.417 0 0 3.3 KB
#6088 WriteAndFlushEnrichedTraces net6.0 464μs 337ns 1.26μs 0 0 0 2.7 KB
#6088 WriteAndFlushEnrichedTraces netcoreapp3.1 659μs 450ns 1.74μs 0 0 0 2.7 KB
#6088 WriteAndFlushEnrichedTraces net472 829μs 387ns 1.39μs 0.414 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 200μs 1.12μs 7.65μs 0.198 0 0 18.45 KB
master SendRequest netcoreapp3.1 213μs 1.07μs 5.13μs 0.216 0 0 20.61 KB
master SendRequest net472 0ns 0ns 0ns 0 0 0 0 b
#6088 SendRequest net6.0 193μs 1.03μs 6.6μs 0.193 0 0 18.45 KB
#6088 SendRequest netcoreapp3.1 220μs 1.23μs 7.57μs 0.218 0 0 20.61 KB
#6088 SendRequest net472 0.000186ns 0.000137ns 0.000531ns 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 567μs 2.1μs 8.14μs 0.563 0 0 41.6 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 683μs 3.58μs 17.2μs 0.338 0 0 41.71 KB
master WriteAndFlushEnrichedTraces net472 872μs 4.24μs 17μs 8.45 2.53 0.422 53.35 KB
#6088 WriteAndFlushEnrichedTraces net6.0 571μs 2.45μs 10.7μs 0.561 0 0 41.65 KB
#6088 WriteAndFlushEnrichedTraces netcoreapp3.1 678μs 3.59μs 17.9μs 0.327 0 0 41.78 KB
#6088 WriteAndFlushEnrichedTraces net472 847μs 3.33μs 12.4μs 8.81 2.52 0.419 53.24 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.41μs 1.1ns 4.28ns 0.0148 0 0 1.02 KB
master ExecuteNonQuery netcoreapp3.1 1.82μs 0.904ns 3.38ns 0.0137 0 0 1.02 KB
master ExecuteNonQuery net472 2.13μs 2.24ns 8.67ns 0.157 0 0 987 B
#6088 ExecuteNonQuery net6.0 1.33μs 1.24ns 4.82ns 0.0144 0 0 1.02 KB
#6088 ExecuteNonQuery netcoreapp3.1 1.76μs 0.779ns 2.91ns 0.0133 0 0 1.02 KB
#6088 ExecuteNonQuery net472 2.06μs 1.79ns 6.95ns 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.12μs 1.79ns 6.94ns 0.0134 0 0 976 B
master CallElasticsearch netcoreapp3.1 1.68μs 0.912ns 3.41ns 0.0134 0 0 976 B
master CallElasticsearch net472 2.59μs 1.64ns 6.35ns 0.157 0 0 995 B
master CallElasticsearchAsync net6.0 1.3μs 0.807ns 3.12ns 0.0135 0 0 952 B
master CallElasticsearchAsync netcoreapp3.1 1.6μs 1.05ns 4.05ns 0.0136 0 0 1.02 KB
master CallElasticsearchAsync net472 2.55μs 1.76ns 6.83ns 0.166 0 0 1.05 KB
#6088 CallElasticsearch net6.0 1.12μs 0.523ns 1.96ns 0.0135 0 0 976 B
#6088 CallElasticsearch netcoreapp3.1 1.53μs 0.384ns 1.39ns 0.0131 0 0 976 B
#6088 CallElasticsearch net472 2.4μs 1.52ns 5.9ns 0.158 0 0 995 B
#6088 CallElasticsearchAsync net6.0 1.27μs 0.87ns 3.37ns 0.0133 0 0 952 B
#6088 CallElasticsearchAsync netcoreapp3.1 1.61μs 0.805ns 3.01ns 0.0138 0 0 1.02 KB
#6088 CallElasticsearchAsync net472 2.54μs 1.23ns 4.76ns 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.26μs 1.38ns 4.78ns 0.0133 0 0 952 B
master ExecuteAsync netcoreapp3.1 1.56μs 0.632ns 2.45ns 0.0124 0 0 952 B
master ExecuteAsync net472 1.76μs 0.605ns 2.18ns 0.145 0 0 915 B
#6088 ExecuteAsync net6.0 1.32μs 1.72ns 5.97ns 0.013 0 0 952 B
#6088 ExecuteAsync netcoreapp3.1 1.64μs 0.923ns 3.45ns 0.0131 0 0 952 B
#6088 ExecuteAsync net472 1.7μs 1.04ns 4.03ns 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.43μs 2.2ns 7.95ns 0.0311 0 0 2.22 KB
master SendAsync netcoreapp3.1 5.15μs 1.65ns 5.95ns 0.0362 0 0 2.76 KB
master SendAsync net472 7.72μs 1.72ns 6.68ns 0.496 0 0 3.15 KB
#6088 SendAsync net6.0 4.12μs 0.873ns 3.27ns 0.0311 0 0 2.22 KB
#6088 SendAsync netcoreapp3.1 5.14μs 1.51ns 5.86ns 0.036 0 0 2.76 KB
#6088 SendAsync net472 7.91μs 3.28ns 11.8ns 0.498 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 1.44ns 5.37ns 0.0234 0 0 1.64 KB
master EnrichedLog netcoreapp3.1 2.31μs 1.8ns 6.49ns 0.022 0 0 1.64 KB
master EnrichedLog net472 2.64μs 2.29ns 8.56ns 0.249 0 0 1.57 KB
#6088 EnrichedLog net6.0 1.45μs 0.696ns 2.61ns 0.0232 0 0 1.64 KB
#6088 EnrichedLog netcoreapp3.1 2.22μs 1.16ns 4.35ns 0.022 0 0 1.64 KB
#6088 EnrichedLog net472 2.54μs 1.49ns 5.37ns 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 114μs 172ns 642ns 0.0566 0 0 4.28 KB
master EnrichedLog netcoreapp3.1 120μs 115ns 414ns 0 0 0 4.28 KB
master EnrichedLog net472 146μs 119ns 461ns 0.655 0.218 0 4.46 KB
#6088 EnrichedLog net6.0 114μs 127ns 491ns 0.0576 0 0 4.28 KB
#6088 EnrichedLog netcoreapp3.1 118μs 197ns 764ns 0 0 0 4.28 KB
#6088 EnrichedLog net472 146μs 116ns 451ns 0.657 0.219 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 3.01μs 1.21ns 4.68ns 0.0301 0 0 2.2 KB
master EnrichedLog netcoreapp3.1 4.19μs 1.96ns 7.33ns 0.0296 0 0 2.2 KB
master EnrichedLog net472 4.79μs 1.68ns 6.28ns 0.319 0 0 2.02 KB
#6088 EnrichedLog net6.0 2.92μs 1.14ns 4.42ns 0.0305 0 0 2.2 KB
#6088 EnrichedLog netcoreapp3.1 4.05μs 2.08ns 8.04ns 0.0284 0 0 2.2 KB
#6088 EnrichedLog net472 4.93μs 1.6ns 6.18ns 0.32 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.41μs 0.88ns 3.41ns 0.0162 0 0 1.14 KB
master SendReceive netcoreapp3.1 1.76μs 1.08ns 4.02ns 0.0158 0 0 1.14 KB
master SendReceive net472 2.1μs 0.725ns 2.81ns 0.184 0.00104 0 1.16 KB
#6088 SendReceive net6.0 1.32μs 0.689ns 2.67ns 0.0157 0 0 1.14 KB
#6088 SendReceive netcoreapp3.1 1.66μs 0.848ns 3.06ns 0.0149 0 0 1.14 KB
#6088 SendReceive net472 2.07μs 0.887ns 3.44ns 0.183 0.00103 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.61μs 0.775ns 3ns 0.0221 0 0 1.6 KB
master EnrichedLog netcoreapp3.1 3.88μs 2ns 7.76ns 0.0213 0 0 1.65 KB
master EnrichedLog net472 4.46μs 2.37ns 8.85ns 0.323 0 0 2.04 KB
#6088 EnrichedLog net6.0 2.69μs 0.853ns 3.3ns 0.0225 0 0 1.6 KB
#6088 EnrichedLog netcoreapp3.1 3.88μs 5.12ns 19.8ns 0.0213 0 0 1.65 KB
#6088 EnrichedLog net472 4.49μs 2.73ns 10.6ns 0.322 0 0 2.04 KB
Benchmarks.Trace.SpanBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartFinishSpan net6.0 417ns 0.253ns 0.98ns 0.00806 0 0 576 B
master StartFinishSpan netcoreapp3.1 591ns 1.37ns 5.32ns 0.00796 0 0 576 B
master StartFinishSpan net472 694ns 1.02ns 3.96ns 0.0916 0 0 578 B
master StartFinishScope net6.0 472ns 0.291ns 1.13ns 0.00971 0 0 696 B
master StartFinishScope netcoreapp3.1 740ns 1.27ns 4.9ns 0.00949 0 0 696 B
master StartFinishScope net472 897ns 0.897ns 3.47ns 0.105 0 0 658 B
#6088 StartFinishSpan net6.0 406ns 0.169ns 0.655ns 0.00797 0 0 576 B
#6088 StartFinishSpan netcoreapp3.1 636ns 0.703ns 2.72ns 0.00785 0 0 576 B
#6088 StartFinishSpan net472 654ns 0.935ns 3.62ns 0.0917 0 0 578 B
#6088 StartFinishScope net6.0 482ns 0.155ns 0.601ns 0.00964 0 0 696 B
#6088 StartFinishScope netcoreapp3.1 778ns 0.933ns 3.61ns 0.00931 0 0 696 B
#6088 StartFinishScope net472 875ns 2.48ns 9.61ns 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 715ns 0.432ns 1.67ns 0.00963 0 0 696 B
master RunOnMethodBegin netcoreapp3.1 943ns 1.85ns 7.15ns 0.00931 0 0 696 B
master RunOnMethodBegin net472 1.15μs 1.29ns 4.81ns 0.105 0 0 658 B
#6088 RunOnMethodBegin net6.0 645ns 0.455ns 1.76ns 0.00979 0 0 696 B
#6088 RunOnMethodBegin netcoreapp3.1 895ns 0.269ns 0.971ns 0.00944 0 0 696 B
#6088 RunOnMethodBegin net472 1.06μs 0.786ns 2.94ns 0.104 0 0 658 B

@andrewlock

andrewlock commented Sep 27, 2024

Copy link
Copy Markdown
Member

Throughput/Crank Report ⚡

Throughput results for AspNetCoreSimpleController comparing the following branches/commits:

Cases where throughput results for the PR are worse than latest master (5% drop or greater), results are shown in red.

Note that these results are based on a single point-in-time result for each branch. For full results, see one of the many, many dashboards!

gantt
    title Throughput Linux x64 (Total requests) 
    dateFormat  X
    axisFormat %s
    section Baseline
    This PR (6088) (11.064M)   : 0, 11063518
    master (11.009M)   : 0, 11009316
    benchmarks/2.9.0 (11.081M)   : 0, 11080577

    section Automatic
    This PR (6088) (7.358M)   : 0, 7358411
    master (7.392M)   : 0, 7391896
    benchmarks/2.9.0 (7.732M)   : 0, 7732233

    section Trace stats
    master (7.658M)   : 0, 7657594

    section Manual
    master (10.944M)   : 0, 10944483

    section Manual + Automatic
    This PR (6088) (6.649M)   : 0, 6649316
    master (6.786M)   : 0, 6785950

    section DD_TRACE_ENABLED=0
    master (10.229M)   : 0, 10229067

Loading
gantt
    title Throughput Linux arm64 (Total requests) 
    dateFormat  X
    axisFormat %s
    section Baseline
    This PR (6088) (9.626M)   : 0, 9625677
    master (9.438M)   : 0, 9438257
    benchmarks/2.9.0 (9.798M)   : 0, 9798067

    section Automatic
    This PR (6088) (6.409M)   : 0, 6409158
    master (6.590M)   : 0, 6590052

    section Trace stats
    master (7.018M)   : 0, 7018387

    section Manual
    master (9.760M)   : 0, 9760011

    section Manual + Automatic
    This PR (6088) (5.989M)   : 0, 5988723
    master (6.122M)   : 0, 6122138

    section DD_TRACE_ENABLED=0
    master (8.792M)   : 0, 8791745

Loading
gantt
    title Throughput Windows x64 (Total requests) 
    dateFormat  X
    axisFormat %s
    section Baseline
    This PR (6088) (10.144M)   : 0, 10143954
    master (9.927M)   : 0, 9927076
    benchmarks/2.9.0 (10.067M)   : 0, 10067315

    section Automatic
    This PR (6088) (6.652M)   : 0, 6651784
    master (6.595M)   : 0, 6594814
    benchmarks/2.9.0 (7.552M)   : 0, 7552193

    section Trace stats
    master (7.253M)   : 0, 7253184

    section Manual
    master (10.031M)   : 0, 10030951

    section Manual + Automatic
    This PR (6088) (6.292M)   : 0, 6291909
    master (6.128M)   : 0, 6128464

    section DD_TRACE_ENABLED=0
    master (9.284M)   : 0, 9283843

Loading

@kevingosse
kevingosse force-pushed the kevin/crashtracking_windows branch from 1623a8a to 8d064ca Compare September 30, 2024 09:07
@kevingosse kevingosse changed the title Kevin/crashtracking windows [Crashtracking] Implement support for Windows Sep 30, 2024
@kevingosse
kevingosse marked this pull request as ready for review September 30, 2024 14:07
@kevingosse
kevingosse requested review from a team as code owners September 30, 2024 14:07
Comment thread shared/src/Datadog.Trace.ClrProfiler.Native/crashhandler.cpp
Comment thread shared/src/Datadog.Trace.ClrProfiler.Native/crashhandler.cpp Outdated
Comment thread shared/src/Datadog.Trace.ClrProfiler.Native/crashhandler.cpp
Comment thread shared/src/Datadog.Trace.ClrProfiler.Native/crashhandler.cpp Outdated
Comment thread shared/src/Datadog.Trace.ClrProfiler.Native/crashhandler.cpp
Comment thread shared/src/Datadog.Trace.ClrProfiler.Native/crashhandler.cpp Outdated
Comment thread shared/src/Datadog.Trace.ClrProfiler.Native/crashhandler.cpp Outdated
Comment thread shared/src/Datadog.Trace.ClrProfiler.Native/crashhandler.cpp Outdated
Comment thread shared/src/Datadog.Trace.ClrProfiler.Native/crashhandler.cpp
Comment thread shared/src/Datadog.Trace.ClrProfiler.Native/dllmain.cpp

@chrisnas chrisnas 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.

LGTM

@gleocadie gleocadie 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.

little comment there and there but overall LGTM

Comment thread shared/src/Datadog.Trace.ClrProfiler.Native/crashhandler.cpp Outdated
Comment thread shared/src/Datadog.Trace.ClrProfiler.Native/crashhandler.cpp Outdated
Comment thread shared/src/Datadog.Trace.ClrProfiler.Native/crashhandler.h
Comment thread shared/src/Datadog.Trace.ClrProfiler.Native/crashhandler.cpp Outdated
Comment thread shared/src/Datadog.Trace.ClrProfiler.Native/crashhandler.cpp
Comment thread shared/src/Datadog.Trace.ClrProfiler.Native/crashhandler.cpp
Comment thread shared/src/Datadog.Trace.ClrProfiler.Native/crashhandler.cpp
Comment thread shared/src/Datadog.Trace.ClrProfiler.Native/crashhandler.cpp

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

LGTM, but I'm 100% trusting the C++ is ok 🙈

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.

Mostly unrelated, but we should probably update the codeowners for all the crashreporting files to be shared between profiler and tracing do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Makes sense 🤔

Comment thread tracer/test/Datadog.Trace.TestHelpers/MockTracerAgent.cs
Comment thread tracer/test/Datadog.Trace.Tools.dd_dotnet.ArtifactTests/CreatedumpTests.cs Outdated
Comment thread tracer/test/Datadog.Trace.Tools.dd_dotnet.ArtifactTests/CreatedumpTests.cs Outdated
Comment thread tracer/test/Datadog.Trace.Tools.dd_dotnet.ArtifactTests/CreatedumpTests.cs Outdated
Comment thread tracer/test/Datadog.Trace.Tools.dd_dotnet.ArtifactTests/CreatedumpTests.cs Outdated

@bouwkast bouwkast 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.

Looks good to me (didn't review the native stuff, but looks like others did)

@kevingosse
kevingosse merged commit b7079da into master Oct 3, 2024
@kevingosse
kevingosse deleted the kevin/crashtracking_windows branch October 3, 2024 10:23
kevingosse pushed a commit that referenced this pull request Oct 3, 2024
## Summary of changes

Register `Datadog.Trace.ClrProfiler.Native.dll` in the
`HKLM\Software\Microsoft\Windows\Windows Error
Reporting\RuntimeExceptionHelperModules` key.

## Reason for change

This is needed by crashtracking.
If the value is absent, the tracer will create it in HKCU (the
instrumented application is unlikely to have permission to write to
HKLM). However, registering the crash handler in HKCU is only supported
in somewhat versions of Windows (since Windows 10 2004). So we should
rely on HKLM whenever possible.

## Other details

Depends on #6088

---------

Co-authored-by: Andrew Lock <[email protected]>
@github-actions github-actions Bot added this to the vNext-v3 milestone Oct 3, 2024
agocs pushed a commit that referenced this pull request Oct 8, 2024
## Summary of changes

Add crashtracking support for Windows.

At the moment, only x64 is supported. Supporting x86 would require to
include a 32-bit version of `dd-dotnet` in the package.

## Reason for change

Until now, crashtracking only supported Linux. There are many crashes
(due to either netfx or IIS) that only occur on Windows.

## Implementation details

Crashtracking on Windows relies on
[WER](https://learn.microsoft.com/en-us/windows/win32/wer/windows-error-reporting).

When the native loader is loaded, we use
`WerRegisterRuntimeExceptionModule` to register it as a crash handler.
Note that .NET also registers a crash handler, and they're invoked by
order of registration. To be invoked first, we unregister the .NET crash
handler, register our own, then re-register the .NET crash handler.

The .NET crash handler is in the DAC (mscordawks.dll for .NET Framework,
mscordaccore.dll for .NET Core). The context argument is set to the
address of `clr.dll`/`coreclr.dll` in memory (this is important because
`WerUnregisterRuntimeExceptionModule` fails if the context value is
different).

When a crash occurs, Windows freezes the process and launches
`WerFault.exe`. In WerFault, the crash handler is loaded and given a
chance to inspect the crash (using the exported
`OutOfProcessExceptionEventCallback` function). We invoke `dd-dotnet` to
inspect the process and generate the crash report.

The environment variables of the crashing process are not propagated to
`WerFault.exe`. Because we need them (for instance, to know the location
of the agent), we make a copy of all the `DD_*` environment variables
and give the address of that copy as the "context" argument of
`WerRegisterRuntimeExceptionModule`. When
`OutOfProcessExceptionEventCallback` is invoked in `WerFault.exe`, we
use `ReadProcessMemory` to read the saved environment variables from the
crashing process, and set them for `dd-dotnet`.

## Test coverage

Reusing the existing crashtracking tests.

## Other details

More information on WER: https://minidump.net/windows-error-reporting/
agocs pushed a commit that referenced this pull request Oct 8, 2024
## Summary of changes

Register `Datadog.Trace.ClrProfiler.Native.dll` in the
`HKLM\Software\Microsoft\Windows\Windows Error
Reporting\RuntimeExceptionHelperModules` key.

## Reason for change

This is needed by crashtracking.
If the value is absent, the tracer will create it in HKCU (the
instrumented application is unlikely to have permission to write to
HKLM). However, registering the crash handler in HKCU is only supported
in somewhat versions of Windows (since Windows 10 2004). So we should
rely on HKLM whenever possible.

## Other details

Depends on #6088

---------

Co-authored-by: Andrew Lock <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants