DataDog / dd-trace-dotnet

.NET Client Library for Datadog APM
https://docs.datadoghq.com/tracing/
Apache License 2.0
413 stars 132 forks source link

[ASM] Capture ObjectDisposedException #5732

Closed NachoEchevarria closed 4 days ago

NachoEchevarria commented 1 week ago

Summary of changes

We were getting a ObjectDisposedException error in the SecurityCoordinator.

In RASP (and IAST), we are instrumenting methods that can be called out of a request context, even when running web apps. For instance, we are instrumenting methods of the class File.

This error occurs when we try to access Context.Features and that field is null. The class DefaultHttpContext checks for null values in that property and launches an exception when it's null. This can happen, for instance, if the method Uninitialize() from DefaultHttpContext is called.

While it was not possible to reproduce this particular exception, some checks were added that could prevent this from happening again. These checks include checking if the additive context has been disposed, if the root span has been closed or if we are not running in a web context. In all of these cases, RASP is not required to run.

Reason for change

Implementation details

Test coverage

Other details

datadog-ddstaging[bot] commented 1 week ago

Datadog Report

Branch report: nacho/ObjectDisposedException Commit report: 795a27a Test service: dd-trace-dotnet

:white_check_mark: 0 Failed, 342810 Passed, 1620 Skipped, 14h 51m 8.12s Total Time

andrewlock commented 1 week ago

Execution-Time Benchmarks Report :stopwatch:

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:

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 (5732) - mean (74ms)  : 65, 84
     .   : milestone, 74,
    master - mean (74ms)  : 65, 83
     .   : milestone, 74,

    section CallTarget+Inlining+NGEN
    This PR (5732) - mean (990ms)  : 969, 1011
     .   : milestone, 990,
    master - mean (991ms)  : 973, 1009
     .   : milestone, 991,
gantt
    title Execution time (ms) FakeDbCommand (.NET Core 3.1) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (5732) - mean (109ms)  : 106, 112
     .   : milestone, 109,
    master - mean (110ms)  : 107, 113
     .   : milestone, 110,

    section CallTarget+Inlining+NGEN
    This PR (5732) - mean (702ms)  : 681, 724
     .   : milestone, 702,
    master - mean (698ms)  : 675, 722
     .   : milestone, 698,
gantt
    title Execution time (ms) FakeDbCommand (.NET 6) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (5732) - mean (93ms)  : 90, 96
     .   : milestone, 93,
    master - mean (93ms)  : 90, 96
     .   : milestone, 93,

    section CallTarget+Inlining+NGEN
    This PR (5732) - mean (653ms)  : 632, 674
     .   : milestone, 653,
    master - mean (657ms)  : 630, 683
     .   : milestone, 657,
gantt
    title Execution time (ms) HttpMessageHandler (.NET Framework 4.6.2) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (5732) - mean (194ms)  : 190, 198
     .   : milestone, 194,
    master - mean (192ms)  : 188, 196
     .   : milestone, 192,

    section CallTarget+Inlining+NGEN
    This PR (5732) - mean (1,096ms)  : 1071, 1120
     .   : milestone, 1096,
    master - mean (1,081ms)  : 1059, 1103
     .   : milestone, 1081,
gantt
    title Execution time (ms) HttpMessageHandler (.NET Core 3.1) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (5732) - mean (279ms)  : 273, 286
     .   : milestone, 279,
    master - mean (276ms)  : 271, 281
     .   : milestone, 276,

    section CallTarget+Inlining+NGEN
    This PR (5732) - mean (893ms)  : 872, 913
     .   : milestone, 893,
    master - mean (874ms)  : 849, 899
     .   : milestone, 874,
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (5732) - mean (269ms)  : 262, 277
     .   : milestone, 269,
    master - mean (269ms)  : 263, 275
     .   : milestone, 269,

    section CallTarget+Inlining+NGEN
    This PR (5732) - mean (862ms)  : 828, 896
     .   : milestone, 862,
    master - mean (867ms)  : 839, 894
     .   : milestone, 867,
andrewlock commented 1 week ago

Throughput/Crank Report:zap:

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 (5732) (12.019M)   : 0, 12019258
    master (11.753M)   : 0, 11753412
    benchmarks/2.9.0 (11.542M)   : 0, 11542126

    section Automatic
    This PR (5732) (8.136M)   : 0, 8136236
    master (7.853M)   : 0, 7853279
    benchmarks/2.9.0 (8.263M)   : 0, 8262905

    section Trace stats
    master (8.259M)   : 0, 8258966

    section Manual
    This PR (5732) (10.315M)   : 0, 10315281
    master (9.899M)   : 0, 9899401

    section Manual + Automatic
    This PR (5732) (7.692M)   : 0, 7691814
    master (7.433M)   : 0, 7432897

    section Version Conflict
    master (6.731M)   : 0, 6730574
gantt
    title Throughput Linux arm64 (Total requests) 
    dateFormat  X
    axisFormat %s
    section Baseline
    This PR (5732) (9.650M)   : 0, 9649980
    master (9.574M)   : 0, 9574121
    benchmarks/2.9.0 (9.596M)   : 0, 9596140

    section Automatic
    This PR (5732) (6.636M)   : 0, 6636137
    master (6.671M)   : 0, 6671192

    section Trace stats
    master (6.990M)   : 0, 6990244

    section Manual
    This PR (5732) (8.268M)   : 0, 8268402
    master (8.307M)   : 0, 8306500

    section Manual + Automatic
    This PR (5732) (6.215M)   : 0, 6214661
    master (6.251M)   : 0, 6250704

    section Version Conflict
    master (5.762M)   : 0, 5761603
gantt
    title Throughput Windows x64 (Total requests) 
    dateFormat  X
    axisFormat %s
    section Baseline
    This PR (5732) (9.949M)   : 0, 9949075
    master (10.202M)   : 0, 10201759
    benchmarks/2.9.0 (10.213M)   : 0, 10213239

    section Automatic
    This PR (5732) (6.992M)   : 0, 6992121
    master (7.212M)   : 0, 7212394
    benchmarks/2.9.0 (7.482M)   : 0, 7482023

    section Trace stats
    master (7.549M)   : 0, 7549360

    section Manual
    This PR (5732) (8.622M)   : 0, 8621515
    master (9.013M)   : 0, 9012822

    section Manual + Automatic
    This PR (5732) (6.706M)   : 0, 6705589
    master (7.018M)   : 0, 7017920

    section Version Conflict
    master (6.365M)   : 0, 6365432
andrewlock commented 1 week ago

Benchmarks Report for appsec :snail:

Benchmarks for #5732 compared to master:

The following thresholds were used for comparing the benchmark speeds:

Allocation changes below 0.5% are ignored.

Benchmark details

Benchmarks.Trace.Asm.AppSecBodyBenchmark - Same speed :heavy_check_mark: Same allocations :heavy_check_mark: ### Raw results | Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------|---------------------------- |-------------- |---------:|---------:|--------:|-------:|------:|------:|----------:| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`AllCycleSimpleBody`|net6.0|70.7μs|47.8ns|179ns|0.0703| 0|0|6 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`AllCycleSimpleBody`|netcoreapp3.1|61.5μs|98.5ns|381ns|0.0917| 0|0|6.94 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`AllCycleSimpleBody`|net472|47.8μs|32.1ns|116ns|1.31| 0|0|8.33 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`AllCycleMoreComplexBody`|net6.0|77.5μs|74ns|267ns|0.116| 0|0|9.5 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`AllCycleMoreComplexBody`|netcoreapp3.1|69μs|78.1ns|303ns|0.138| 0|0|10.36 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`AllCycleMoreComplexBody`|net472|54.6μs|58.5ns|227ns|1.88| 0.0272|0|11.84 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`ObjectExtractorSimpleBody`|net6.0|142ns|0.101ns|0.392ns|0.00393| 0|0|280 B| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`ObjectExtractorSimpleBody`|netcoreapp3.1|209ns|0.441ns|1.71ns|0.00377| 0|0|272 B| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`ObjectExtractorSimpleBody`|net472|171ns|0.117ns|0.452ns|0.0446| 0|0|281 B| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`ObjectExtractorMoreComplexBody`|net6.0|3.08μs|3.07ns|11.5ns|0.0537| 0|0|3.78 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`ObjectExtractorMoreComplexBody`|netcoreapp3.1|4.16μs|2.75ns|10.3ns|0.0503| 0|0|3.69 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`ObjectExtractorMoreComplexBody`|net472|3.84μs|3.67ns|14.2ns|0.603| 0.00578|0|3.8 KB| |#5732|`AllCycleSimpleBody`|net6.0|71.1μs|111ns|429ns|0.0705| 0|0|6.01 KB| |#5732|`AllCycleSimpleBody`|netcoreapp3.1|60.6μs|87.3ns|338ns|0.0901| 0|0|6.95 KB| |#5732|`AllCycleSimpleBody`|net472|47.3μs|31.9ns|110ns|1.32| 0|0|8.34 KB| |#5732|`AllCycleMoreComplexBody`|net6.0|77.4μs|56.9ns|213ns|0.117| 0|0|9.51 KB| |#5732|`AllCycleMoreComplexBody`|netcoreapp3.1|68.3μs|69.9ns|271ns|0.136| 0|0|10.37 KB| |#5732|`AllCycleMoreComplexBody`|net472|53.8μs|46.9ns|181ns|1.86| 0.027|0|11.85 KB| |#5732|`ObjectExtractorSimpleBody`|net6.0|145ns|0.178ns|0.667ns|0.00392| 0|0|280 B| |#5732|`ObjectExtractorSimpleBody`|netcoreapp3.1|204ns|0.246ns|0.919ns|0.00366| 0|0|272 B| |#5732|`ObjectExtractorSimpleBody`|net472|171ns|0.123ns|0.477ns|0.0446| 0|0|281 B| |#5732|`ObjectExtractorMoreComplexBody`|net6.0|3.07μs|2.69ns|10.1ns|0.0525| 0|0|3.78 KB| |#5732|`ObjectExtractorMoreComplexBody`|netcoreapp3.1|3.99μs|1.76ns|6.83ns|0.0497| 0|0|3.69 KB| |#5732|`ObjectExtractorMoreComplexBody`|net472|3.87μs|2.77ns|10.4ns|0.603| 0.00579|0|3.8 KB|
Benchmarks.Trace.Asm.AppSecEncoderBenchmark - Same speed :heavy_check_mark: Same allocations :heavy_check_mark: ### Raw results | Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------|---------------------------- |-------------- |---------:|---------:|--------:|-------:|------:|------:|----------:| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`EncodeArgs`|net6.0|38μs|14.2ns|53ns|0.452| 0|0|32.4 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`EncodeArgs`|netcoreapp3.1|54.2μs|18ns|67.5ns|0.433| 0|0|32.4 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`EncodeArgs`|net472|68μs|52.7ns|204ns|5.15| 0.0673|0|32.5 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`EncodeLegacyArgs`|net6.0|77.1μs|371ns|1.48μs|0.0386| 0|0|2.14 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`EncodeLegacyArgs`|netcoreapp3.1|105μs|113ns|422ns|0| 0|0|2.15 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`EncodeLegacyArgs`|net472|156μs|50.6ns|196ns|0.311| 0|0|2.15 KB| |#5732|`EncodeArgs`|net6.0|38.5μs|23.3ns|87.4ns|0.458| 0|0|32.4 KB| |#5732|`EncodeArgs`|netcoreapp3.1|55.1μs|29.4ns|110ns|0.438| 0|0|32.4 KB| |#5732|`EncodeArgs`|net472|67.4μs|61.2ns|237ns|5.15| 0.0673|0|32.5 KB| |#5732|`EncodeLegacyArgs`|net6.0|80.9μs|116ns|451ns|0| 0|0|2.14 KB| |#5732|`EncodeLegacyArgs`|netcoreapp3.1|105μs|81.3ns|315ns|0| 0|0|2.14 KB| |#5732|`EncodeLegacyArgs`|net472|156μs|91.2ns|353ns|0.311| 0|0|2.15 KB|
Benchmarks.Trace.Asm.AppSecWafBenchmark - Same speed :heavy_check_mark: Same allocations :heavy_check_mark: ### Raw results | Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------|---------------------------- |-------------- |---------:|---------:|--------:|-------:|------:|------:|----------:| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`RunWafRealisticBenchmark`|net6.0|181μs|57.4ns|215ns|0| 0|0|2.42 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`RunWafRealisticBenchmark`|netcoreapp3.1|193μs|84.5ns|327ns|0| 0|0|2.37 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`RunWafRealisticBenchmark`|net472|207μs|36.9ns|138ns|0.309| 0|0|2.43 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`RunWafRealisticBenchmarkWithAttack`|net6.0|122μs|135ns|524ns|0| 0|0|1.46 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`RunWafRealisticBenchmarkWithAttack`|netcoreapp3.1|129μs|142ns|549ns|0| 0|0|1.45 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`RunWafRealisticBenchmarkWithAttack`|net472|139μs|33.6ns|126ns|0.209| 0|0|1.48 KB| |#5732|`RunWafRealisticBenchmark`|net6.0|184μs|60.1ns|217ns|0| 0|0|2.42 KB| |#5732|`RunWafRealisticBenchmark`|netcoreapp3.1|193μs|97.8ns|353ns|0| 0|0|2.37 KB| |#5732|`RunWafRealisticBenchmark`|net472|210μs|106ns|412ns|0.312| 0|0|2.43 KB| |#5732|`RunWafRealisticBenchmarkWithAttack`|net6.0|123μs|81ns|314ns|0| 0|0|1.46 KB| |#5732|`RunWafRealisticBenchmarkWithAttack`|netcoreapp3.1|131μs|207ns|776ns|0| 0|0|1.45 KB| |#5732|`RunWafRealisticBenchmarkWithAttack`|net472|140μs|60.1ns|225ns|0.21| 0|0|1.48 KB|
Benchmarks.Trace.Iast.StringAspectsBenchmark - Slower :warning: More allocations :warning: #### Slower :warning: in #5732 | Benchmark | diff/base | Base Median (ns) | Diff Median (ns) | Modality | |:----------|-----------:|-----------:|--------:|--------:| | Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark‑net6.0 | 1.166 | 278,600.00 | 324,900.00 | #### Faster :tada: in #5732 | Benchmark | base/diff | Base Median (ns) | Diff Median (ns) | Modality | |:----------|-----------:|-----------:|--------:|--------:| | Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark‑netcoreapp3.1 | 1.205 | 328,000.00 | 272,100.00 | #### More allocations :warning: in #5732 | Benchmark | Base Allocated | Diff Allocated | Change | Change % | |:----------|-----------:|-----------:|--------:|--------:| | Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark‑netcoreapp3.1 | 253.9 KB | 256.3 KB | 2.4 KB | 0.95% | Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark‑net6.0 | 254.22 KB | 255.74 KB | 1.52 KB | 0.60% #### Fewer allocations :tada: in #5732 | Benchmark | Base Allocated | Diff Allocated | Change | Change % | |:----------|-----------:|-----------:|--------:|--------:| | Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark‑net472 | 62.16 KB | 59.19 KB | -2.97 KB | -4.77% ### Raw results | Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------|---------------------------- |-------------- |---------:|---------:|--------:|-------:|------:|------:|----------:| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`StringConcatBenchmark`|net6.0|58.2μs|739ns|7.13μs|0| 0|0|43.44 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`StringConcatBenchmark`|netcoreapp3.1|53.5μs|258ns|999ns|0| 0|0|42.64 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`StringConcatBenchmark`|net472|37.5μs|104ns|389ns|0| 0|0|62.16 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`StringConcatAspectBenchmark`|net6.0|298μs|6.69μs|66.2μs|0| 0|0|254.22 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`StringConcatAspectBenchmark`|netcoreapp3.1|334μs|1.9μs|13.9μs|0| 0|0|253.9 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`StringConcatAspectBenchmark`|net472|284μs|4μs|38.3μs|0| 0|0|278.53 KB| |#5732|`StringConcatBenchmark`|net6.0|51.9μs|234ns|874ns|0| 0|0|43.44 KB| |#5732|`StringConcatBenchmark`|netcoreapp3.1|54.4μs|262ns|1.08μs|0| 0|0|42.64 KB| |#5732|`StringConcatBenchmark`|net472|38μs|140ns|561ns|0| 0|0|59.19 KB| |#5732|`StringConcatAspectBenchmark`|net6.0|331μs|1.88μs|13.2μs|0| 0|0|255.74 KB| |#5732|`StringConcatAspectBenchmark`|netcoreapp3.1|294μs|4.7μs|45.5μs|0| 0|0|256.3 KB| |#5732|`StringConcatAspectBenchmark`|net472|298μs|7.11μs|68.9μs|0| 0|0|278.53 KB|
andrewlock commented 1 week ago

Benchmarks Report for tracer :snail:

Benchmarks for #5732 compared to master:

The following thresholds were used for comparing the benchmark speeds:

Allocation changes below 0.5% are ignored.

Benchmark details

Benchmarks.Trace.ActivityBenchmark - Same speed :heavy_check_mark: Same allocations :heavy_check_mark: ### Raw results | Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------|---------------------------- |-------------- |---------:|---------:|--------:|-------:|------:|------:|----------:| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`StartStopWithChild`|net6.0|7.78μs|43.6ns|279ns|0.0154| 0.00768|0|5.42 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`StartStopWithChild`|netcoreapp3.1|9.78μs|52.8ns|280ns|0.0241| 0.00963|0|5.62 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`StartStopWithChild`|net472|16μs|49ns|190ns|1.01| 0.293|0.0952|6.07 KB| |#5732|`StartStopWithChild`|net6.0|7.69μs|44.9ns|397ns|0.0119| 0.00398|0|5.43 KB| |#5732|`StartStopWithChild`|netcoreapp3.1|9.93μs|56.1ns|381ns|0.0202| 0.0101|0|5.62 KB| |#5732|`StartStopWithChild`|net472|16μs|47.9ns|186ns|1.03| 0.299|0.105|6.06 KB|
Benchmarks.Trace.AgentWriterBenchmark - Same speed :heavy_check_mark: Same allocations :heavy_check_mark: ### Raw results | Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------|---------------------------- |-------------- |---------:|---------:|--------:|-------:|------:|------:|----------:| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`WriteAndFlushEnrichedTraces`|net6.0|489μs|145ns|563ns|0| 0|0|2.7 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`WriteAndFlushEnrichedTraces`|netcoreapp3.1|640μs|294ns|1.14μs|0| 0|0|2.7 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`WriteAndFlushEnrichedTraces`|net472|838μs|306ns|1.19μs|0.414| 0|0|3.3 KB| |#5732|`WriteAndFlushEnrichedTraces`|net6.0|464μs|244ns|913ns|0| 0|0|2.7 KB| |#5732|`WriteAndFlushEnrichedTraces`|netcoreapp3.1|643μs|127ns|474ns|0| 0|0|2.7 KB| |#5732|`WriteAndFlushEnrichedTraces`|net472|832μs|344ns|1.33μs|0.414| 0|0|3.3 KB|
Benchmarks.Trace.AspNetCoreBenchmark - Same speed :heavy_check_mark: Same allocations :heavy_check_mark: ### Raw results | Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------|---------------------------- |-------------- |---------:|---------:|--------:|-------:|------:|------:|----------:| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`SendRequest`|net6.0|170μs|229ns|886ns|0.168| 0|0|18.44 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`SendRequest`|netcoreapp3.1|191μs|299ns|1.16μs|0.192| 0|0|20.6 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`SendRequest`|net472|0.000295ns|0.000179ns|0.000692ns|0| 0|0|0 b| |#5732|`SendRequest`|net6.0|171μs|160ns|621ns|0.171| 0|0|18.45 KB| |#5732|`SendRequest`|netcoreapp3.1|194μs|286ns|1.11μs|0.194| 0|0|20.61 KB| |#5732|`SendRequest`|net472|0.000656ns|0.000214ns|0.0008ns|0| 0|0|0 b|
Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark - Same speed :heavy_check_mark: Same allocations :heavy_check_mark: ### Raw results | Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------|---------------------------- |-------------- |---------:|---------:|--------:|-------:|------:|------:|----------:| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`WriteAndFlushEnrichedTraces`|net6.0|547μs|312ns|1.12μs|0.543| 0|0|41.65 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`WriteAndFlushEnrichedTraces`|netcoreapp3.1|664μs|946ns|3.67μs|0.332| 0|0|41.89 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`WriteAndFlushEnrichedTraces`|net472|852μs|3.28μs|12.7μs|8.36| 2.64|0.44|53.25 KB| |#5732|`WriteAndFlushEnrichedTraces`|net6.0|558μs|589ns|2.28μs|0.548| 0|0|41.63 KB| |#5732|`WriteAndFlushEnrichedTraces`|netcoreapp3.1|651μs|1.66μs|6.43μs|0.326| 0|0|41.77 KB| |#5732|`WriteAndFlushEnrichedTraces`|net472|872μs|4.34μs|19.4μs|8.19| 2.59|0.431|53.25 KB|
Benchmarks.Trace.DbCommandBenchmark - Slower :warning: Same allocations :heavy_check_mark: #### Slower :warning: in #5732 | Benchmark | diff/base | Base Median (ns) | Diff Median (ns) | Modality | |:----------|-----------:|-----------:|--------:|--------:| | Benchmarks.Trace.DbCommandBenchmark.ExecuteNonQuery‑net6.0 | 1.145 | 1,000.09 | 1,145.37 | ### Raw results | Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------|---------------------------- |-------------- |---------:|---------:|--------:|-------:|------:|------:|----------:| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`ExecuteNonQuery`|net6.0|1μs|0.463ns|1.79ns|0.011| 0|0|808 B| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`ExecuteNonQuery`|netcoreapp3.1|1.48μs|0.933ns|3.61ns|0.011| 0|0|808 B| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`ExecuteNonQuery`|net472|1.74μs|0.748ns|2.9ns|0.122| 0|0|770 B| |#5732|`ExecuteNonQuery`|net6.0|1.15μs|0.493ns|1.91ns|0.011| 0|0|808 B| |#5732|`ExecuteNonQuery`|netcoreapp3.1|1.54μs|0.881ns|3.41ns|0.0107| 0|0|808 B| |#5732|`ExecuteNonQuery`|net472|1.63μs|1.74ns|6.49ns|0.122| 0|0|770 B|
Benchmarks.Trace.ElasticsearchBenchmark - Same speed :heavy_check_mark: Same allocations :heavy_check_mark: ### Raw results | Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------|---------------------------- |-------------- |---------:|---------:|--------:|-------:|------:|------:|----------:| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`CallElasticsearch`|net6.0|1.23μs|0.499ns|1.93ns|0.0141| 0|0|976 B| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`CallElasticsearch`|netcoreapp3.1|1.48μs|0.716ns|2.58ns|0.0134| 0|0|976 B| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`CallElasticsearch`|net472|2.43μs|1.49ns|5.77ns|0.157| 0.00121|0|995 B| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`CallElasticsearchAsync`|net6.0|1.23μs|1.16ns|4.34ns|0.0131| 0|0|952 B| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`CallElasticsearchAsync`|netcoreapp3.1|1.62μs|0.763ns|2.85ns|0.0138| 0|0|1.02 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`CallElasticsearchAsync`|net472|2.65μs|1.89ns|7.33ns|0.167| 0.00132|0|1.05 KB| |#5732|`CallElasticsearch`|net6.0|1.2μs|0.399ns|1.49ns|0.0139| 0|0|976 B| |#5732|`CallElasticsearch`|netcoreapp3.1|1.58μs|0.429ns|1.55ns|0.0134| 0|0|976 B| |#5732|`CallElasticsearch`|net472|2.44μs|2.55ns|9.89ns|0.158| 0.00122|0|995 B| |#5732|`CallElasticsearchAsync`|net6.0|1.34μs|0.551ns|2.14ns|0.0134| 0|0|952 B| |#5732|`CallElasticsearchAsync`|netcoreapp3.1|1.63μs|1.33ns|4.97ns|0.0131| 0|0|1.02 KB| |#5732|`CallElasticsearchAsync`|net472|2.61μs|1.99ns|7.72ns|0.166| 0|0|1.05 KB|
Benchmarks.Trace.GraphQLBenchmark - Faster :tada: Same allocations :heavy_check_mark: #### Faster :tada: in #5732 | Benchmark | base/diff | Base Median (ns) | Diff Median (ns) | Modality | |:----------|-----------:|-----------:|--------:|--------:| | Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync‑netcoreapp3.1 | 1.117 | 1,679.65 | 1,503.81 | ### Raw results | Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------|---------------------------- |-------------- |---------:|---------:|--------:|-------:|------:|------:|----------:| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`ExecuteAsync`|net6.0|1.22μs|0.474ns|1.84ns|0.0135| 0|0|952 B| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`ExecuteAsync`|netcoreapp3.1|1.68μs|2.5ns|9.69ns|0.0126| 0|0|952 B| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`ExecuteAsync`|net472|1.78μs|1.12ns|4.32ns|0.145| 0|0|915 B| |#5732|`ExecuteAsync`|net6.0|1.25μs|0.302ns|1.09ns|0.0131| 0|0|952 B| |#5732|`ExecuteAsync`|netcoreapp3.1|1.5μs|0.804ns|3.11ns|0.0128| 0|0|952 B| |#5732|`ExecuteAsync`|net472|1.81μs|1.9ns|7.38ns|0.145| 0|0|915 B|
Benchmarks.Trace.HttpClientBenchmark - Same speed :heavy_check_mark: Same allocations :heavy_check_mark: ### Raw results | Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------|---------------------------- |-------------- |---------:|---------:|--------:|-------:|------:|------:|----------:| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`SendAsync`|net6.0|4.22μs|2.32ns|8.99ns|0.0295| 0|0|2.22 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`SendAsync`|netcoreapp3.1|5.12μs|2.73ns|10.2ns|0.0382| 0|0|2.76 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`SendAsync`|net472|7.52μs|1.46ns|5.45ns|0.499| 0|0|3.15 KB| |#5732|`SendAsync`|net6.0|4.1μs|2.39ns|8.63ns|0.0309| 0|0|2.22 KB| |#5732|`SendAsync`|netcoreapp3.1|5.08μs|1.35ns|4.86ns|0.0355| 0|0|2.76 KB| |#5732|`SendAsync`|net472|7.7μs|10.7ns|41.4ns|0.497| 0|0|3.15 KB|
Benchmarks.Trace.ILoggerBenchmark - Same speed :heavy_check_mark: Same allocations :heavy_check_mark: ### Raw results | Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------|---------------------------- |-------------- |---------:|---------:|--------:|-------:|------:|------:|----------:| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`EnrichedLog`|net6.0|1.61μs|0.474ns|1.71ns|0.0226| 0|0|1.64 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`EnrichedLog`|netcoreapp3.1|2.1μs|0.702ns|2.63ns|0.0221| 0|0|1.64 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`EnrichedLog`|net472|2.62μs|1.87ns|7.01ns|0.25| 0|0|1.57 KB| |#5732|`EnrichedLog`|net6.0|1.6μs|1.32ns|4.95ns|0.0231| 0|0|1.64 KB| |#5732|`EnrichedLog`|netcoreapp3.1|2.17μs|1.27ns|4.91ns|0.0218| 0|0|1.64 KB| |#5732|`EnrichedLog`|net472|2.64μs|1.29ns|4.66ns|0.249| 0|0|1.57 KB|
Benchmarks.Trace.Log4netBenchmark - Same speed :heavy_check_mark: Same allocations :heavy_check_mark: ### Raw results | Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------|---------------------------- |-------------- |---------:|---------:|--------:|-------:|------:|------:|----------:| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`EnrichedLog`|net6.0|114μs|261ns|1.01μs|0.057| 0|0|4.28 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`EnrichedLog`|netcoreapp3.1|119μs|188ns|726ns|0.0605| 0|0|4.28 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`EnrichedLog`|net472|147μs|97.3ns|377ns|0.658| 0.219|0|4.46 KB| |#5732|`EnrichedLog`|net6.0|115μs|196ns|734ns|0| 0|0|4.28 KB| |#5732|`EnrichedLog`|netcoreapp3.1|119μs|298ns|1.15μs|0| 0|0|4.28 KB| |#5732|`EnrichedLog`|net472|147μs|81.2ns|304ns|0.659| 0.22|0|4.46 KB|
Benchmarks.Trace.NLogBenchmark - Same speed :heavy_check_mark: Same allocations :heavy_check_mark: ### Raw results | Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------|---------------------------- |-------------- |---------:|---------:|--------:|-------:|------:|------:|----------:| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`EnrichedLog`|net6.0|2.93μs|0.882ns|3.42ns|0.0304| 0|0|2.2 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`EnrichedLog`|netcoreapp3.1|4.1μs|1.35ns|4.86ns|0.0288| 0|0|2.2 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`EnrichedLog`|net472|4.87μs|5.57ns|19.3ns|0.32| 0|0|2.02 KB| |#5732|`EnrichedLog`|net6.0|2.87μs|0.871ns|3.26ns|0.0303| 0|0|2.2 KB| |#5732|`EnrichedLog`|netcoreapp3.1|4.22μs|1.05ns|3.91ns|0.0295| 0|0|2.2 KB| |#5732|`EnrichedLog`|net472|4.84μs|2.51ns|9.4ns|0.319| 0|0|2.02 KB|
Benchmarks.Trace.RedisBenchmark - Same speed :heavy_check_mark: Same allocations :heavy_check_mark: ### Raw results | Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------|---------------------------- |-------------- |---------:|---------:|--------:|-------:|------:|------:|----------:| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`SendReceive`|net6.0|1.32μs|0.73ns|2.73ns|0.0159| 0|0|1.14 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`SendReceive`|netcoreapp3.1|1.74μs|1.63ns|6.32ns|0.0149| 0|0|1.14 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`SendReceive`|net472|1.98μs|1.51ns|5.67ns|0.183| 0.000988|0|1.16 KB| |#5732|`SendReceive`|net6.0|1.27μs|0.848ns|3.28ns|0.016| 0|0|1.14 KB| |#5732|`SendReceive`|netcoreapp3.1|1.73μs|1.26ns|4.89ns|0.0146| 0|0|1.14 KB| |#5732|`SendReceive`|net472|1.99μs|0.884ns|3.43ns|0.184| 0|0|1.16 KB|
Benchmarks.Trace.SerilogBenchmark - Same speed :heavy_check_mark: Same allocations :heavy_check_mark: ### Raw results | Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------|---------------------------- |-------------- |---------:|---------:|--------:|-------:|------:|------:|----------:| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`EnrichedLog`|net6.0|2.76μs|0.51ns|1.91ns|0.022| 0|0|1.6 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`EnrichedLog`|netcoreapp3.1|3.83μs|2.96ns|11.1ns|0.0226| 0|0|1.65 KB| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`EnrichedLog`|net472|4.34μs|1.34ns|5.02ns|0.323| 0|0|2.04 KB| |#5732|`EnrichedLog`|net6.0|2.68μs|1.08ns|4.17ns|0.0228| 0|0|1.6 KB| |#5732|`EnrichedLog`|netcoreapp3.1|3.83μs|8.56ns|33.1ns|0.021| 0|0|1.65 KB| |#5732|`EnrichedLog`|net472|4.29μs|2.44ns|9.45ns|0.324| 0|0|2.04 KB|
Benchmarks.Trace.SpanBenchmark - Slower :warning: Same allocations :heavy_check_mark: #### Slower :warning: in #5732 | Benchmark | diff/base | Base Median (ns) | Diff Median (ns) | Modality | |:----------|-----------:|-----------:|--------:|--------:| | Benchmarks.Trace.SpanBenchmark.StartFinishScope‑netcoreapp3.1 | 1.134 | 703.33 | 797.81 | ### Raw results | Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------|---------------------------- |-------------- |---------:|---------:|--------:|-------:|------:|------:|----------:| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`StartFinishSpan`|net6.0|403ns|0.338ns|1.31ns|0.0081| 0|0|576 B| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`StartFinishSpan`|netcoreapp3.1|602ns|0.431ns|1.55ns|0.00789| 0|0|576 B| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`StartFinishSpan`|net472|686ns|0.62ns|2.4ns|0.0915| 0|0|578 B| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`StartFinishScope`|net6.0|551ns|0.815ns|3.16ns|0.00967| 0|0|696 B| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`StartFinishScope`|netcoreapp3.1|703ns|0.375ns|1.45ns|0.00948| 0|0|696 B| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`StartFinishScope`|net472|869ns|0.795ns|3.08ns|0.105| 0|0|658 B| |#5732|`StartFinishSpan`|net6.0|388ns|0.281ns|1.05ns|0.00806| 0|0|576 B| |#5732|`StartFinishSpan`|netcoreapp3.1|568ns|0.622ns|2.41ns|0.00785| 0|0|576 B| |#5732|`StartFinishSpan`|net472|660ns|1.81ns|7.01ns|0.0915| 0|0|578 B| |#5732|`StartFinishScope`|net6.0|529ns|0.221ns|0.855ns|0.00962| 0|0|696 B| |#5732|`StartFinishScope`|netcoreapp3.1|799ns|0.832ns|3.22ns|0.00956| 0|0|696 B| |#5732|`StartFinishScope`|net472|824ns|0.538ns|2.09ns|0.104| 0|0|658 B|
Benchmarks.Trace.TraceAnnotationsBenchmark - Same speed :heavy_check_mark: Same allocations :heavy_check_mark: ### Raw results | Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | |---------|---------------------------- |-------------- |---------:|---------:|--------:|-------:|------:|------:|----------:| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`RunOnMethodBegin`|net6.0|607ns|0.164ns|0.636ns|0.00971| 0|0|696 B| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`RunOnMethodBegin`|netcoreapp3.1|882ns|0.563ns|2.1ns|0.0093| 0|0|696 B| |[master](https://github.com/DataDog/dd-trace-dotnet/tree/0f17e5756636c7ced13cdd7d003fe6dbca1039dc)|`RunOnMethodBegin`|net472|1.04μs|0.653ns|2.53ns|0.104| 0|0|658 B| |#5732|`RunOnMethodBegin`|net6.0|659ns|0.515ns|1.99ns|0.00964| 0|0|696 B| |#5732|`RunOnMethodBegin`|netcoreapp3.1|862ns|0.764ns|2.96ns|0.00954| 0|0|696 B| |#5732|`RunOnMethodBegin`|net472|1.08μs|0.747ns|2.69ns|0.104| 0|0|658 B|
robertpi commented 1 week ago

Under such circumstances, we should capture the exception and return null, same as we do in that method when the context is null.

So this method only occurs if there's no HTTP context available? We're starting to see it because the data gathered in RASP doesn't necessarily require a HTTP context (where as most WAF data does).

NachoEchevarria commented 1 week ago

Under such circumstances, we should capture the exception and return null, same as we do in that method when the context is null.

So this method only occurs if there's no HTTP context available? We're starting to see it because the data gathered in RASP doesn't necessarily require a HTTP context (where as most WAF data does).

The error would occur when there is no valid context. For instance, if the request has finished and the context is not valid. The method Uninitialize() can be called to reset the context and reuse it for a new query.

NachoEchevarria commented 1 week ago

This feels like a case of addressing the symptoms instead of the cause, and we see many more symptoms of this 🤔 My real concern is why are we accessing the HttpContext after the request has finished? AFAIK Uninitialize() is only called after the aspnetcore pipeline has completely finished, so I think we need to work out when and where that is happening? 🤔

We are instrumenting methods that access files. These methods might be called after the request has finished in some cases. If a file operation is performed, we will be called even if the request is finished or we are in a console app. I wonder if maybe we can use rootSpan.IsFinished as a way to check if the request has finished. AFAIK, if the request has finished, the root span should have finished as well. Still, I think that we should be protected against this situations. Maybe write a warning message? We should filter our instrumentations as much as possible to avoid these cases anyway.

andrewlock commented 1 week ago

AFAIK, if the request has finished, the root span should have finished as well

Normally, but not necessarily, e.g. customers could create "root" spans that are the root of all requests 🤔

Still, I think that we should be protected against this situations

I agree 100%, but I think a preferable approach is to not "assume" there is an HttpContext 🤔 Fundamentally it's unsafe to access HttpContext outside of that context (+ HttpContext is not thread safe) so we'll potentially get all sorts of errors, not just ObjectDisposedExceptions (we already have a bunch of NullReferenceExceptions related to this pattern too)

Simply put, I think we need to find a completely different mechanism for attaching this data if we don't know whether an HttpContext is available (rather than "access it and see what happens") 🤔

Maybe write a warning message

This seems like one of the cases where it could happen a lot, and we end up with a lot of warnings. Plus it's not clear that the customer can do anything about it - it's an error on our part, right? - so I'm not sure it adds much value

NachoEchevarria commented 5 days ago

AFAIK, if the request has finished, the root span should have finished as well

Normally, but not necessarily, e.g. customers could create "root" spans that are the root of all requests 🤔

Still, I think that we should be protected against this situations

I agree 100%, but I think a preferable approach is to not "assume" there is an HttpContext 🤔 Fundamentally it's unsafe to access HttpContext outside of that context (+ HttpContext is not thread safe) so we'll potentially get all sorts of errors, not just ObjectDisposedExceptions (we already have a bunch of NullReferenceExceptions related to this pattern too)

Simply put, I think we need to find a completely different mechanism for attaching this data if we don't know whether an HttpContext is available (rather than "access it and see what happens") 🤔

Maybe write a warning message

This seems like one of the cases where it could happen a lot, and we end up with a lot of warnings. Plus it's not clear that the customer can do anything about it - it's an error on our part, right? - so I'm not sure it adds much value

After thinking about it, I have added more checks to ensure that we are inside a request without actually accessing the httpContext. Since I was not able to reproduce this particular error, we will need to see how this change affects to this particular exception. If the exception is thrown, it will still be reported as an error.

NachoEchevarria commented 4 days ago

Thanks for your comments and reviews!