-
Notifications
You must be signed in to change notification settings - Fork 774
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
Fix ASP.NET Core ExceptionFilter prevents recording exception #3475
Conversation
…tion data wouldn't be collected
src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs
Outdated
Show resolved
Hide resolved
…y-dotnet into fix-exceptionfilter
…sue has changed. this commit reflects that
test/OpenTelemetry.Instrumentation.AspNetCore.Tests/ExceptionFilterTests.cs
Outdated
Show resolved
Hide resolved
test/OpenTelemetry.Instrumentation.AspNetCore.Tests/ExceptionFilterTests.cs
Outdated
Show resolved
Hide resolved
test/OpenTelemetry.Instrumentation.AspNetCore.Tests/ExceptionFilterTests.cs
Outdated
Show resolved
Hide resolved
A few small CI failures to resolve Static analysis enforces style guidelines. You should be able to produce this locally, but might need to do a release build
We use markdownlint to enforce style in markdown files. You could run this locally too following instructions here, but in your case it looks you just need to add a newline after a header.
|
Fixed! Sorry about that. |
Codecov Report
@@ Coverage Diff @@
## main #3475 +/- ##
==========================================
+ Coverage 87.26% 87.29% +0.03%
==========================================
Files 277 277
Lines 9938 9944 +6
==========================================
+ Hits 8672 8681 +9
+ Misses 1266 1263 -3
|
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.
LGTM, thanks @al-mac!
If you can make it, we have a .NET SIG meeting tomorrow at 11 am Pacific. I plan to discuss your PR. Part of me wonders if we should do something different in the future to prevent OnException
and other methods from being invoked in scenarios we did not originally intend for.
My thought is maybe being explicit with the event names we handle versus doing an EndsWith("Exception")
here
opentelemetry-dotnet/src/OpenTelemetry/DiagnosticSourceInstrumentation/DiagnosticSourceListener.cs
Lines 60 to 63 in 6f2b1a0
else if (value.Key.EndsWith("Exception", StringComparison.Ordinal)) | |
{ | |
this.handler.OnException(Activity.Current, value.Value); | |
} |
Thanks for this PR @al-mac ! @alanwest Please do add this to SIG discussion. I was chatting offline with @vishweshbankwar for some potential improvements in this area as well. (Its related to how leveraging Activity.Current in non Start/End path could result in fetching unintended Activity.) |
@alanwest thanks! Unfortunately I won't be able to attend the meeting. Nice catch on the potential change on the DiagnosticSourceListener.cs. The specific scenario that we worked on this PR will probably never happen if this changes to something like |
@@ -550,6 +552,48 @@ void ConfigureTestServices(IServiceCollection services) | |||
Assert.Equal(shouldEnrichBeCalled, enrichCalled); | |||
} | |||
|
|||
[Fact] | |||
public async Task ShouldExportActivityWithOneExceptionFilter() |
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.
Minor: Both tests could be combined into one like
[Theory]
[InlineData(1)]
[InlineData(2)]
public async Task ShouldExportSingleActivityWithOneOrMoreExceptionFilters(int mode)
.
.
.
Related issue: #2853 |
👍 ah, good find! I've updated the description since this PR should resolve the issue. |
This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or Pushing will instruct the bot to automatically remove the label. This bot runs once per day. |
This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or Pushing will instruct the bot to automatically remove the label. This bot runs once per day. |
Closed as inactive. Feel free to reopen if this PR is still being worked on. |
@al-mac apologies for the delay on this PR! We just discussed it today and would like to get it merged. Would you mind resolving the conflicts? |
@alanwest not at all! i'll work on it later today |
Fixes #2853
ASP.NET Core exception filters fire events before and after filter execution.
Before:
https://github.com/dotnet/aspnetcore/blob/36df8e5dc487e27cb85674ef3f144dca07f05c20/src/Mvc/Mvc.Core/src/MvcCoreDiagnosticListenerExtensions.cs#L396-L402
After:
https://github.com/dotnet/aspnetcore/blob/c85baf8db0c72ae8e68643029d514b2e737c9fae/src/Mvc/Mvc.Core/src/MvcCoreDiagnosticListenerExtensions.cs#L422-L434
The ASP.NET Core instrumentation's
OnException
event is invoked when these events fire. The payload of the event differs from that of the regular exception path and precludes the exception from being recorded (if enabled) and the span status from being set.Changes
Please provide a brief description of the changes here.
For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes