Back to Aspnetcore

ASP.NET Core built-in metrics

aspnetcore/log-mon/metrics/built-in.md

latest37.6 KB
Original Source

ASP.NET Core built-in metrics

This article describes the built-in metrics for ASP.NET Core produced using the xref:System.Diagnostics.Metrics?displayProperty=nameWithType API. For a listing of metrics based on the older EventCounters API, see Available counters.

For information on how to collect, report, enrich, and test with ASP.NET Core metrics, see xref:log-mon/metrics/metrics.

:::moniker range=">= aspnetcore-10.0"

Microsoft.AspNetCore.Components

The Microsoft.AspNetCore.Components metrics report information on Razor component route changes and browser events:

Metric: aspnetcore.components.navigation

NameInstrument TypeUnit (UCUM)Description
aspnetcore.components.navigation<!--](https://opentelemetry.io/docs/specs/semconv/dotnet/dotnet-http-metrics/#metric-aspnetcorecomponentsnavigation)-->Counter{route}Tracks the total number of route changes in the app.
AttributeTypeDescriptionExamplesPresence
aspnetcore.components.typestringComponent navigated to.TestComponentAlways
aspnetcore.components.routestringThe component's route./test-routeAlways
error.typestringThe full name of exception type.System.InvalidOperationException; Contoso.MyExceptionIf an exception is thrown.

Usage: How many different Blazor pages did users visit?

Metric: aspnetcore.components.event_handler

NameInstrument TypeUnit (UCUM)Description
aspnetcore.components.event_handler<!--](https://opentelemetry.io/docs/specs/semconv/dotnet/dotnet-http-metrics/#metric-aspnetcorecomponentsevent_handler)-->HistogramsMeasures the duration of processing browser events, including business logic of the component, excluding the duration of child component event handling.
AttributeTypeDescriptionExamplesPresence
aspnetcore.components.typestringComponent type handling the event.TestComponentAlways
aspnetcore.components.methodstringC# method handling the event.OnClickAlways
aspnetcore.components.attribute.namestringComponent attribute name handling the event.onclickAlways
error.typestringThe full name of exception type.System.InvalidOperationException; Contoso.MyExceptionIf an exception is thrown.

Usage:

  • Which component's click event handler is slow?
  • Which buttons are selected often?

Microsoft.AspNetCore.Components.Lifecycle

The Microsoft.AspNetCore.Components.Lifecycle metrics report information on Razor component lifecycle events:

Metric: aspnetcore.components.update_parameters

NameInstrument TypeUnit (UCUM)Description
aspnetcore.components.update_parameters<!--](https://opentelemetry.io/docs/specs/semconv/dotnet/dotnet-http-metrics/#metric-aspnetcorecomponentsupdate_parameters)-->HistogramsMeasures the duration of processing component parameters, including business logic.
AttributeTypeDescriptionExamplesPresence
aspnetcore.components.typestringComponent type handling the event.TestComponentAlways
error.typestringThe full name of exception type.System.InvalidOperationException; Contoso.MyExceptionIf an exception is thrown.

Usage:

  • Which components are slow to update?
  • Which components are updated often?

Metric: aspnetcore.components.render_diff

NameInstrument TypeUnit (UCUM)Description
aspnetcore.components.render_diff<!--](https://opentelemetry.io/docs/specs/semconv/dotnet/dotnet-http-metrics/#metric-aspnetcorecomponentsrender_diff)-->HistogramsTracks the duration of rendering batches.
AttributeTypeDescriptionExamplesPresence
aspnetcore.components.diff.lengthintThe length of the render diff/size of the batch (bucketed).50Always
error.typestringThe full name of exception type.System.InvalidOperationException; Contoso.MyExceptionIf an exception is thrown.

Usage:

  • Is server rendering slow?
  • Do I render diffs that are too large? (network bandwidth, DOM update)

Microsoft.AspNetCore.Components.Server.Circuits

The Microsoft.AspNetCore.Components.Server.Circuits metrics report information on server-side Blazor circuits in Blazor Server and Blazor Web Apps:

Metric: aspnetcore.components.circuit.active

NameInstrument TypeUnit (UCUM)Description
aspnetcore.components.circuit.active<!--](https://opentelemetry.io/docs/specs/semconv/dotnet/dotnet-http-metrics/#metric-aspnetcorecomponentscircuitactive)-->UpDownCounter{circuit}Shows the number of active circuits currently in memory.

Usage: How much memory does the session state hold?

Metric: aspnetcore.components.circuit.connected

NameInstrument TypeUnit (UCUM)Description
aspnetcore.components.circuit.connected<!--](https://opentelemetry.io/docs/specs/semconv/dotnet/dotnet-http-metrics/#metric-aspnetcorecomponentscircuitconnected)-->UpDownCounter{circuit}Tracks the number of circuits connected to clients.

Usage: How many SignalR connections are open?

Metric: aspnetcore.components.circuit.duration

NameInstrument TypeUnit (UCUM)Description
aspnetcore.components.circuit.duration<!--](https://opentelemetry.io/docs/specs/semconv/dotnet/dotnet-http-metrics/#metric-aspnetcorecomponentscircuitduration)-->HistogramsMeasures circuit lifetime duration and provides total circuit count.

Usage:

  • How many sessions processed?
  • How long do users keep the session/tab open?

:::moniker-end

Microsoft.AspNetCore.Hosting

The Microsoft.AspNetCore.Hosting metrics report high-level information about HTTP requests received by ASP.NET Core:

Metric: http.server.request.duration

NameInstrument TypeUnit (UCUM)Description
http.server.request.durationHistogramsMeasures the duration of inbound HTTP requests.
AttributeTypeDescriptionExamplesPresence
http.routestringThe matched route.{controller}/{action}/
{id?}If it's available.
error.typestringDescribes a class of error the operation ended with.timeout; name_resolution_error; 500If request has ended with an error.
http.request.methodstringHTTP request method.GET; POST; HEADAlways
http.response.status_codeintHTTP response status code.200If one was sent.
network.protocol.versionstringVersion of the protocol specified in network.protocol.name.3.1.1Always
url.schemestringThe URI scheme component identifying the used protocol.http; httpsAlways
aspnetcore.request.is_unhandledBooleanTrue when the request wasn't handled by the application pipeline.trueIf the request was unhandled.

The time used to handle an inbound HTTP request as measured at the hosting layer of ASP.NET Core. The time measurement starts once the underlying web host has:

The time ends when:

  • The ASP.NET Core handler pipeline is finished executing.
  • All response data has been sent.
  • The context data structures for the request are being disposed.

When using OpenTelemetry, the default buckets for this metric are set to [ 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10 ].

Metric: http.server.active_requests

NameInstrument TypeUnit (UCUM)Description
http.server.active_requestsUpDownCounter{request}Measures the number of concurrent HTTP requests that are currently in-flight.
AttributeTypeDescriptionExamplesPresence
http.request.methodstringHTTP request method. [1]GET; POST; HEADAlways
url.schemestringThe URI scheme component identifying the used protocol.http; httpsAlways

Microsoft.AspNetCore.Routing

The Microsoft.AspNetCore.Routing metrics report information about routing HTTP requests to ASP.NET Core endpoints:

Metric: aspnetcore.routing.match_attempts

NameInstrument TypeUnit (UCUM)Description
aspnetcore.routing.match_attemptsCounter{match_attempt}Number of requests that were attempted to be matched to an endpoint.
AttributeTypeDescriptionExamplesPresence
aspnetcore.routing.match_statusstringMatch resultsuccess; failureAlways
aspnetcore.routing.is_fallback_routebooleanA value that indicates whether the matched route is a fallback route.TrueIf a route was successfully matched.
http.routestringThe matched route{controller}/{action}/
{id?}If a route was successfully matched.

Microsoft.AspNetCore.Diagnostics

The Microsoft.AspNetCore.Diagnostics metrics report diagnostics information from ASP.NET Core error handling middleware:

Metric: aspnetcore.diagnostics.exceptions

NameInstrument TypeUnit (UCUM)Description
aspnetcore.diagnostics.exceptionsCounter{exception}Number of exceptions caught by exception handling middleware.
AttributeTypeDescriptionExamplesPresence
aspnetcore.diagnostics.exception.resultstringASP.NET Core exception middleware handling resulthandled; unhandledAlways
aspnetcore.diagnostics.handler.typestringFull type name of the IExceptionHandler implementation that handled the exception.Contoso.MyHandlerIf the exception was handled by this handler.
exception.typestringThe full name of exception type.System.OperationCanceledException; Contoso.MyExceptionAlways

Microsoft.AspNetCore.RateLimiting

The Microsoft.AspNetCore.RateLimiting metrics report rate limiting information from ASP.NET Core rate-limiting middleware:

Metric: aspnetcore.rate_limiting.active_request_leases

NameInstrument TypeUnit (UCUM)Description
aspnetcore.rate_limiting.active_request_leasesUpDownCounter{request}Number of requests that are currently active on the server that hold a rate limiting lease.
AttributeTypeDescriptionExamplesPresence
aspnetcore.rate_limiting.policystringRate limiting policy name.fixed; sliding; tokenIf the matched endpoint for the request had a rate-limiting policy.

Metric: aspnetcore.rate_limiting.request_lease.duration

NameInstrument TypeUnit (UCUM)Description
aspnetcore.rate_limiting.request_lease.durationHistogramsThe duration of the rate limiting lease held by requests on the server.
AttributeTypeDescriptionExamplesPresence
aspnetcore.rate_limiting.policystringRate limiting policy name.fixed; sliding; tokenIf the matched endpoint for the request had a rate-limiting policy.

Metric: aspnetcore.rate_limiting.queued_requests

NameInstrument TypeUnit (UCUM)Description
aspnetcore.rate_limiting.queued_requestsUpDownCounter{request}Number of requests that are currently queued waiting to acquire a rate limiting lease.
AttributeTypeDescriptionExamplesPresence
aspnetcore.rate_limiting.policystringRate limiting policy name.fixed; sliding; tokenIf the matched endpoint for the request had a rate-limiting policy.

Metric: aspnetcore.rate_limiting.request.time_in_queue

NameInstrument TypeUnit (UCUM)Description
aspnetcore.rate_limiting.request.time_in_queueHistogramsThe time a request spent in a queue waiting to acquire a rate limiting lease.
AttributeTypeDescriptionExamplesPresence
aspnetcore.rate_limiting.policystringRate limiting policy name.fixed; sliding; tokenIf the matched endpoint for the request had a rate-limiting policy.
aspnetcore.rate_limiting.resultstringThe rate limiting result shows whether lease was acquired or contains a rejection reason.acquired; request_canceledAlways

Metric: aspnetcore.rate_limiting.requests

NameInstrument TypeUnit (UCUM)Description
aspnetcore.rate_limiting.requestsCounter{request}Number of requests that tried to acquire a rate limiting lease.
AttributeTypeDescriptionExamplesPresence
aspnetcore.rate_limiting.policystringRate limiting policy name.fixed; sliding; tokenIf the matched endpoint for the request had a rate-limiting policy.
aspnetcore.rate_limiting.resultstringThe rate limiting result shows whether lease was acquired or contains a rejection reason.acquired; request_canceledAlways

Microsoft.AspNetCore.HeaderParsing

The Microsoft.AspNetCore.HeaderParsing metrics report information about ASP.NET Core header parsing:

Metric: aspnetcore.header_parsing.parse_errors

NameInstrument TypeUnit (UCUM)Description
aspnetcore.header_parsing.parse_errorsCounter{parse_error}Number of errors that occurred when parsing HTTP request headers.
AttributeTypeDescriptionExamplesPresence
aspnetcore.header_parsing.header.namestringThe header name.Content-TypeAlways
error.typestringThe error message.Unable to parse media type value.Always

Metric: aspnetcore.header_parsing.cache_accesses

The metric is emitted only for HTTP request header parsers that support caching.

NameInstrument TypeUnit (UCUM)Description
aspnetcore.header_parsing.cache_accessesCounter{cache_access}Number of times a cache storing parsed header values was accessed.
AttributeTypeDescriptionExamplesPresence
aspnetcore.header_parsing.header.namestringThe header name.Content-TypeAlways
aspnetcore.header_parsing.cache_access.typestringA value indicating whether the header's value was found in the cache or not.Hit; MissAlways

Microsoft.AspNetCore.Server.Kestrel

The Microsoft.AspNetCore.Server.Kestrel metrics report HTTP connection information from ASP.NET Core Kestrel web server:

Metric: kestrel.active_connections

NameInstrument TypeUnit (UCUM)Description
kestrel.active_connectionsUpDownCounter{connection}Number of connections that are currently active on the server.
AttributeTypeDescriptionExamplesPresence
network.transportstringOSI transport layer or inter-process communication method.tcp; unixAlways
network.typestringOSI network layer or non-OSI equivalent.ipv4; ipv6If the transport is tcp or udp.
server.addressstringServer address domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name.example.comAlways
server.portintServer port number80; 8080; 443If the transport is tcp or udp.

Metric: kestrel.connection.duration

NameInstrument TypeUnit (UCUM)Description
kestrel.connection.durationHistogramsThe duration of connections on the server.
AttributeTypeDescriptionExamplesPresence
error.typestringDescribes a type of error the connection ended with, or the unhandled exception type thrown during the connection pipeline. Known connection errors can be found at Semantic Conventions for Kestrel web server metrics.connection_reset; invalid_request_headers; System.OperationCanceledExceptionIf the connection ended with a known error or an exception was thrown.
network.protocol.namestringOSI application layer or non-OSI equivalent.http; web_socketsAlways
network.protocol.versionstringVersion of the protocol specified in network.protocol.name.1.1; 2Always
network.transportstringOSI transport layer or inter-process communication method.tcp; unixAlways
network.typestringOSI network layer or non-OSI equivalent.ipv4; ipv6If the transport is tcp or udp.
server.addressstringServer address domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name.example.comAlways
server.portintServer port number80; 8080; 443If the transport is tcp or udp.
tls.protocol.versionstringTLS protocol version.1.2; 1.3If the connection is secured with TLS.

As this metric is tracking the connection duration, and ideally http connections are used for multiple requests, the buckets should be longer than those used for request durations. For example, using [ 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 30, 60, 120, 300] provides an upper bucket of 5 mins.

:::moniker range="= aspnetcore-9.0"

When a connection ends with a known error, the error.type attribute value is set to the known error type. Known connection errors can be found at Semantic Conventions for Kestrel web server metrics.

:::moniker-end

Metric: kestrel.rejected_connections

NameInstrument TypeUnit (UCUM)Description
kestrel.rejected_connectionsCounter{connection}Number of connections rejected by the server.
AttributeTypeDescriptionExamplesPresence
network.transportstringOSI transport layer or inter-process communication method.tcp; unixAlways
network.typestringOSI network layer or non-OSI equivalent.ipv4; ipv6If the transport is tcp or udp.
server.addressstringServer address domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name.example.comAlways
server.portintServer port number80; 8080; 443If the transport is tcp or udp.

Connections are rejected when the currently active count exceeds the value configured with MaxConcurrentConnections.

Metric: kestrel.queued_connections

NameInstrument TypeUnit (UCUM)Description
kestrel.queued_connectionsUpDownCounter{connection}Number of connections that are currently queued and are waiting to start.
AttributeTypeDescriptionExamplesPresence
network.transportstringOSI transport layer or inter-process communication method.tcp; unixAlways
network.typestringOSI network layer or non-OSI equivalent.ipv4; ipv6If the transport is tcp or udp.
server.addressstringServer address domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name.example.comAlways
server.portintServer port number80; 8080; 443If the transport is tcp or udp.

Metric: kestrel.queued_requests

NameInstrument TypeUnit (UCUM)Description
kestrel.queued_requestsUpDownCounter{request}Number of HTTP requests on multiplexed connections (HTTP/2 and HTTP/3) that are currently queued and are waiting to start.
AttributeTypeDescriptionExamplesPresence
network.protocol.namestringOSI application layer or non-OSI equivalent.http; web_socketsAlways
network.protocol.versionstringVersion of the protocol specified in network.protocol.name.1.1; 2Always
network.transportstringOSI transport layer or inter-process communication method.tcp; unixAlways
network.typestringOSI network layer or non-OSI equivalent.ipv4; ipv6If the transport is tcp or udp.
server.addressstringServer address domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name.example.comAlways
server.portintServer port number80; 8080; 443If the transport is tcp or udp.

Metric: kestrel.upgraded_connections

NameInstrument TypeUnit (UCUM)Description
kestrel.upgraded_connectionsUpDownCounter{connection}Number of connections that are currently upgraded (WebSockets).
AttributeTypeDescriptionExamplesPresence
network.transportstringOSI transport layer or inter-process communication method.tcp; unixAlways
network.typestringOSI network layer or non-OSI equivalent.ipv4; ipv6If the transport is tcp or udp.
server.addressstringServer address domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name.example.comAlways
server.portintServer port number80; 8080; 443If the transport is tcp or udp.

The counter only tracks HTTP/1.1 connections.

Metric: kestrel.tls_handshake.duration

NameInstrument TypeUnit (UCUM)Description
kestrel.tls_handshake.durationHistogramsThe duration of TLS handshakes on the server.
AttributeTypeDescriptionExamplesPresence
error.typestringThe full name of exception type.System.OperationCanceledException; Contoso.MyExceptionIf an exception was thrown.
network.transportstringOSI transport layer or inter-process communication method.tcp; unixAlways
network.typestringOSI network layer or non-OSI equivalent.ipv4; ipv6If the transport is tcp or udp.
server.addressstringServer address domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name.example.comAlways
server.portintServer port number80; 8080; 443If the transport is tcp or udp.
tls.protocol.versionstringTLS protocol version.1.2; 1.3If the connection is secured with TLS.

When using OpenTelemetry, the default buckets for this metic are set to [ 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10 ].

Metric: kestrel.active_tls_handshakes

NameInstrument TypeUnit (UCUM)Description
kestrel.active_tls_handshakesUpDownCounter{handshake}Number of TLS handshakes that are currently in progress on the server.
AttributeTypeDescriptionExamplesPresence
network.transportstringOSI transport layer or inter-process communication method.tcp; unixAlways
network.typestringOSI network layer or non-OSI equivalent.ipv4; ipv6If the transport is tcp or udp.
server.addressstringServer address domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name.example.comAlways
server.portintServer port number80; 8080; 443If the transport is tcp or udp.

Microsoft.AspNetCore.Http.Connections

The Microsoft.AspNetCore.Http.Connections metrics report connection information from ASP.NET Core SignalR:

Metric: signalr.server.connection.duration

NameInstrument TypeUnit (UCUM)Description
signalr.server.connection.durationHistogramsThe duration of connections on the server.
AttributeTypeDescriptionExamplesPresence
signalr.connection.statusstringSignalR HTTP connection closure status.app_shutdown; timeoutAlways
signalr.transportstringSignalR transport typeweb_sockets; long_pollingAlways
ValueDescription
normal_closureThe connection was closed normally.
timeoutThe connection was closed due to a timeout.
app_shutdownThe connection was closed because the app is shutting down.

signalr.transport is one of the following:

ValueDescription
server_sent_eventsserver-sent events
long_pollingLong Polling
web_socketsWebSocket

As this metric is tracking the connection duration, and ideally SignalR connections are durable, the buckets should be longer than those used for request durations. For example, using [0, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 30, 60, 120, 300] provides an upper bucket of 5 mins.

Metric: signalr.server.active_connections

NameInstrument TypeUnit (UCUM)Description
signalr.server.active_connectionsUpDownCounter{connection}Number of connections that are currently active on the server.
AttributeTypeDescriptionExamplesPresence
signalr.connection.statusstringSignalR HTTP connection closure status.app_shutdown; timeoutAlways
signalr.transportstringSignalR transport typeweb_sockets; long_pollingAlways

:::moniker range=">= aspnetcore-10.0"

Microsoft.AspNetCore.Authorization

The Microsoft.AspNetCore.Authorization metrics report information about Authorization attempts in ASP.NET Core apps:

Metric: aspnetcore.authorization.attempts

NameInstrument TypeUnit (UCUM)Description
aspnetcore.authorization.attemptsCounter{request}The total number of requests for which authorization was attempted.
AttributeTypeDescriptionExamplesPresence
user.is_authenticatedbooleanWhether the request came from an authenticated usertrueRequired
aspnetcore.authorization.policystringThe name of the authorization policy.AtLeast21; EmployeeOnlyConditionally required if an authorization policy is used.
aspnetcore.authorization.resultstringWhether the authorization succeeded or failed.success; failureConditionally Required if an exception is not thrown during authorization.
error.typestringThe full name of the exception type.System.InvalidOperationException; Contoso.MyExceptionConditionally Required if the request has ended with an error.

Microsoft.AspNetCore.Authentication

The Microsoft.AspNetCore.Authentication metrics report information about Authentication in ASP.NET Core apps:

Metric: aspnetcore.authentication.authenticate.duration

NameInstrument TypeUnit (UCUM)Description
aspnetcore.authentication.authenticate.durationHistogramsThe authentication duration for a request.
AttributeTypeDescriptionExamplesPresence
aspnetcore.authentication.resultstringThe authentication result.success; failure; none; _OTHERConditionally Required if the request did not end with an error.
aspnetcore.authentication.schemestringThe name of the authentication scheme.Bearer; CookiesConditionally Required if the request did not end with an error.
error.typestringThe full name of the exception type.System.InvalidOperationException; Contoso.MyExceptionConditionally Required if authentication failed or the request. has ended with an error.

Metric: aspnetcore.authentication.challenges

NameInstrument TypeUnit (UCUM)Description
aspnetcore.authentication.challengesCounter{request}The total number of times a scheme is challenged.
AttributeTypeDescriptionExamplesPresence
aspnetcore.authentication.schemestringThe name of the authentication scheme.Bearer; CookiesConditionally Required if the request did not end with an error.
error.typestringThe full name of the exception type.System.InvalidOperationException; Contoso.MyExceptionConditionally Required if the request has ended with an error.

Metric: aspnetcore.authentication.forbids

NameInstrument TypeUnit (UCUM)Description
aspnetcore.authentication.forbidsCounter{request}The total number of times an authenticated user attempts to access a resource they aren't permitted to access.
AttributeTypeDescriptionExamplesPresence
aspnetcore.authentication.schemestringThe name of the authentication scheme.Bearer; CookiesConditionally Required if the request did not end with an error.
error.typestringThe full name of the exception type.System.InvalidOperationException; Contoso.MyExceptionConditionally Required if the request has ended with an error.

Metric: aspnetcore.authentication.sign_ins

NameInstrument TypeUnit (UCUM)Description
aspnetcore.authentication.sign_insCounter{request}The total number of times a principal is signed in with a scheme.
AttributeTypeDescriptionExamplesPresence
aspnetcore.authentication.schemestringThe name of the authentication scheme.Bearer; CookiesConditionally Required if the request did not end with an error.
error.typestringThe full name of the exception type.System.InvalidOperationException; Contoso.MyExceptionConditionally Required if the request has ended with an error.

Metric: aspnetcore.authentication.sign_outs

NameInstrument TypeUnit (UCUM)Description
aspnetcore.authentication.sign_outsCounter{request}The total number of times a principal is signed out with a scheme.
AttributeTypeDescriptionExamplesPresence
aspnetcore.authentication.schemestringThe name of the authentication scheme.Bearer; CookiesConditionally Required if the request did not end with an error.
error.typestringThe full name of the exception type.System.InvalidOperationException; Contoso.MyExceptionConditionally Required if the request has ended with an error.

:::moniker-end