Skip to content

Commit

Permalink
Distributed Tracing: Use recommended conventions for setting status a…
Browse files Browse the repository at this point in the history
…nd stack traces
  • Loading branch information
ReubenBond committed Feb 19, 2024
1 parent f043afa commit f949e90
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,24 @@ protected static async Task Process(IGrainCallContext context, Activity activity
await context.Invoke();
if (activity is not null && activity.IsAllDataRequested)
{
activity.SetTag("status", "Ok");
activity.SetStatus(ActivityStatusCode.Ok);
}
}
catch (Exception e)
{
if (activity is not null && activity.IsAllDataRequested)
{
activity.SetStatus(ActivityStatusCode.Error);

// exception attributes from https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/exceptions.md
activity.SetTag("exception.type", e.GetType().FullName);
activity.SetTag("exception.message", e.Message);
activity.SetTag("exception.stacktrace", e.StackTrace);

// Note that "exception.stacktrace" is the full exception detail, not just the StackTrace property.
// See https://opentelemetry.io/docs/specs/semconv/attributes-registry/exception/
// and https://github.com/open-telemetry/opentelemetry-specification/pull/697#discussion_r453662519
activity.SetTag("exception.stacktrace", e.ToString());
activity.SetTag("exception.escaped", true);
activity.SetTag("status", "Error");
}

throw;
Expand Down

0 comments on commit f949e90

Please sign in to comment.