[Exception Replay] Added test suite for ASP.NET Core (#5821 -> v2)#5970
Conversation
| namespace Datadog.Trace.Debugger.IntegrationTests | ||
| { | ||
| [UsesVerify] | ||
| public class AspNetBase : TestHelper |
There was a problem hiding this comment.
🔵 Code Quality Violation
class with a Dispose() method must implement IDisposable (...read more)
IDisposable provides an interface for the cleanup of unmanaged resources through the function void Dispose().
To avoid confusion, this rule ensures that any class that exposes a public void Dispose() function must implement IDisposable.
Learn More
| } | ||
| } | ||
|
|
||
| public abstract class AspNetCore5ExceptionReplay : AspNetBase, IClassFixture<AspNetCoreTestFixture> |
There was a problem hiding this comment.
🔵 Code Quality Violation
class with a Dispose() method must implement IDisposable (...read more)
IDisposable provides an interface for the cleanup of unmanaged resources through the function void Dispose().
To avoid confusion, this rule ensures that any class that exposes a public void Dispose() function must implement IDisposable.
Learn More
| } | ||
| } | ||
|
|
||
| public class AspNetCore5ExceptionReplayEnabledDynamicInstrumentationEnabled_FullCallStack : AspNetCore5ExceptionReplay |
There was a problem hiding this comment.
⚪ Code Quality Violation
The name does not comply with naming convention (...read more)
Class names should use the PascalCase and start with an uppercase.
Learn More
| } | ||
| } | ||
|
|
||
| public class AspNetCore5ExceptionReplayEnabledDynamicInstrumentationDisabled_FullCallStack : AspNetCore5ExceptionReplay |
There was a problem hiding this comment.
⚪ Code Quality Violation
The name does not comply with naming convention (...read more)
Class names should use the PascalCase and start with an uppercase.
Learn More
|
|
||
| ref struct PingPonged | ||
| { | ||
| public static async Task<int> Me(Func<int, Task<int>> method, int iteration) |
There was a problem hiding this comment.
⚪ Code Quality Violation
Avoid short method names under 3 characters (...read more)
Method names should be descriptive of the function behavior and functionalities. Instead of using a very short name, always have a name that indicates what the function is doing.
Learn More
|
|
||
| ref struct PingPonged | ||
| { | ||
| public static async Task<int> Me(Func<int, Task<int>> method, int iteration) |
There was a problem hiding this comment.
⚪ Code Quality Violation
Avoid short method names under 3 characters (...read more)
Method names should be descriptive of the function behavior and functionalities. Instead of using a very short name, always have a name that indicates what the function is doing.
Learn More
| private static readonly string[] KnownClassNamesToRemoveFromExceptionReplayFrame = { "<<Configure>b__5_2>d" }; | ||
|
|
||
| // This class is used to test Exception Replay with Dynamic Instrumentation enabled or disabled. | ||
| public AspNetCore5ExceptionReplay(AspNetCoreTestFixture fixture, ITestOutputHelper outputHelper, bool enableDynamicInstrumentation, bool captureFullCallStack) |
There was a problem hiding this comment.
⚪ Code Quality Violation
View all suggested fixes
| public AspNetCore5ExceptionReplay(AspNetCoreTestFixture fixture, ITestOutputHelper outputHelper, bool enableDynamicInstrumentation, bool captureFullCallStack) | |
| private AspNetCore5ExceptionReplay(AspNetCoreTestFixture fixture, ITestOutputHelper outputHelper, bool enableDynamicInstrumentation, bool captureFullCallStack) |
| public AspNetCore5ExceptionReplay(AspNetCoreTestFixture fixture, ITestOutputHelper outputHelper, bool enableDynamicInstrumentation, bool captureFullCallStack) | |
| protected AspNetCore5ExceptionReplay(AspNetCoreTestFixture fixture, ITestOutputHelper outputHelper, bool enableDynamicInstrumentation, bool captureFullCallStack) |
| public AspNetCore5ExceptionReplay(AspNetCoreTestFixture fixture, ITestOutputHelper outputHelper, bool enableDynamicInstrumentation, bool captureFullCallStack) | |
| private protected AspNetCore5ExceptionReplay(AspNetCoreTestFixture fixture, ITestOutputHelper outputHelper, bool enableDynamicInstrumentation, bool captureFullCallStack) |
avoid using public for constructor in abstract class (...read more)
Using an abstract modifier in a class declaration indicates that a class is intended only to be a base class of other classes and not instantiated by itself. Due to this, there is no need for public or internal constructors within. Any initialization logic should be added in a private,private protected, or protected constructor.
| await asyncRun.RunAsync(); | ||
| break; | ||
| default: | ||
| throw new Exception($"Test class not found: {testClassName}"); |
There was a problem hiding this comment.
| return true; | ||
| } | ||
|
|
||
| if (tag.Key.EndsWith(classNameSuffix) && tag.Value.StartsWith("<")) |
There was a problem hiding this comment.
🟠 Code Quality Violation
| if (tag.Key.EndsWith(classNameSuffix) && tag.Value.StartsWith("<")) | |
| if (tag.Key.EndsWith(classNameSuffix) && tag.Value.StartsWith('<')) |
use a character, not a string (...read more)
This rule is designed to ensure that you use the most efficient methods for string comparison in C#. When using the StartsWith or EndsWith methods with a single character, the performance can be significantly reduced compared to using the indexer with the first or last index. This is because these methods are designed to work with substrings, not single characters, and therefore involve unnecessary overhead when used in this way.
The importance of this rule lies in writing efficient and performant code. In large-scale applications, using inefficient methods for string comparison can lead to noticeable performance issues. Therefore, it's crucial to use the appropriate methods for each specific use-case.
Learn More
| ref MeRefStruct NotSupportedFrame(string str) | ||
| { | ||
| SupportedFrame(str); | ||
| throw new Exception(); |
There was a problem hiding this comment.
| namespace Datadog.Trace.Debugger.IntegrationTests | ||
| { | ||
| [UsesVerify] | ||
| public class AspNetBase : TestHelper |
There was a problem hiding this comment.
🔵 Code Quality Violation
class with a Dispose() method must implement IDisposable (...read more)
IDisposable provides an interface for the cleanup of unmanaged resources through the function void Dispose().
To avoid confusion, this rule ensures that any class that exposes a public void Dispose() function must implement IDisposable.
Learn More
| } | ||
| } | ||
|
|
||
| public abstract class AspNetCore5ExceptionReplay : AspNetBase, IClassFixture<AspNetCoreTestFixture> |
There was a problem hiding this comment.
🔵 Code Quality Violation
class with a Dispose() method must implement IDisposable (...read more)
IDisposable provides an interface for the cleanup of unmanaged resources through the function void Dispose().
To avoid confusion, this rule ensures that any class that exposes a public void Dispose() function must implement IDisposable.
Learn More
| } | ||
| } | ||
|
|
||
| public class AspNetCore5ExceptionReplayEnabledDynamicInstrumentationEnabled_FullCallStack : AspNetCore5ExceptionReplay |
There was a problem hiding this comment.
⚪ Code Quality Violation
The name does not comply with naming convention (...read more)
Class names should use the PascalCase and start with an uppercase.
Learn More
| } | ||
| } | ||
|
|
||
| public class AspNetCore5ExceptionReplayEnabledDynamicInstrumentationDisabled_FullCallStack : AspNetCore5ExceptionReplay |
There was a problem hiding this comment.
⚪ Code Quality Violation
The name does not comply with naming convention (...read more)
Class names should use the PascalCase and start with an uppercase.
Learn More
|
|
||
| ref struct PingPonged | ||
| { | ||
| public static async Task<int> Me(Func<int, Task<int>> method, int iteration) |
There was a problem hiding this comment.
⚪ Code Quality Violation
Avoid short method names under 3 characters (...read more)
Method names should be descriptive of the function behavior and functionalities. Instead of using a very short name, always have a name that indicates what the function is doing.
Learn More
|
|
||
| ref struct PingPonged | ||
| { | ||
| public static async Task<int> Me(Func<int, Task<int>> method, int iteration) |
There was a problem hiding this comment.
⚪ Code Quality Violation
Avoid short method names under 3 characters (...read more)
Method names should be descriptive of the function behavior and functionalities. Instead of using a very short name, always have a name that indicates what the function is doing.
Learn More
| private static readonly string[] KnownClassNamesToRemoveFromExceptionReplayFrame = { "<<Configure>b__5_2>d" }; | ||
|
|
||
| // This class is used to test Exception Replay with Dynamic Instrumentation enabled or disabled. | ||
| public AspNetCore5ExceptionReplay(AspNetCoreTestFixture fixture, ITestOutputHelper outputHelper, bool enableDynamicInstrumentation, bool captureFullCallStack) |
There was a problem hiding this comment.
⚪ Code Quality Violation
View all suggested fixes
| public AspNetCore5ExceptionReplay(AspNetCoreTestFixture fixture, ITestOutputHelper outputHelper, bool enableDynamicInstrumentation, bool captureFullCallStack) | |
| private AspNetCore5ExceptionReplay(AspNetCoreTestFixture fixture, ITestOutputHelper outputHelper, bool enableDynamicInstrumentation, bool captureFullCallStack) |
| public AspNetCore5ExceptionReplay(AspNetCoreTestFixture fixture, ITestOutputHelper outputHelper, bool enableDynamicInstrumentation, bool captureFullCallStack) | |
| protected AspNetCore5ExceptionReplay(AspNetCoreTestFixture fixture, ITestOutputHelper outputHelper, bool enableDynamicInstrumentation, bool captureFullCallStack) |
| public AspNetCore5ExceptionReplay(AspNetCoreTestFixture fixture, ITestOutputHelper outputHelper, bool enableDynamicInstrumentation, bool captureFullCallStack) | |
| private protected AspNetCore5ExceptionReplay(AspNetCoreTestFixture fixture, ITestOutputHelper outputHelper, bool enableDynamicInstrumentation, bool captureFullCallStack) |
avoid using public for constructor in abstract class (...read more)
Using an abstract modifier in a class declaration indicates that a class is intended only to be a base class of other classes and not instantiated by itself. Due to this, there is no need for public or internal constructors within. Any initialization logic should be added in a private,private protected, or protected constructor.
| await asyncRun.RunAsync(); | ||
| break; | ||
| default: | ||
| throw new Exception($"Test class not found: {testClassName}"); |
There was a problem hiding this comment.
| return true; | ||
| } | ||
|
|
||
| if (tag.Key.EndsWith(classNameSuffix) && tag.Value.StartsWith("<")) |
There was a problem hiding this comment.
🟠 Code Quality Violation
| if (tag.Key.EndsWith(classNameSuffix) && tag.Value.StartsWith("<")) | |
| if (tag.Key.EndsWith(classNameSuffix) && tag.Value.StartsWith('<')) |
use a character, not a string (...read more)
This rule is designed to ensure that you use the most efficient methods for string comparison in C#. When using the StartsWith or EndsWith methods with a single character, the performance can be significantly reduced compared to using the indexer with the first or last index. This is because these methods are designed to work with substrings, not single characters, and therefore involve unnecessary overhead when used in this way.
The importance of this rule lies in writing efficient and performant code. In large-scale applications, using inefficient methods for string comparison can lead to noticeable performance issues. Therefore, it's crucial to use the appropriate methods for each specific use-case.
Learn More
| ref MeRefStruct NotSupportedFrame(string str) | ||
| { | ||
| SupportedFrame(str); | ||
| throw new Exception(); |
There was a problem hiding this comment.
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:
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 (5970) - mean (73ms) : 63, 83
. : milestone, 73,
section CallTarget+Inlining+NGEN
This PR (5970) - mean (1,034ms) : 1012, 1057
. : milestone, 1034,
gantt
title Execution time (ms) FakeDbCommand (.NET Core 3.1)
dateFormat X
axisFormat %s
todayMarker off
section Baseline
This PR (5970) - mean (109ms) : 106, 113
. : milestone, 109,
section CallTarget+Inlining+NGEN
This PR (5970) - mean (722ms) : 695, 750
. : milestone, 722,
gantt
title Execution time (ms) FakeDbCommand (.NET 6)
dateFormat X
axisFormat %s
todayMarker off
section Baseline
This PR (5970) - mean (96ms) : 89, 102
. : milestone, 96,
section CallTarget+Inlining+NGEN
This PR (5970) - mean (675ms) : 651, 700
. : milestone, 675,
gantt
title Execution time (ms) HttpMessageHandler (.NET Framework 4.6.2)
dateFormat X
axisFormat %s
todayMarker off
section Baseline
This PR (5970) - mean (190ms) : 188, 192
. : milestone, 190,
section CallTarget+Inlining+NGEN
This PR (5970) - mean (1,115ms) : 1095, 1136
. : milestone, 1115,
gantt
title Execution time (ms) HttpMessageHandler (.NET Core 3.1)
dateFormat X
axisFormat %s
todayMarker off
section Baseline
This PR (5970) - mean (276ms) : 271, 280
. : milestone, 276,
section CallTarget+Inlining+NGEN
This PR (5970) - mean (875ms) : 853, 898
. : milestone, 875,
gantt
title Execution time (ms) HttpMessageHandler (.NET 6)
dateFormat X
axisFormat %s
todayMarker off
section Baseline
This PR (5970) - mean (265ms) : 259, 270
. : milestone, 265,
section CallTarget+Inlining+NGEN
This PR (5970) - mean (872ms) : 853, 891
. : milestone, 872,
|
Datadog ReportBranch report: ✅ 0 Failed, 44 Passed, 0 Skipped, 28m 8.47s Total Time ⌛ Performance Regressions vs Default Branch (14)
|
Benchmarks Report for tracer 🐌Benchmarks for #5970 compared to master:
The following thresholds were used for comparing the benchmark speeds:
Allocation changes below 0.5% are ignored. Benchmark detailsBenchmarks.Trace.ActivityBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.AgentWriterBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.AspNetCoreBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.DbCommandBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.ElasticsearchBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.GraphQLBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.HttpClientBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.ILoggerBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.Log4netBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.NLogBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.RedisBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.SerilogBenchmark - Same speed ✔️ Same allocations ✔️Raw results
Benchmarks.Trace.SpanBenchmark - Slower
|
| Benchmark | diff/base | Base Median (ns) | Diff Median (ns) | Modality |
|---|---|---|---|---|
| Benchmarks.Trace.SpanBenchmark.StartFinishSpan‑net6.0 | 1.177 | 393.62 | 463.44 |
Raw results
| Branch | Method | Toolchain | Mean | StdError | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
|---|---|---|---|---|---|---|---|---|---|
| master | StartFinishSpan |
net6.0 | 394ns | 0.368ns | 1.43ns | 0.00814 | 0 | 0 | 576 B |
| master | StartFinishSpan |
netcoreapp3.1 | 547ns | 0.718ns | 2.68ns | 0.00782 | 0 | 0 | 576 B |
| master | StartFinishSpan |
net472 | 661ns | 0.274ns | 1.06ns | 0.0918 | 0 | 0 | 578 B |
| master | StartFinishScope |
net6.0 | 471ns | 0.169ns | 0.653ns | 0.00989 | 0 | 0 | 696 B |
| master | StartFinishScope |
netcoreapp3.1 | 742ns | 0.516ns | 2ns | 0.00932 | 0 | 0 | 696 B |
| master | StartFinishScope |
net472 | 854ns | 1.11ns | 4.31ns | 0.104 | 0 | 0 | 658 B |
| #5970 | StartFinishSpan |
net6.0 | 464ns | 0.362ns | 1.4ns | 0.00816 | 0 | 0 | 576 B |
| #5970 | StartFinishSpan |
netcoreapp3.1 | 549ns | 0.219ns | 0.847ns | 0.00799 | 0 | 0 | 576 B |
| #5970 | StartFinishSpan |
net472 | 694ns | 0.823ns | 3.19ns | 0.0916 | 0 | 0 | 578 B |
| #5970 | StartFinishScope |
net6.0 | 499ns | 0.275ns | 1.07ns | 0.00981 | 0 | 0 | 696 B |
| #5970 | StartFinishScope |
netcoreapp3.1 | 694ns | 0.371ns | 1.44ns | 0.0096 | 0 | 0 | 696 B |
| #5970 | StartFinishScope |
net472 | 847ns | 1.23ns | 4.76ns | 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 | 665ns | 0.486ns | 1.88ns | 0.00959 | 0 | 0 | 696 B |
| master | RunOnMethodBegin |
netcoreapp3.1 | 876ns | 0.816ns | 3.16ns | 0.00929 | 0 | 0 | 696 B |
| master | RunOnMethodBegin |
net472 | 1.12μs | 1.26ns | 4.86ns | 0.104 | 0 | 0 | 658 B |
| #5970 | RunOnMethodBegin |
net6.0 | 654ns | 0.588ns | 2.28ns | 0.00995 | 0 | 0 | 696 B |
| #5970 | RunOnMethodBegin |
netcoreapp3.1 | 912ns | 1.13ns | 4.37ns | 0.00929 | 0 | 0 | 696 B |
| #5970 | RunOnMethodBegin |
net472 | 1.12μs | 1.4ns | 5.41ns | 0.104 | 0 | 0 | 658 B |
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 (5970) (11.189M) : 0, 11188782
master (11.115M) : 0, 11114864
benchmarks/2.9.0 (11.120M) : 0, 11120231
section Automatic
This PR (5970) (7.511M) : 0, 7510928
master (7.311M) : 0, 7311158
benchmarks/2.9.0 (7.874M) : 0, 7874046
section Trace stats
master (7.660M) : 0, 7659733
section Manual
This PR (5970) (9.684M) : crit ,0, 9683897
master (11.297M) : 0, 11296697
section Manual + Automatic
This PR (5970) (7.079M) : 0, 7079074
master (6.770M) : 0, 6770096
gantt
title Throughput Linux arm64 (Total requests)
dateFormat X
axisFormat %s
section Baseline
This PR (5970) (9.661M) : 0, 9661049
benchmarks/2.9.0 (9.342M) : 0, 9341974
section Automatic
This PR (5970) (6.652M) : 0, 6651809
section Manual
This PR (5970) (8.268M) : 0, 8268116
section Manual + Automatic
This PR (5970) (6.242M) : 0, 6241600
gantt
title Throughput Windows x64 (Total requests)
dateFormat X
axisFormat %s
section Baseline
This PR (5970) (10.012M) : 0, 10012186
master (10.030M) : 0, 10029859
benchmarks/2.9.0 (10.105M) : 0, 10105239
section Automatic
This PR (5970) (6.547M) : 0, 6546926
master (6.746M) : 0, 6746187
benchmarks/2.9.0 (7.518M) : 0, 7517801
section Trace stats
master (7.324M) : 0, 7323510
section Manual
This PR (5970) (8.671M) : crit ,0, 8670666
master (9.931M) : 0, 9931035
section Manual + Automatic
This PR (5970) (6.390M) : 0, 6389559
master (6.245M) : 0, 6244786
|
Added the infrastructure of integration testing for Exception Replay in ASP.NET Core. To add a test, one needs to simply create a class that inherits from `IRun` / `IAsyncRun` and decorated with `ExceptionReplayTestData` attribute, providing to the attribute the amount of snapshots anticipated both in default configuration and full stack trace capture configuration. This PR also introduces the renaming of the configs of Exception Replay from Exception Debugging. In the early days we used to call Exception Replay internally Exception Debugging, thus some of the configs held this name. This PR renamed those leftovers to Exception Replay, including the enablement config of `DD_EXCEPTION_REPLAY_ENABLED`. [Introduced a PR to `dd-go`](https://github.com/DataDog/dd-go/pull/146180) too where these configs were added to the `config_norm_rules.json` file. Laying the groundwork for integration testing of Exception Replay. The testing infra bootstraps the web app, queries via reflection all the tests (classes inheriting from `IRun`/`IAsyncRun` and decorated with `ExceptionReplayTestData` attribute) and list them. Upon executing a test, a request will hit an endpoint of `RunTest` with the name of the test to run (FQN of the class name). The crafted test must throw an exception to be considered valid. For a more complex test scenarios, more endpoints could be introduced. Every test runs in 4 flavors: - With Exception Replay while Dynamic Instrumentation is **enabled**, default stack trace capturing limit. - With Exception Replay while Dynamic Instrumentation is **enabled**, full stack trace capturing limit. - With Exception Replay while Dynamic Instrumentation is **disabled**, default stack trace capturing limit. - With Exception Replay while Dynamic Instrumentation is **disabled**, full stack trace capturing limit. This whole PR 🤓. I've added two tests that utilize the infra: - `ExceptionWithNonSupportedFramesTest` - `RecursiveExceptionTest` Fixes DEBUG-2681, DEBUG-2732, DEBUG-1642.
5c41798 to
a6842de
Compare
Added the infrastructure of integration testing for Exception Replay in ASP.NET Core.
To add a test, one needs to simply create a class that inherits from
IRun/IAsyncRunand decorated withExceptionReplayTestDataattribute, providing to the attribute the amount of snapshots anticipated both in default configuration and full stack trace capture configuration.This PR also introduces the renaming of the configs of Exception Replay from Exception Debugging. In the early days we used to call Exception Replay internally Exception Debugging, thus some of the configs held this name. This PR renamed those leftovers to Exception Replay, including the enablement config of
DD_EXCEPTION_REPLAY_ENABLED. Introduced a PR todd-gotoo where these configs were added to theconfig_norm_rules.jsonfile.Laying the groundwork for integration testing of Exception Replay.
The testing infra bootstraps the web app, queries via reflection all the tests (classes inheriting from
IRun/IAsyncRunand decorated withExceptionReplayTestDataattribute) and list them. Upon executing a test, a request will hit an endpoint ofRunTestwith the name of the test to run (FQN of the class name). The crafted test must throw an exception to be considered valid.For a more complex test scenarios, more endpoints could be introduced.
Every test runs in 4 flavors:
This whole PR 🤓. I've added two tests that utilize the infra:
ExceptionWithNonSupportedFramesTestRecursiveExceptionTestFixes DEBUG-2681, DEBUG-2732, DEBUG-1642.
Backport of #5821