Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected TraceAnnotationsTests(string sampleAppName, bool enableTelemetry, ITes
[SkippableFact]
public async Task SubmitTraces()
{
const int expectedSpanCount = 51;
const int expectedSpanCount = 52;
var ddTraceMethodsString = string.Empty;

foreach (var type in TestTypes)
Expand All @@ -88,6 +88,10 @@ public async Task SubmitTraces()

ddTraceMethodsString += ";Samples.TraceAnnotations.ExtensionMethods[ExtensionMethodForTestType,ExtensionMethodForTestTypeGeneric,ExtensionMethodForTestTypeTypeStruct];System.Net.Http.HttpRequestMessage[set_Method]";

// Add method with extreme exception handling nesting (APMS-19196 regression test)
// Must target the sync method which has the EH directly in its body (not in an async state machine)
ddTraceMethodsString += ";Samples.TraceAnnotations.ExtremeExceptionHandling[DeepNestedExceptionHandlingSync]";

SetEnvironmentVariable("DD_TRACE_METHODS", ddTraceMethodsString);
// Don't bother with telemetry in version mismatch scenarios because older versions may only support V1 telemetry
// which we no longer support in our mock telemetry agent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -844,5 +844,19 @@
language: dotnet,
version: 1.0.0
}
},
{
TraceId: Id_1,
SpanId: Id_62,
Name: trace.annotation,
Resource: ExtremeExceptionHandling.DeepNestedExceptionHandlingSync,
Service: Samples.TraceAnnotations,
ParentId: Id_2,
Tags: {
component: trace,
env: integration_tests,
language: dotnet,
version: 1.0.0
}
}
]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
[
{
TraceId: Id_1,
SpanId: Id_2,
Expand Down Expand Up @@ -844,5 +844,19 @@
language: dotnet,
version: 1.0.0
}
},
{
TraceId: Id_1,
SpanId: Id_62,
Name: trace.annotation,
Resource: ExtremeExceptionHandling.DeepNestedExceptionHandlingSync,
Service: Samples.TraceAnnotations,
ParentId: Id_2,
Tags: {
component: trace,
env: integration_tests,
language: dotnet,
version: 1.0.0
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -844,5 +844,19 @@
language: dotnet,
version: 1.0.0
}
},
{
TraceId: Id_1,
SpanId: Id_62,
Name: trace.annotation,
Resource: ExtremeExceptionHandling.DeepNestedExceptionHandlingSync,
Service: Samples.TraceAnnotations,
ParentId: Id_2,
Tags: {
component: trace,
env: integration_tests,
language: dotnet,
version: 1.0.0
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -844,5 +844,19 @@
language: dotnet,
version: 1.0.0
}
},
{
TraceId: Id_1,
SpanId: Id_62,
Name: trace.annotation,
Resource: ExtremeExceptionHandling.DeepNestedExceptionHandlingSync,
Service: Samples.TraceAnnotations.VersionMismatch.AfterFeature,
ParentId: Id_2,
Tags: {
component: trace,
env: integration_tests,
language: dotnet,
version: 1.0.0
}
}
]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
[
{
TraceId: Id_1,
SpanId: Id_2,
Expand Down Expand Up @@ -844,5 +844,19 @@
language: dotnet,
version: 1.0.0
}
},
{
TraceId: Id_1,
SpanId: Id_62,
Name: trace.annotation,
Resource: ExtremeExceptionHandling.DeepNestedExceptionHandlingSync,
Service: Samples.TraceAnnotations.VersionMismatch.AfterFeature,
ParentId: Id_2,
Tags: {
component: trace,
env: integration_tests,
language: dotnet,
version: 1.0.0
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -844,5 +844,19 @@
language: dotnet,
version: 1.0.0
}
},
{
TraceId: Id_1,
SpanId: Id_62,
Name: trace.annotation,
Resource: ExtremeExceptionHandling.DeepNestedExceptionHandlingSync,
Service: Samples.TraceAnnotations.VersionMismatch.AfterFeature,
ParentId: Id_2,
Tags: {
component: trace,
env: integration_tests,
language: dotnet,
version: 1.0.0
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -844,5 +844,19 @@
language: dotnet,
version: 1.0.0
}
},
{
TraceId: Id_1,
SpanId: Id_62,
Name: trace.annotation,
Resource: ExtremeExceptionHandling.DeepNestedExceptionHandlingSync,
Service: Samples.TraceAnnotations.VersionMismatch.BeforeFeature,
ParentId: Id_2,
Tags: {
component: trace,
env: integration_tests,
language: dotnet,
version: 1.0.0
}
}
]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
[
{
TraceId: Id_1,
SpanId: Id_2,
Expand Down Expand Up @@ -844,5 +844,19 @@
language: dotnet,
version: 1.0.0
}
},
{
TraceId: Id_1,
SpanId: Id_62,
Name: trace.annotation,
Resource: ExtremeExceptionHandling.DeepNestedExceptionHandlingSync,
Service: Samples.TraceAnnotations.VersionMismatch.BeforeFeature,
ParentId: Id_2,
Tags: {
component: trace,
env: integration_tests,
language: dotnet,
version: 1.0.0
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -844,5 +844,19 @@
language: dotnet,
version: 1.0.0
}
},
{
TraceId: Id_1,
SpanId: Id_62,
Name: trace.annotation,
Resource: ExtremeExceptionHandling.DeepNestedExceptionHandlingSync,
Service: Samples.TraceAnnotations.VersionMismatch.BeforeFeature,
ParentId: Id_2,
Tags: {
component: trace,
env: integration_tests,
language: dotnet,
version: 1.0.0
}
}
]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) ">
<Reference Include="System.Net.Http" />
Expand All @@ -21,5 +21,6 @@
<Compile Include="..\Samples.TraceAnnotations\ProgramHelpers.cs" />
<Compile Include="..\Samples.TraceAnnotations\TestType.cs" />
<Compile Include="..\Samples.TraceAnnotations\TraceAttribute.cs" />
<Compile Include="..\Samples.TraceAnnotations\ExtremeExceptionHandling.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) ">
<Reference Include="System.Net.Http" />
Expand All @@ -21,5 +21,6 @@
<Compile Include="..\Samples.TraceAnnotations\ProgramHelpers.cs" />
<Compile Include="..\Samples.TraceAnnotations\TestType.cs" />
<Compile Include="..\Samples.TraceAnnotations\TraceAttribute.cs" />
<Compile Include="..\Samples.TraceAnnotations\ExtremeExceptionHandling.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
using System;
using System.Threading.Tasks;

namespace Samples.TraceAnnotations
{
/// <summary>
/// Test class with deeply nested try/catch/finally patterns that triggered
/// a bug in the IL rewriter's exception handler sorting logic (APMS-19196).
/// The bug causes InvalidProgramException on Linux x86/x64 due to stricter EH clause
/// validation by the Linux CLR; Windows does not exhibit the crash.
/// </summary>
public static class ExtremeExceptionHandling
{
private static int _counter = 0;

/// <summary>
/// Async wrapper that calls the sync method with deep EH nesting.
/// </summary>
public static async Task<string> DeepNestedExceptionHandlingAsync()
{
await Task.Yield();
return DeepNestedExceptionHandlingSync();
}

/// <summary>
/// Synchronous method with 9 levels of nested try/catch/finally.
/// This pattern triggers the EH clause sorting bug when instrumented.
/// The EH is directly in this method (not in a state machine).
/// </summary>
public static string DeepNestedExceptionHandlingSync()
{
var requestId = System.Threading.Interlocked.Increment(ref _counter);

try
{
// Level 1
try
{
Console.WriteLine($"[L1] {requestId}");

// Level 5 (skipping L2,L3,L4 - the crashing pattern!)
try
{
Console.WriteLine($"[L5] {requestId}");

// Level 6
try
{
Console.WriteLine($"[L6] {requestId}");

// Level 7
try
{
Console.WriteLine($"[L7] {requestId}");

// Level 8
try
{
Console.WriteLine($"[L8] {requestId}");

// Level 9 - THE CRASH TRIGGER
try
{
Console.WriteLine($"[L9] {requestId}");
System.Threading.Thread.Sleep(1);
Console.WriteLine($"[L9] Success {requestId}");
}
catch (Exception l9Ex)
{
Console.WriteLine($"[L9] Exception: {l9Ex.GetType().Name}");
}
finally
{
Console.WriteLine($"[L9] Finally {requestId}");
}
}
catch (Exception l8Ex)
{
Console.WriteLine($"[L8] Exception: {l8Ex.GetType().Name}");
}
finally
{
Console.WriteLine($"[L8] Finally {requestId}");
}
}
catch (Exception l7Ex)
{
Console.WriteLine($"[L7] Exception: {l7Ex.GetType().Name}");
}
finally
{
Console.WriteLine($"[L7] Finally {requestId}");
}
}
catch (Exception l6Ex)
{
Console.WriteLine($"[L6] Exception: {l6Ex.GetType().Name}");
}
finally
{
Console.WriteLine($"[L6] Finally {requestId}");
}
}
catch (Exception l5Ex)
{
Console.WriteLine($"[L5] Exception: {l5Ex.GetType().Name}");
}
finally
{
Console.WriteLine($"[L5] Finally {requestId}");
}
}
finally
{
Console.WriteLine($"[L1] Finally {requestId}");
}
}
catch (Exception rootEx)
{
Console.WriteLine($"[ROOT] Exception: {rootEx.GetType().Name}");
}
finally
{
Console.WriteLine($"[ROOT] Finally {requestId}");
}

return $"Success {requestId}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ public static async Task RunTestsAsync()
await WaitUsingOfficialAttribute();
await NewRelicTransactionMethodAsync("Hello World");
NewRelicTraceMethod(42);

// Test extreme exception handling patterns (APMS-19196 regression test)
// This exercises the IL rewriter with complex try/catch/finally nesting
await ExtremeExceptionHandling.DeepNestedExceptionHandlingAsync();
}

[OfficialTrace(OperationName = "overridden.attribute", ResourceName = "Program_WaitUsingOfficialAttribute")]
Expand Down
Loading