Conversation
Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
...onents/WebAssembly/WebAssembly/test/Microsoft.AspNetCore.Components.WebAssembly.Tests.csproj
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
This PR aligns WebAssembly host telemetry registration with server-side Blazor by enabling metrics and tracing by default during host initialization. Previously, WebAssembly hosts did not automatically register ComponentsMetrics and ComponentsActivitySource, creating an inconsistency with the server render mode.
Key Changes:
- Added automatic registration of
ComponentsMetricsandComponentsActivitySourceinWebAssemblyHostBuilder.InitializeDefaultServices() - Added
Microsoft.Extensions.Diagnosticsdependency to both source and test projects - Added test coverage verifying
IMeterFactoryregistration
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Components/WebAssembly/WebAssembly/src/Microsoft.AspNetCore.Components.WebAssembly.csproj | Added Microsoft.Extensions.Diagnostics package reference required for metrics functionality |
| src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyHostBuilder.cs | Registered ComponentsMetrics and ComponentsTracing services in InitializeDefaultServices method |
| src/Components/WebAssembly/WebAssembly/test/Microsoft.AspNetCore.Components.WebAssembly.Tests.csproj | Added Microsoft.Extensions.Diagnostics package reference for test project |
| src/Components/WebAssembly/WebAssembly/test/Hosting/WebAssemblyHostBuilderTest.cs | Added test to verify IMeterFactory registration, confirming metrics services are available |
src/Components/WebAssembly/WebAssembly/test/Hosting/WebAssemblyHostBuilderTest.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
This comes with increased download size. Please quantify the download size difference.
Please also make it opt-in (IL trimable), not always included.
Probably behind existing <MetricsSupport>true</MetricsSupport>.
There was a problem hiding this comment.
We have benchmarks that tell us about size regressions. We've never measured the size diff on every change for wasm stuff.
Please also make it opt-in (IL trimable), not always included.
Is there an AppContextSwitch for this?
We will want to make this work by default and be opt-out rather than opt-in since it will otherwise force people to jump through more hoops for something that we want to be easy.
There was a problem hiding this comment.
System.Diagnostics.Metrics.Meter.IsSupported
There was a problem hiding this comment.
@copilot register the services behind System.Diagnostics.Metrics.Meter.IsSupported (don't use the fully qualified name, add the using if needed). Check with the microsoft docs if there is a different check for traces we could use, if there is, use that, if not, Meter.IsSupported is good enough.
There was a problem hiding this comment.
Registered metrics and tracing services behind the System.Diagnostics.Metrics.Meter.IsSupported feature switch check using AppContext.TryGetSwitch. Services are now opt-out (enabled by default, can be disabled via the feature switch). Commit bc57528.
There was a problem hiding this comment.
We will want to make this work by default and be opt-out rather than opt-in
I disagree
#64575 (comment)
Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyHostBuilder.cs
Outdated
Show resolved
Hide resolved
…metryEnabled Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
Head branch was pushed to by a user without write access
|
Thank you! |
Register Components metrics and tracing in WebAssembly host with opt-in support
Enable WebAssembly host to register metrics and tracing services when explicitly enabled via feature switch.
Description
WebAssembly host can now register metrics and tracing services during initialization when the
System.Diagnostics.Metrics.Meter.IsSupportedfeature switch is enabled. Services are disabled by default (opt-in) to keep bundle sizes minimal, and can be enabled by setting the AppContext switch totrue.Changes:
Microsoft.Extensions.Diagnosticsreference to WebAssembly project (brought in transitively to test project)ComponentsMetricsandComponentsActivitySourceinWebAssemblyHostBuilder.InitializeDefaultServices()behind feature switch checkSystem.Diagnostics.Metrics.Meter.IsSupportedAppContext switch totrueThis allows developers to enable consistent telemetry collection across Blazor hosting modes when needed, while keeping WebAssembly bundle sizes minimal by default through the opt-in feature switch mechanism.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.