Skip to content

Record exception in HttpClient native instrumentation #115959

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

joegoldman2
Copy link
Contributor

Fixes #108050.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label May 24, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@antonfirsov antonfirsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good as-is, thank you!

@joegoldman2
Copy link
Contributor Author

Failures in CI look unrelated.

if (exception is not null)
{
// Records the exception as per https://github.com/open-telemetry/opentelemetry-specification/blob/v1.45.0/specification/trace/exceptions.md
activity.AddException(exception);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually one thought: This call will record the exception event with a timestamp slightly after the Activity end time. I'm not sure if this will cause any trouble on the monitoring side, but we could avoid the issue by passing timestamp: activity.StartTimeUtc + activity.Duration here.

Copy link
Contributor Author

@joegoldman2 joegoldman2 May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure to understand this point. How the exception event can have a timestamp after the activity end timestamp?
The activity is stopped later l221:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a SetEndTime() call at the top of the finally block:

activity.Stop() will not update value of Duration value if it has been set manually earlier by calling SetEndTime(). (Note that there is no EndTime property SetEndTime() assigns the Duration.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I missed that. I applied the suggestion and added a comment. Please let me know if it's fine for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Net.Http community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exception event missing from activity in HttpClient native instrumentation
2 participants