Skip to content

ASP.NET Core metrics #47536

Closed
Closed
@JamesNK

Description

@JamesNK

Background and Motivation

ASP.NET Core 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 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.

Proposed API

Microsoft.AspNetCore.Hosting

Notes: HTTP counters and tags here follow OTel's lead: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/http-metrics.md#http-server

http-server-current-requests

Name Instrument Type Unit Description
http-server-current-requests UpDownCounter {request} Number of HTTP requests that are currently active on the server.
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 Name of the local HTTP server that received the request. localhost Always
port int Port of the local HTTP server that received the request. 8080 Added if not default (80 for http or 443 for https)

http-server-request-duration

Name Instrument Type Unit Description
http-server-request-duration Histogram s The duration of HTTP requests on the server.
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 Name of the local HTTP server that received the request. localhost Always
port int Port of the local HTTP server that received the request. 8080 Added if not default (80 for http or 443 for https)
route string The matched route {controller}/{action}/{id?} Added if route endpoint set
exception-name string Name of the .NET exception thrown during the request. Report exception is either unhandled from middleware or handled by ExceptionHandlerMiddleware or DeveloperExceptionPageMiddleware. System.OperationCanceledException If unhandled exception
Custom tags n/a Custom tags added from IHttpMetricsTagsFeature. organization=contoso n/a

Microsoft.AspNetCore.Server.Kestrel

Notes: All Kestrel counters include the endpoint as a tag.

kestrel-current-connections

Name Instrument Type Unit Description
kestrel-current-connections UpDownCounter {connection} Number of connections that are currently active on the server.
Attribute Type Description Examples Presence
endpoint string Name of the local endpoint that received the connection. localhost:8080 Always

kestrel-connection-duration

Name Instrument Type Unit Description
kestrel-connection-duration Histogram s The duration of connections on the server.
Attribute Type Description Examples Presence
endpoint string Name of the local endpoint that received the connection. localhost:8080 Always
exception-name string Name of the .NET exception thrown during the connect. Report exception is unhandled If unhandled exception
Custom tags n/a Custom tags added from IConnectionMetricsTagsFeature. organization=contoso n/a

kestrel-rejected-connections

Name Instrument Type Unit Description
kestrel-rejected-connections Counter {connection} Number of connections rejected by the server. Connections are rejected when the currently active count exceeds the value configured with MaxConcurrentConnections.
Attribute Type Description Examples Presence
endpoint string Name of the local endpoint that received the connection. localhost:8080 Always

kestrel-queued-connections

Name Instrument Type Unit Description
kestrel-queued-connections UpDownCounter {connection} Number of connections that are currently queued and are waiting to start.
Attribute Type Description Examples Presence
endpoint string Name of the local endpoint that received the connection. localhost:8080 Always

kestrel-queued-requests

Name Instrument Type Unit Description
kestrel-queued-requests UpDownCounter {request} Number of HTTP requests on multiplexed connections (HTTP/2 and HTTP/3) that are currently queued and are waiting to start.
Attribute Type Description Examples Presence
endpoint string Name of the local endpoint that received the connection. localhost:8080 Always

kestrel-current-upgraded-connections

Name Instrument Type Unit Description
kestrel-current-upgraded-connections UpDownCounter {request} Number of HTTP connections that are currently upgraded (WebSockets). The number only tracks HTTP/1.1 connections.
Attribute Type Description Examples Presence
endpoint string Name of the local endpoint that received the connection. localhost:8080 Always

kestrel-tls-handshake-duration

Name Instrument Type Unit Description
kestrel-tls-handshake-duration Histogram {s} The duration of TLS handshakes on the server.
Attribute Type Description Examples Presence
endpoint string Name of the local endpoint that received the connection. localhost:8080 Always
protocol string Security protocol used to authenticate the connection. Tls10; Tls11; Tls12; Tls13 Always
exception-name string Name of the .NET exception thrown on TLS handshake failure. System.OperationCanceledException If TLS handshake fails

kestrel-current-tls-handshakes

Name Instrument Type Unit Description
kestrel-current-tls-handshakes UpDownCounter {handshake} Number of TLS handshakes that are currently in progress on the server.
Attribute Type Description Examples Presence
endpoint string Name of the local endpoint that received the connection. localhost:8080 Always

Microsoft.AspNetCore.Http.Connections

Notes: Timed out connection counter is merged into connection-duration counter. I'm unaware of an official connection closed status, so I invented one with some values. @BrennanConroy It would be good if you could help with better end statuses.

signalr-http-transport-current-connections

Name Instrument Type Unit Description
signalr-http-transport-current-connections UpDownCounter {connection} Number of connections that are currently active on the server.

signalr-http-transport-current-transports

Name Instrument Type Unit Description
signalr-http-transport-current-transports UpDownCounter {transport} Number of connection transports that are currently active on the server.
Attribute Type Description Examples Presence
transport string The connection transport None; WebSockets; ServerSentEvents; LongPolling Always

Update: REMOVED

signalr-http-transport-connection-duration

Name Instrument Type Unit Description
signalr-http-transport-connection-duration Histogram s The duration of connections on the server.
Attribute Type Description Examples Presence
status string The connection end status NormalClosure; Timeout; AppShutdown Always
transport string The connection transport None; WebSockets; ServerSentEvents; LongPolling Always

Usage Examples

Alternative Designs

Risks

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedAPI was approved in API review, it can be implementedarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions