From d474d463e91ff0820829810ec438d400210f8a92 Mon Sep 17 00:00:00 2001 From: Matan Green Date: Wed, 20 Mar 2024 15:55:05 +0200 Subject: [PATCH] Fixed a small bug slipped in as part of the nullability fixes done in PR #5163 + added diagnosting tags to Exception Debugging when the log level is set to Debug --- .../ExceptionDebuggingProcessor.cs | 1 + .../ExceptionTrackManager.cs | 11 +++++++---- .../TrackedStackFrameNode.cs | 15 +++++---------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/tracer/src/Datadog.Trace/Debugger/ExceptionAutoInstrumentation/ExceptionDebuggingProcessor.cs b/tracer/src/Datadog.Trace/Debugger/ExceptionAutoInstrumentation/ExceptionDebuggingProcessor.cs index eba027180ef7..2ef2cbd4ff13 100644 --- a/tracer/src/Datadog.Trace/Debugger/ExceptionAutoInstrumentation/ExceptionDebuggingProcessor.cs +++ b/tracer/src/Datadog.Trace/Debugger/ExceptionAutoInstrumentation/ExceptionDebuggingProcessor.cs @@ -112,6 +112,7 @@ public bool Process(ref CaptureInfo info, IDebuggerSnapshotC } var exception = info.Value as Exception; + snapshotCreator.TrackedStackFrameNode.LeavingException = exception; snapshotCreator.LeaveHash = shadowStack.CurrentStackFrameNode?.LeaveSequenceHash ?? Fnv1aHash.FnvOffsetBias; var leavingExceptionType = info.Value.GetType(); diff --git a/tracer/src/Datadog.Trace/Debugger/ExceptionAutoInstrumentation/ExceptionTrackManager.cs b/tracer/src/Datadog.Trace/Debugger/ExceptionAutoInstrumentation/ExceptionTrackManager.cs index e3f20944d929..d9f83b16ae64 100644 --- a/tracer/src/Datadog.Trace/Debugger/ExceptionAutoInstrumentation/ExceptionTrackManager.cs +++ b/tracer/src/Datadog.Trace/Debugger/ExceptionAutoInstrumentation/ExceptionTrackManager.cs @@ -336,11 +336,14 @@ private static void TagAndUpload(Span span, string tagPrefix, ExceptionStackNode span.Tags.SetTag(tagPrefix + "frame_data.class_name", method.DeclaringType?.Name); span.Tags.SetTag(tagPrefix + "snapshot_id", snapshotId); - tagPrefix = tagPrefix.Replace("_", string.Empty); + if (Log.IsEnabled(LogEventLevel.Debug)) + { + tagPrefix = tagPrefix.Replace("_", string.Empty); - span.Tags.SetTag(tagPrefix + "frame_data.function", method.Name); - span.Tags.SetTag(tagPrefix + "frame_data.class_name", method.DeclaringType?.Name); - span.Tags.SetTag(tagPrefix + "snapshot_id", snapshotId); + span.Tags.SetTag(tagPrefix + "frame_data.function", method.Name); + span.Tags.SetTag(tagPrefix + "frame_data.class_name", method.DeclaringType?.Name); + span.Tags.SetTag(tagPrefix + "snapshot_id", snapshotId); + } ExceptionDebugging.AddSnapshot(probeId, snapshot); } diff --git a/tracer/src/Datadog.Trace/Debugger/ExceptionAutoInstrumentation/TrackedStackFrameNode.cs b/tracer/src/Datadog.Trace/Debugger/ExceptionAutoInstrumentation/TrackedStackFrameNode.cs index b7ca8bf04469..0d6eb8ad1d52 100644 --- a/tracer/src/Datadog.Trace/Debugger/ExceptionAutoInstrumentation/TrackedStackFrameNode.cs +++ b/tracer/src/Datadog.Trace/Debugger/ExceptionAutoInstrumentation/TrackedStackFrameNode.cs @@ -61,7 +61,7 @@ public int SequenceHash public TrackedStackFrameNode? Parent => _parent; - public Exception? LeavingException { get; private set; } + public Exception? LeavingException { get; set; } public string Snapshot { @@ -180,9 +180,9 @@ internal void AddScopeMember(string name, Type type, T value, ScopeMemberKind Members.AddMember(new ScopeMember(name, type, value, memberKind)); } - private IEnumerable FlattenException(Exception exception) + private IEnumerable FlattenException(Exception? exception) { - var exceptionList = new Stack(); + var exceptionList = new Stack(); exceptionList.Push(exception); @@ -334,14 +334,9 @@ private void ClearNonRelevantChildNodes() } } - public bool HasChildException(Exception exception) + public bool HasChildException(Exception? exception) { - if (LeavingException == null) - { - return false; - } - - if (LeavingException == exception || LeavingException == exception.InnerException) + if (LeavingException == exception || LeavingException == exception?.InnerException) { return true; }