Skip to content

Commit

Permalink
Set activity status to error when an exception is recorded
Browse files Browse the repository at this point in the history
Fixes #77
  • Loading branch information
kzu committed Nov 19, 2022
1 parent 3e526e6 commit d4c6e5d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Merq.Core/Telemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ static class Telemetry

public static void RecordException(this Activity? activity, Exception e)
{
// See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/exceptions.md
activity?.AddEvent(new ActivityEvent("exception", tags: new()
if (activity != null)
{
{ "exception.message", e.Message },
{ "exception.type", e.GetType().FullName },
{ "exception.stacktrace", e.ToString() },
}));
activity.SetStatus(ActivityStatusCode.Error, e.Message);

// See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/exceptions.md
activity.AddEvent(new ActivityEvent("exception", tags: new()
{
{ "exception.message", e.Message },
{ "exception.type", e.GetType().FullName },
{ "exception.stacktrace", e.ToString() },
}));
}
}
}

0 comments on commit d4c6e5d

Please sign in to comment.