Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should RecordException(this Activity activity, Exception? ex, in TagList tags) set the attributes error.type and otel.status_code? #5346

Closed
joegoldman2 opened this issue Feb 12, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@joegoldman2
Copy link
Contributor

Feature Request

When an exception is thrown but not properly caught, HttpInListener records it and sets the attributes error.type and otel.status_code:

activity.SetTag(SemanticConventions.AttributeErrorType, exc.GetType().FullName);
if (this.options.RecordException)
{
activity.RecordException(exc);
}
activity.SetStatus(ActivityStatusCode.Error);

When the exception is caught and manually recorded using activity.RecordException(ex), the attributes error.type and otel.status_code are not set:

public static void RecordException(this Activity activity, Exception? ex, in TagList tags)
{
if (ex == null || activity == null)
{
return;
}
var tagsCollection = new ActivityTagsCollection
{
{ SemanticConventions.AttributeExceptionType, ex.GetType().FullName },
{ SemanticConventions.AttributeExceptionStacktrace, ex.ToInvariantString() },
};
if (!string.IsNullOrWhiteSpace(ex.Message))
{
tagsCollection.Add(SemanticConventions.AttributeExceptionMessage, ex.Message);
}
foreach (var tag in tags)
{
tagsCollection[tag.Key] = tag.Value;
}
activity.AddEvent(new ActivityEvent(SemanticConventions.AttributeExceptionEventName, default, tagsCollection));

Should they also be set in this case?

@joegoldman2 joegoldman2 added the enhancement New feature or request label Feb 12, 2024
@vishweshbankwar
Copy link
Member

RecordException follows specification and only records exceptions as an event.

It looks like whether RecordException should also set the Span Status is still an open question (open-telemetry/opentelemetry-specification#1008).

Regarding error.type - this attribute is specific to http conventions https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-spans.md#common-attributes and that is why its only used with http instrumentations.

@joegoldman2
Copy link
Contributor Author

Thank you for your feedback, it's clear.

error.type is also available for messaging convention https://opentelemetry.io/docs/specs/semconv/messaging/messaging-spans/ and maybe others.

@vishweshbankwar
Copy link
Member

error.type is also available for messaging convention https://opentelemetry.io/docs/specs/semconv/messaging/messaging-spans/ and maybe others.

I see. Was not up to date with messaging conventions. Thanks for letting me know.

Since there is no action need right now on this from .NET. I am closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants