Skip to content

Commit a8f21ec

Browse files
.NET 10 metrics /1 (#35129)
* .NET 10 metrics /1 * .NET 10 metrics /1 * .NET 10 metrics /1 * .NET 10 metrics /1 * .NET 10 metrics /1 * .NET 10 metrics /1 * Update aspnetcore/log-mon/metrics/built-in/includes/built-in10.md Co-authored-by: Copilot <[email protected]> * .NET 10 metrics /1 * .NET 10 metrics /1 * .NET 10 metrics /1 * .NET 10 metrics /1 * .NET 10 metrics /1 * .NET 10 metrics /1 --------- Co-authored-by: Copilot <[email protected]>
1 parent 6989b98 commit a8f21ec

File tree

3 files changed

+104
-8
lines changed

3 files changed

+104
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: ASP.NET Core built-in metrics
33
description: Built-in metrics for ASP.NET Core apps
44
author: rick-anderson
55
ms.author: riande
6-
ms.date: 10/18/2023
6+
ms.date: 4/8/2025
77
ms.topic: reference
88
uid: log-mon/metrics/built-in
99
---

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

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
:::moniker range=">= aspnetcore-10.0"
22

33
This article describes the metrics built-in for ASP.NET Core produced using the
4-
<xref:System.Diagnostics.Metrics?displayProperty=nameWithType> API. For a listing of metrics based on the older [EventCounters](/dotnet/core/diagnostics/event-counters) API,see [Available counters](/dotnet/core/diagnostics/available-counters).
4+
<xref:System.Diagnostics.Metrics?displayProperty=nameWithType> API. For a listing of metrics based on the older [EventCounters](/dotnet/core/diagnostics/event-counters) API, see [Available counters](/dotnet/core/diagnostics/available-counters).
55

66
See [Using ASP.NET Core metrics](xref:log-mon/metrics/metrics) for information about how to collect, report, enrich, and test ASP.NET Core metrics
77

@@ -400,4 +400,98 @@ As this metric is tracking the connection duration, and ideally SignalR connecti
400400
| `signalr.transport` | string | [SignalR transport type](https://github.com/dotnet/aspnetcore/blob/main/src/SignalR/docs/specs/TransportProtocols.md) | `web_sockets`; `long_polling` | Always |
401401

402402
.
403+
404+
## `Microsoft.AspNetCore.Authorization`
405+
406+
The `Microsoft.AspNetCore.Authorization` metrics report information about [Authorization attempts](xref:security/authorization/introduction) in ASP.NET Core apps:
407+
408+
#### Metric: `aspnetcore.authorization.attempts`
409+
410+
| Name | Instrument Type | Unit (UCUM) | Description |
411+
| -------- | --------------- | ----------- | -------------- |
412+
| `aspnetcore.authorization.attempts` <!--(https://opentelemetry.io/docs/specs/semconv/dotnet/dotnet-aspnetcore-metrics/)--> | Counter | `{request}` | The total number of requests for which authorization was attempted. |
413+
414+
| Attribute | Type | Description | Examples | Presence |
415+
|---|---|---|---|---|
416+
| `user.is_authenticated` | boolean | Whether the request came from an authenticated user | `true` | `Required` |
417+
| `aspnetcore.authorization.policy` | string | The name of the authorization policy. | `AtLeast21`; `EmployeeOnly` | `Conditionally required` if an authorization policy is used |
418+
| `aspnetcore.authorization.result` | string | Whether the authorization succeeded or failed. | `success`; `failure` | `Conditionally Required` if an exception is not thrown during authorization |
419+
| `error.type` | string | The full name of the exception type. | `System.InvalidOperationException`; `Contoso.MyException` | `Conditionally Required` if the request has ended with an error |
420+
421+
.
422+
423+
## `Microsoft.AspNetCore.Authentication`
424+
425+
The `Microsoft.AspNetCore.Authentication` metrics report information about [Authentication](xref:security/authentication/index) in ASP.NET Core apps:
426+
427+
- [`aspnetcore.authentication.authenticate.duration`](#metric-aspnetcoreauthenticationauthenticateduration)
428+
- [`aspnetcore.authentication.challenges`](#metric-aspnetcoreauthenticationchallenges)
429+
- [`aspnetcore.authentication.forbids`](#metric-aspnetcoreauthenticationforbids)
430+
- [`aspnetcore.authentication.sign_ins`](#metric-aspnetcoreauthenticationsign_ins)
431+
- [`aspnetcore.authentication.sign_outs`](#metric-aspnetcoreauthenticationsign_outs)
432+
433+
#### Metric: `aspnetcore.authentication.authenticate.duration`
434+
435+
| Name | Instrument Type | Unit (UCUM) | Description |
436+
| -------- | --------------- | ----------- | -------------- |
437+
| `aspnetcore.authentication.authenticate.duration` <!--(https://opentelemetry.io/docs/specs/semconv/dotnet/dotnet-aspnetcore-metrics/)--> | Histogram | `s` | The authentication duration for a request. |
438+
439+
| Attribute | Type | Description | Examples | Presence |
440+
|---|---|---|---|---|
441+
| `aspnetcore.authentication.result` | string | The authentication result. | `success`; `failure`; `none`; `_OTHER` | `Conditionally Required` if the request did not end with an error |
442+
| `aspnetcore.authentication.scheme` | string | The name of the authentication scheme. | `Bearer`; `Cookies` | `Conditionally Required` if the request did not end with an error |
443+
| `error.type` | string | The full name of the exception type. | `System.InvalidOperationException`; `Contoso.MyException` | `Conditionally Required` if authentication failed or the request has ended with an error |
444+
445+
.
446+
447+
#### Metric: `aspnetcore.authentication.challenges`
448+
449+
| Name | Instrument Type | Unit (UCUM) | Description |
450+
| -------- | --------------- | ----------- | -------------- |
451+
| `aspnetcore.authentication.challenges` <!--(https://opentelemetry.io/docs/specs/semconv/dotnet/dotnet-aspnetcore-metrics/)--> | Counter | `{request}` | The total number of times a scheme is challenged. |
452+
453+
| Attribute | Type | Description | Examples | Presence |
454+
|---|---|---|---|---|
455+
| `aspnetcore.authentication.scheme` | string | The name of the authentication scheme. | `Bearer`; `Cookies` | `Conditionally Required` if the request did not end with an error |
456+
| `error.type` | string | The full name of the exception type. | `System.InvalidOperationException`; `Contoso.MyException` | `Conditionally Required` if the request has ended with an error |
457+
458+
.
459+
460+
#### Metric: `aspnetcore.authentication.forbids`
461+
462+
| Name | Instrument Type | Unit (UCUM) | Description |
463+
| -------- | --------------- | ----------- | -------------- |
464+
| `aspnetcore.authentication.forbids` <!--(https://opentelemetry.io/docs/specs/semconv/dotnet/dotnet-aspnetcore-metrics/)--> | Counter | `{request}` | The total number of times an authenticated user attempts to access a resource they aren't permitted to access. |
465+
466+
| Attribute | Type | Description | Examples | Presence |
467+
|---|---|---|---|---|
468+
| `aspnetcore.authentication.scheme` | string | The name of the authentication scheme. | `Bearer`; `Cookies` | `Conditionally Required` if the request did not end with an error |
469+
| `error.type` | string | The full name of the exception type. | `System.InvalidOperationException`; `Contoso.MyException` | `Conditionally Required` if the request has ended with an error |
470+
471+
.
472+
473+
#### Metric: `aspnetcore.authentication.sign_ins`
474+
475+
| Name | Instrument Type | Unit (UCUM) | Description |
476+
| -------- | --------------- | ----------- | -------------- |
477+
| `aspnetcore.authentication.sign_ins` <!--(https://opentelemetry.io/docs/specs/semconv/dotnet/dotnet-aspnetcore-metrics/)--> | Counter | `{request}` | The total number of times a principal is signed in with a scheme. |
478+
479+
| Attribute | Type | Description | Examples | Presence |
480+
|---|---|---|---|---|
481+
| `aspnetcore.authentication.scheme` | string | The name of the authentication scheme. | `Bearer`; `Cookies` | `Conditionally Required` if the request did not end with an error |
482+
| `error.type` | string | The full name of the exception type. | `System.InvalidOperationException`; `Contoso.MyException` | `Conditionally Required` if the request has ended with an error |
483+
484+
.
485+
486+
#### Metric: `aspnetcore.authentication.sign_outs`
487+
488+
| Name | Instrument Type | Unit (UCUM) | Description |
489+
| -------- | --------------- | ----------- | -------------- |
490+
| `aspnetcore.authentication.sign_outs` <!--(https://opentelemetry.io/docs/specs/semconv/dotnet/dotnet-aspnetcore-metrics/)--> | Counter | `{request}` | The total number of times a principal is signed out with a scheme. |
491+
492+
| Attribute | Type | Description | Examples | Presence |
493+
|---|---|---|---|---|
494+
| `aspnetcore.authentication.scheme` | string | The name of the authentication scheme. | `Bearer`; `Cookies` | `Conditionally Required` if the request did not end with an error |
495+
| `error.type` | string | The full name of the exception type. | `System.InvalidOperationException`; `Contoso.MyException` | `Conditionally Required` if the request has ended with an error |
496+
403497
:::moniker-end

aspnetcore/log-mon/metrics/metrics.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ Metrics are numerical measurements reported over time. They're typically used to
1919

2020
These metrics can be reported to a monitoring system at regular intervals. Dashboards can be setup to view metrics and alerts created to notify people of problems. If the web service is intended to respond to requests within 400 ms and starts responding in 600 ms, the monitoring system can notify the operations staff that the app response is slower than normal.
2121

22-
> [!TIP]
23-
> See [ASP.NET Core metrics](/dotnet/core/diagnostics/built-in-metrics-aspnetcore) for a comprehensive list of all instruments together with their attributes.
22+
See [ASP.NET Core metrics](xref:log-mon/metrics/built-in) for a comprehensive list of all instruments together with their attributes.
2423

25-
## Using metrics
24+
## Use metrics
2625

27-
There are two parts to using metrics in a .NET app:
26+
Using metrics involves the following:
2827

2928
* **Instrumentation:** Code in .NET libraries takes measurements and associates these measurements with a metric name. .NET and ASP.NET Core include many built-in metrics.
30-
* **Collection:** A .NET app configures named metrics to be transmitted from the app for external storage and analysis. Some tools may perform configuration outside the app using configuration files or a UI tool.
29+
* **Collection and storage:** A .NET app configures named metrics to be transmitted from the app for external storage and analysis. Some tools may perform configuration outside the app using configuration files or a UI tool.
30+
* **Visualization:** A tool that can display the metrics in a human-readable format. For example, [Grafana](https://grafana.com/) and [Prometheus](https://prometheus.io/).
31+
* **Alerting:** A tool that provides notifications when a metric exceeds a threshold. For example, if the average response time for a web service exceeds 400 ms, an alert can be sent to the operations staff.
32+
* **Analysis:** A tool that can analyze the metrics over time. This is often a web-based dashboard that can be customized to show the most important metrics for a specific app.
3133

32-
Instrumented code can record numeric measurements, but the measurements need to be aggregated, transmitted, and stored to create useful metrics for monitoring. The process of aggregating, transmitting, and storing data is called collection. This tutorial shows several examples of collecting metrics:
34+
Instrumented code can record numeric measurements, but the measurements need to be aggregated, transmitted, and stored to create useful metrics for monitoring. The process of aggregating, transmitting, and storing data is called collection. This tutorial shows several examples of collecting and displaying metrics:
3335

3436
* Populating metrics in [Grafana](https://grafana.com/) with [OpenTelemetry](https://opentelemetry.io/) and [Prometheus](https://prometheus.io/).
3537
* Viewing metrics in real time with [`dotnet-counters`](/dotnet/core/diagnostics/dotnet-counters)

0 commit comments

Comments
 (0)