Skip to content

[API Proposal]: HttpClient/HttpMessageInvoker metrics #84978

Closed
@JamesNK

Description

@JamesNK

Background and motivation

System.Net.Http has event counters. In .NET 8 we want to add metrics counters. These will sit side-by-side with event counters for backward compatibility.

Metrics counters add new features (histograms, tags) that allow for richer data to be represented by fewer counters. For example, there are event counters in hosting for total-requests and failed-requests counters. One metrics counter can represent these with a tag to represent the status.

API Proposal

The proposal for this issue covers the meter name, counters name and description and tags. The IDs and names are a public API that can't easily change after shipping.

System.Net.Http

Notes: current-requests and request-duration follow OTel's lead: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/http-metrics.md#http-client

http-client-current-requests

Name Instrument Type Unit Description
http-client-current-requests UpDownCounter {request} Number of outbound HTTP requests that are currently active on the client.
Attribute Type Description Examples Presence
method string HTTP request method. GET; POST; HEAD Always
scheme string The URI scheme identifying the used protocol. http; https Always
host string Host identifier of the "URI origin" HTTP request is sent to. localhost Always
port int Port identifier of the "URI origin" HTTP request is sent to. 8080 Added if not default (80 for http or 443 for https)
protocol string HTTP request protocol. HTTP/1.1; HTTP/2; HTTP/3 Always

http-client-request-duration

Name Instrument Type Unit Description
http-client-request-duration Histogram s The duration of outbound HTTP requests.
Attribute Type Description Examples Presence
scheme string The URI scheme identifying the used protocol. http; https Always
method string HTTP request method. GET; POST; HEAD Always
status-code int HTTP response status code. 200 Always
protocol string HTTP request protocol. HTTP/1.1; HTTP/2; HTTP/3 Always
host string Host identifier of the "URI origin" HTTP request is sent to. localhost Always
port int Port identifier of the "URI origin" HTTP request is sent to. 8080 Added if not default (80 for http or 443 for https)
Custom tags n/a Custom tags added from TBD. organization=contoso n/a

http-client-failed-requests

Name Instrument Type Unit Description
http-client-failed-requests Counter {request} Number of outbound HTTP requests that have failed.
Attribute Type Description Examples Presence
method string HTTP request method. GET; POST; HEAD Always
scheme string The URI scheme identifying the used protocol. http; https Always
host string Host identifier of the "URI origin" HTTP request is sent to. localhost Always
port int Port identifier of the "URI origin" HTTP request is sent to. 8080 Added if not default (80 for http or 443 for https)
protocol string HTTP request protocol. HTTP/1.1; HTTP/2; HTTP/3 Always
exception-name string Name of the .NET exception thrown during the request. System.OperationCanceledException If unhandled exception

http-client-current-connections

Name Instrument Type Unit Description
http-client-current-connections UpDownCounter {connection} Number of outbound HTTP connections that are currently active on the client.
Attribute Type Description Examples Presence
scheme string The URI scheme identifying the used protocol. http; https Always
host string Host identifier of the "URI origin" HTTP request is sent to. localhost Always
port int Port identifier of the "URI origin" HTTP request is sent to. 8080 Added if not default (80 for http or 443 for https)
protocol string HTTP request protocol. HTTP/1.1; HTTP/2; HTTP/3 Always

http-client-current-idle-connections

Name Instrument Type Unit Description
http-client-current-idle-connections UpDownCounter {connection} Number of outbound HTTP connections that are currently idle on the client.
Attribute Type Description Examples Presence
scheme string The URI scheme identifying the used protocol. http; https Always
host string Host identifier of the "URI origin" HTTP request is sent to. localhost Always
port int Port identifier of the "URI origin" HTTP request is sent to. 8080 Added if not default (80 for http or 443 for https)
protocol string HTTP request protocol. HTTP/1.1; HTTP/2; HTTP/3 Always

http-client-connection-duration

Name Instrument Type Unit Description
http-client-connection-duration Histogram s The duration of outbound HTTP connections.
Attribute Type Description Examples Presence
scheme string The URI scheme identifying the used protocol. http; https Always
host string Host identifier of the "URI origin" HTTP request is sent to. localhost Always
port int Port identifier of the "URI origin" HTTP request is sent to. 8080 Added if not default (80 for http or 443 for https)
protocol string HTTP request protocol. HTTP/1.1; HTTP/2; HTTP/3 Always
reason string Reason why the connection ended. ??? Always

API Usage

Metrics are collected using libraries, tooling or MeterListener

https://learn.microsoft.com/en-us/dotnet/core/diagnostics/metrics-collection

Alternative Designs

No response

Risks

No response

Metadata

Metadata

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