Skip to content

Fix duplicate error.type tags #55211

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

Merged
merged 3 commits into from
Apr 22, 2024
Merged

Fix duplicate error.type tags #55211

merged 3 commits into from
Apr 22, 2024

Conversation

JamesNK
Copy link
Member

@JamesNK JamesNK commented Apr 19, 2024

Fixes #55159

Duplicate metrics tags can break some telemetry tooling. It's possible to have ASP.NET Core add multiple error.type tags to a counter. That's bad and should be fixed.

error.type can be added by exception middleware and it can be added in hosting if there is an unhandled exception. That means there can be duplicates if:

  • Exception handling middleware handles an exception (tag added in middleware) and then there is an unhandled exception afterwards (tag added in hosting)
  • Two configured exception handling middleware instances. An error is thrown and is handled (tag added in middleware 1) and then afterwards another error is thrown and handled by the second middleware (tag added in middleware 2).

Fix by conditionally adding error.type to tag collection only if it isn't present, aka first value wins.

Before (duplicate tags):

image

After (one tag):

image

@JamesNK JamesNK merged commit b932bca into main Apr 22, 2024
26 checks passed
@JamesNK JamesNK deleted the jamesnk/metrics-exceptiontags branch April 22, 2024 21:42
@dotnet-policy-service dotnet-policy-service bot added this to the 9.0-preview4 milestone Apr 22, 2024
@JamesNK
Copy link
Member Author

JamesNK commented Apr 22, 2024

/backport to release/8.0

Copy link
Contributor

Started backporting to release/8.0: https://github.com/dotnet/aspnetcore/actions/runs/8792220010

Copy link
Contributor

@JamesNK backporting to release/8.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: Fix duplicate error.type tags
.git/rebase-apply/patch:351: new blank line at EOF.
+
warning: 1 line adds whitespace errors.
Using index info to reconstruct a base tree...
M	src/Hosting/Hosting/src/Internal/HostingMetrics.cs
M	src/Middleware/Diagnostics/test/FunctionalTests/TestFixture.cs
M	src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs
CONFLICT (content): Merge conflict in src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerTest.cs
Auto-merging src/Middleware/Diagnostics/test/FunctionalTests/TestFixture.cs
Auto-merging src/Hosting/Hosting/src/Internal/HostingMetrics.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Fix duplicate error.type tags
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

Copy link
Contributor

@JamesNK an error occurred while backporting to release/8.0, please check the run log for details!

Error: git am failed, most likely due to a merge conflict.

JamesNK added a commit that referenced this pull request Apr 22, 2024
wtgodbe pushed a commit that referenced this pull request May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-hosting Includes Hosting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exception middlewares introduce duplicates of error.type diagnostic tags in some situations
2 participants