Skip to content

Add status code and exception info to System.Net.Http events - #84036

Merged
MihaZupan merged 2 commits into
dotnet:mainfrom
MihaZupan:http-telem-statuscode
Apr 17, 2023
Merged

Add status code and exception info to System.Net.Http events#84036
MihaZupan merged 2 commits into
dotnet:mainfrom
MihaZupan:http-telem-statuscode

Conversation

@MihaZupan

@MihaZupanMihaZupan commented Mar 28, 2023

Copy link
Copy Markdown
Member

Contributes to #83734

This PR adds the following parameters to existing events:

-void RequestStop()+void RequestStop(int statusCode)-void ResponseHeadersStop()+void ResponseHeadersStop(int statusCode)-void RequestFailed();+void RequestFailed(string exceptionMessage)

and a new event under a dedicated keyword

[Event(15,Level=EventLevel.Error,Keywords=Keywords.RequestFailedDetailed)]voidRequestFailedDetailed(stringexception);

Copying the reasoning behind having the status code on both RequestStop and ResponseHeadersStop from #83734 (comment):

ResponseHeadersStop in addition to RequestStop because we may not have a status code available in RequestStop in failure cases, and because a single RequestStart may span multiple actual requests internally due to redirects (or custom user handler logic such as retries). Having a status code on the RequestStop is still valuable for users that just care about the result of the HttpClient call, without diving into details of what happened as part of that call. See 003e675#r103790748 for more discussion about this.

@dotnet/ncl please confirm that the added parameters make sense (not just to me) -- this is akin to adding a public API in that we don't want to break it in the future (we can add more parameters, but wouldn't want to remove them for example).

@MihaZupanMihaZupan added this to the 8.0.0 milestone Mar 28, 2023
@MihaZupan
MihaZupan requested review from a team, brianrob and noahfalkMarch 28, 2023 18:50
@MihaZupanMihaZupan self-assigned this Mar 28, 2023
@ghost

Copy link
Copy Markdown

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

Issue Details

Contributes to #83734

This PR adds the following parameters to existing events:

-void RequestStop()+void RequestStop(int statusCode)-void ResponseHeadersStop()+void ResponseHeadersStop(int statusCode)-void RequestFailed();+void RequestFailed(string exception);

Copying the reasoning behind having the status code on both RequestStop and ResponseHeadersStop from #83734 (comment):

ResponseHeadersStop in addition to RequestStop because we may not have a status code available in RequestStop in failure cases, and because a single RequestStart may span multiple actual requests internally due to redirects (or custom user handler logic such as retries). Having a status code on the RequestStop is still valuable for users that just care about the result of the HttpClient call, without diving into details of what happened as part of that call. See 003e675#r103790748 for more discussion about this.

@dotnet/ncl please confirm that the added parameters make sense (not just to me) -- this is akin to adding a public API.

Author:MihaZupan
Assignees:MihaZupan
Labels:

area-System.Net.Http

Milestone:8.0.0

Comment threadsrc/libraries/System.Net.Http/src/System/Net/Http/HttpMessageInvoker.cs Outdated
Comment threadsrc/libraries/System.Net.Http/src/System/Net/Http/HttpTelemetry.cs Outdated

@brianrobbrianrob left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A couple of questions, but overall looks good.

Comment threadsrc/libraries/System.Net.Http/src/System/Net/Http/HttpTelemetry.cs Outdated
Comment threadsrc/libraries/System.Net.Http/src/System/Net/Http/HttpTelemetry.cs Outdated
Comment threadsrc/libraries/System.Net.Http/src/System/Net/Http/HttpTelemetry.cs Outdated
@danmoseley

Copy link
Copy Markdown
Contributor

Not directly related to this change, but are these kinds of events already exposed in a first class way to open telemetry? I'm just wondering whether we expect we'd need work in this codebase analogous to what @JamesNK is doing in dotnet/aspnetcore#46834

@noahfalk

Copy link
Copy Markdown
Member

Not directly related to this change, but are these kinds of events already exposed in a first class way to open telemetry? I'm just wondering whether we expect we'd need work in this codebase analogous to what @JamesNK is doing in dotnet/aspnetcore#46834

The events are exposed in the sense that OpenTelemetry instrumentation could create an EventListener and receive them if it wants to. Currently OTel's HttpClient instrumentation doesn't do that as it utilizes some DianosticSource events instead: https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/src/OpenTelemetry.Instrumentation.Http.

@MihaZupan
MihaZupanforce-pushed the http-telem-statuscode branch from fe48bce to e9eb374CompareApril 12, 2023 17:29
@MihaZupan

Copy link
Copy Markdown
MemberAuthor

@dotnet/ncl PTAL, the change is now:

  • Adding int statusCode to RequestStop and ResponseHeadersStop
  • Adding string exceptionMessage to RequestFailed
  • Adding a new event RequestFailedDetailed(string exception) under a dedicated keyword opt-in

@ManickaPManickaP left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@MihaZupan

Copy link
Copy Markdown
MemberAuthor

@noahfalk mind taking another look at this one if it matches what you'd expect? This is also the first time for networking telemetry that we're making use of Keywords/Version, I just followed existing patterns there w.r.t. naming.

@noahfalknoahfalk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Functionally this looks fine to me, my only remaining concern is have we validated with Jeff that this meets his needs? For example I could speculate he may not want the overhead/risk of the detailed error message with full stack trace, but perhaps he would still want the Exception type name as part of the error information?

@MihaZupan

Copy link
Copy Markdown
MemberAuthor

but perhaps he would still want the Exception type name as part of the error information?

I'll double-check offline, but with HttpClient the exception type name alone is not useful - it should be either TaskCanceledException or HttpRequestException. You can deduce whether it was the former based on the message.

@MihaZupan

Copy link
Copy Markdown
MemberAuthor

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@ghostghost locked as resolved and limited conversation to collaborators May 17, 2023
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@MihaZupan@danmoseley@noahfalk@brianrob@ManickaP