Skip to content

Commit 22f30fb

Browse files
committed
Updates
1 parent 4367912 commit 22f30fb

File tree

2 files changed

+92
-2
lines changed

2 files changed

+92
-2
lines changed

aspnetcore/blazor/performance/index.md

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
title: ASP.NET Core Blazor performance best practices
33
author: guardrex
4-
description: Tips for increasing the performance of ASP.NET Core Blazor apps and avoiding common performance problems.
4+
description: Guidance on ASP.NET Core Blazor metrics and tracing, improving app performance, and avoiding common performance problems.
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: wpickett
77
ms.custom: mvc
8-
ms.date: 04/16/2025
8+
ms.date: 06/08/2025
99
uid: blazor/performance/index
1010
---
1111
# ASP.NET Core Blazor performance best practices
@@ -24,3 +24,87 @@ Blazor is optimized for high performance in most realistic application UI scenar
2424
Ahead-of-time (AOT) compilation compiles a Blazor app's .NET code directly into native WebAssembly for direct execution by the browser. AOT-compiled apps result in larger apps that take longer to download, but AOT-compiled apps usually provide better runtime performance, especially for apps that execute CPU-intensive tasks. For more information, see <xref:blazor/tooling/webassembly#ahead-of-time-aot-compilation>.
2525

2626
:::moniker-end
27+
28+
:::moniker range=">= aspnetcore-10.0"
29+
30+
## Metrics and tracing
31+
32+
Metrics and tracing capabilities help you monitor and diagnose app performance, track user interactions, and understand component behavior in production environments.
33+
34+
### Configuration
35+
36+
To enable Blazor metrics and tracing in your app, configure [OpenTelemetry](https://github.com/open-telemetry/opentelemetry-dotnet) with the following meters and activity sources in the app's `Program` file where services are registered:
37+
38+
```csharp
39+
builder.Services.ConfigureOpenTelemetryMeterProvider(meterProvider =>
40+
{
41+
meterProvider.AddMeter("Microsoft.AspNetCore.Components");
42+
meterProvider.AddMeter("Microsoft.AspNetCore.Components.Lifecycle");
43+
meterProvider.AddMeter("Microsoft.AspNetCore.Components.Server.Circuits");
44+
});
45+
46+
builder.Services.ConfigureOpenTelemetryTracerProvider(tracerProvider =>
47+
{
48+
tracerProvider.AddSource("Microsoft.AspNetCore.Components");
49+
});
50+
```
51+
52+
### Performance meters
53+
54+
`Microsoft.AspNetCore.Components` meter:
55+
56+
* `aspnetcore.components.navigation`: Tracks the total number of route changes in the app.
57+
* `aspnetcore.components.event_handler`: Measures the duration of processing browser events, including business logic.
58+
59+
`Microsoft.AspNetCore.Components.Lifecycle` meter:
60+
61+
* `aspnetcore.components.update_parameters`: Measures the duration of processing component parameters, including business logic.
62+
* `aspnetcore.components.render_diff`: Tracks the duration of rendering batches.
63+
64+
`Microsoft.AspNetCore.Components.Server.Circuits` meter:
65+
66+
In server-side Blazor apps, additional circuit-specific metrics include:
67+
68+
* `aspnetcore.components.circuit.active`: Shows the number of active circuits currently in memory.
69+
* `aspnetcore.components.circuit.connected`: Tracks the number of circuits connected to clients.
70+
* `aspnetcore.components.circuit.duration`: Measures circuit lifetime duration and provides total circuit count.
71+
72+
### Blazor tracing
73+
74+
The new activity tracing capabilities use the `Microsoft.AspNetCore.Components` activity source and provide three main types of tracing activities: circuit lifecycle, navigation, and event handling.
75+
76+
Circuit lifecycle tracing:
77+
78+
`Microsoft.AspNetCore.Components.CircuitStart`: Traces circuit initialization with the format `Circuit {circuitId}`.
79+
80+
* Tag: `aspnetcore.components.circuit.id`
81+
* Link: HTTP activity
82+
83+
Navigation tracing:
84+
85+
`Microsoft.AspNetCore.Components.RouteChange`: Tracks route changes with the format `Route {route} -> {componentType}`.
86+
87+
* Tags
88+
* `aspnetcore.components.circuit.id`
89+
* `aspnetcore.components.route`
90+
* `aspnetcore.components.type`
91+
* Links
92+
* HTTP trace
93+
* Circuit trace
94+
95+
Event handling tracing:
96+
97+
`Microsoft.AspNetCore.Components.HandleEvent`: Traces event handling with the format `Event {attributeName} -> {componentType}.{methodName}`.
98+
99+
* Tags
100+
* `aspnetcore.components.attribute.name`
101+
* `aspnetcore.components.circuit.id`
102+
* `aspnetcore.components.method`
103+
* `aspnetcore.components.type`
104+
* `error.type`
105+
* Links
106+
* HTTP trace
107+
* Circuit trace
108+
* Router trace
109+
110+
:::moniker-end

aspnetcore/release-notes/aspnetcore-10/includes/blazor.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,3 +416,9 @@ Blazor now provides an improved way to display a "Not Found" page when navigatin
416416
The Blazor project template now includes a `NotFound.razor` page by default. This page automatically renders whenever `NavigationManager.NotFound` is called in your app, making it easier to handle missing routes with a consistent user experience.
417417

418418
For more information, see <xref:blazor/fundamentals/routing#not-found-responses>.
419+
420+
### Metrics and tracing
421+
422+
This release introduces comprehensive metrics and tracing capabilities for Blazor apps, providing detailed observability of the component lifecycle, navigation, event handling, and circuit management.
423+
424+
For more information, see <xref:blazor/performance/index#metrics-and-tracing>.

0 commit comments

Comments
 (0)