From e58b8979528964aa55418768415ed020ede1d6f1 Mon Sep 17 00:00:00 2001 From: Joe Schmitt <1146681+schmittjoseph@users.noreply.github.com> Date: Tue, 10 Sep 2024 13:36:01 -0700 Subject: [PATCH] Prevent collected exceptions from being dropped due to null event values (#7301) --- .../Exceptions/Eventing/ExceptionsEventSource.cs | 4 ++-- .../Exceptions/Pipeline/Steps/ExceptionEventsPipelineStep.cs | 2 +- .../Exceptions/Eventing/ExceptionsEventSourceTests.cs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.Diagnostics.Monitoring.StartupHook/Exceptions/Eventing/ExceptionsEventSource.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/Exceptions/Eventing/ExceptionsEventSource.cs index 3bcb89b13da..901308c9515 100644 --- a/src/Microsoft.Diagnostics.Monitoring.StartupHook/Exceptions/Eventing/ExceptionsEventSource.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/Exceptions/Eventing/ExceptionsEventSource.cs @@ -35,11 +35,11 @@ public void ExceptionGroup( public void ExceptionInstance( ulong ExceptionId, ulong ExceptionGroupId, - string? ExceptionMessage, + string ExceptionMessage, ulong[] StackFrameIds, DateTime Timestamp, ulong[] InnerExceptionIds, - string? ActivityId, + string ActivityId, ActivityIdFormat ActivityIdFormat) { Span data = stackalloc EventData[8]; diff --git a/src/Microsoft.Diagnostics.Monitoring.StartupHook/Exceptions/Pipeline/Steps/ExceptionEventsPipelineStep.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/Exceptions/Pipeline/Steps/ExceptionEventsPipelineStep.cs index ec3dd331d44..6d8455208e7 100644 --- a/src/Microsoft.Diagnostics.Monitoring.StartupHook/Exceptions/Pipeline/Steps/ExceptionEventsPipelineStep.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/Exceptions/Pipeline/Steps/ExceptionEventsPipelineStep.cs @@ -60,7 +60,7 @@ public void Invoke(Exception exception, ExceptionPipelineExceptionContext contex frameIds, context.Timestamp, GetInnerExceptionsIds(exception), - context.ActivityId, + context.ActivityId ?? string.Empty, context.ActivityIdFormat ); } diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/Exceptions/Eventing/ExceptionsEventSourceTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/Exceptions/Eventing/ExceptionsEventSourceTests.cs index 685da3af35a..17607e17ed2 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/Exceptions/Eventing/ExceptionsEventSourceTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/Exceptions/Eventing/ExceptionsEventSourceTests.cs @@ -108,7 +108,7 @@ public void ExceptionsEventSource_WriteException_LevelTooHigh() using ExceptionsEventListener listener = new(); listener.EnableEvents(source, EventLevel.Warning); - source.ExceptionInstance(5, 7, ObjectDisposedExceptionMessage, Array.Empty(), DateTime.UtcNow, Array.Empty(), null, ActivityIdFormat.Unknown); + source.ExceptionInstance(5, 7, ObjectDisposedExceptionMessage, Array.Empty(), DateTime.UtcNow, Array.Empty(), string.Empty, ActivityIdFormat.Unknown); Assert.Empty(listener.Exceptions); } @@ -120,7 +120,7 @@ public void ExceptionsEventSource_WriteException_NotEnabled() using ExceptionsEventListener listener = new(); - source.ExceptionInstance(7, 9, OperationCancelledExceptionMessage, Array.Empty(), DateTime.UtcNow, Array.Empty(), null, ActivityIdFormat.Unknown); + source.ExceptionInstance(7, 9, OperationCancelledExceptionMessage, Array.Empty(), DateTime.UtcNow, Array.Empty(), string.Empty, ActivityIdFormat.Unknown); Assert.Empty(listener.Exceptions); }