-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Don't add "unknown" to Blazor metrics tags when values are null #63351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…azor metrics Co-authored-by: JamesNK <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR removes the addition of "unknown" tag values in Blazor ComponentsMetrics when actual values are null, following telemetry best practices where tags should only be present when they have meaningful values.
- Replaces inline tag creation with conditional helper methods that only add tags when values are not null
- Updates all metric recording methods to use the new helper pattern instead of the
?? "unknown"
fallback - Adds comprehensive test coverage to verify that null values result in omitted tags rather than "unknown" values
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
src/Components/Components/src/ComponentsMetrics.cs | Refactors tag creation to use conditional helper methods instead of "unknown" fallbacks |
src/Components/Components/test/ComponentsMetricsTest.cs | Adds test coverage for null value scenarios to verify tags are properly omitted |
|
This is not related, merge with main: #63358 |
@copilot, merge this branch with main. |
Co-authored-by: ilonatommy <[email protected]>
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
/backport to release/10.0-rc1 |
Started backporting to release/10.0-rc1: https://github.com/dotnet/aspnetcore/actions/runs/17156650495 |
This PR addresses the issue where Blazor ComponentsMetrics was adding "unknown" as tag values when the actual values were null, instead of omitting the tags entirely.
Problem
The current implementation in
ComponentsMetrics.cs
uses the patterncomponentType ?? "unknown"
when adding tags to telemetry measurements. This results in metrics containing tags with "unknown" values even when no meaningful value is available:This behavior is inconsistent with other ASP.NET Core metrics implementations and telemetry best practices, where tags should only be present when they have meaningful values.
Solution
Following the established pattern used in Identity metrics (
SignInManagerMetrics
,UserManagerMetrics
), this PR:Introduces helper methods that conditionally add tags only when values are not null:
AddComponentTypeTag
AddRouteTag
AddMethodNameTag
AddAttributeNameTag
AddErrorTag
Updates all metric recording methods to use these helper methods instead of the
?? "unknown"
pattern:Navigation
CaptureEventDuration
FailEventSync
CaptureParametersDuration
FailParametersSync
CaptureBatchDuration
FailBatchSync
Adds comprehensive tests to verify that tags are properly omitted when null values are passed.
Example
Before this change:
After this change:
This change makes Blazor metrics consistent with the rest of the ASP.NET Core telemetry ecosystem and follows OpenTelemetry best practices for conditional tag inclusion.
Fixes #63350.
💡 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.