Skip to content

Adding more information and events to System.Net.Http telemetry #83734

Closed
@MihaZupan

Description

@MihaZupan

While we include a decent amount of information about a request in the RequestStart event, we provide almost no information about what happened with the response (outside of timestamps/latency info for various steps during a request).

void RequestStart(string scheme, string host, int port, string pathAndQuery, byte versionMajor, byte versionMinor, HttpVersionPolicy versionPolicy);
void RequestFailed();

We've heard from customers moving from .NET Framework where they could get information like the response status code from the System.Diagnostics.Eventing.FrameworkEventSource provider, e.g.:

GetResponseStart
id: 9223372032565852628
uri: https://httpbin.org/ip
success: True
synchronous: False

GetResponseStop
id: 9223372032565852628
success: True
synchronous: False
statusCode: 200

I propose we include more information on the following (existing) System.Net.Http events:

  • Status code on RequestStop.
    -void RequestStop()
    +void RequestStop(int statusCode)
  • Status code on ResponseHeadersStop. 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.
    -void ResponseHeadersStop()
    +void ResponseHeadersStop(int statusCode)
  • Exception message & stack trace on RequestFailed.
    -void RequestFailed();
    +void RequestFailed(string exception);
    If we decide on an error code system as part of [API Proposal]: Support error codes for HttpRequestException #76644, we could include that information as a second parameter, or we could rely on the error code becoming a part of the HttpRequestException's message. @antonfirsov is including the HttpRequestError in the message string something you've considered?

The remaining set of potential improvements is now tracked by #85729.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Net.HttpenhancementProduct code improvement that does NOT require public API changes/additions

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions