Skip to content

Commit

Permalink
Handle case where SetException throws (#5291)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlock authored Mar 13, 2024
1 parent 832de4b commit 7be52af
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions tracer/src/Datadog.Trace/Span.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,17 +405,25 @@ internal void SetExceptionTags(Exception exception)
{
if (exception != null)
{
// for AggregateException, use the first inner exception until we can support multiple errors.
// there will be only one error in most cases, and even if there are more and we lose
// the other ones, it's still better than the generic "one or more errors occurred" message.
if (exception is AggregateException aggregateException && aggregateException.InnerExceptions.Count > 0)
try
{
exception = aggregateException.InnerExceptions[0];
}
// for AggregateException, use the first inner exception until we can support multiple errors.
// there will be only one error in most cases, and even if there are more and we lose
// the other ones, it's still better than the generic "one or more errors occurred" message.
if (exception is AggregateException aggregateException && aggregateException.InnerExceptions.Count > 0)
{
exception = aggregateException.InnerExceptions[0];
}

SetTag(Trace.Tags.ErrorMsg, exception.Message);
SetTag(Trace.Tags.ErrorStack, exception.ToString());
SetTag(Trace.Tags.ErrorType, exception.GetType().ToString());
SetTag(Trace.Tags.ErrorMsg, exception.Message);
SetTag(Trace.Tags.ErrorType, exception.GetType().ToString());
SetTag(Trace.Tags.ErrorStack, exception.ToString());
}
catch (Exception ex)
{
// We have found rare cases where exception.ToString() throws an exception, such as in a FileNotFoundException
Log.Warning(ex, "Error setting exception tags on span {SpanId} in trace {TraceId}", SpanId, TraceId);

This comment has been minimized.

Copy link
@lucaspimentel

lucaspimentel Mar 13, 2024

Member

We should use TraceId128 instead of TraceId to include the full 128-bit trace id.

This comment has been minimized.

Copy link
@andrewlock

andrewlock Mar 15, 2024

Author Member

Done #5312

FYI, commenting on commits on master is generally a good way to ensure noone ever sees them again 😅

}
}
}

Expand Down

0 comments on commit 7be52af

Please sign in to comment.