opentelemetry-dotnet
opentelemetry-dotnet copied to clipboard
Fix ASP.NET Core ExceptionFilter prevents recording exception
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:
- [x] Appropriate
CHANGELOG.md
updated for non-trivial changes - [ ] Design discussion issue #
- [ ] Changes in public API reviewed
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
D:\a\opentelemetry-dotnet\opentelemetry-dotnet\test\OpenTelemetry.Instrumentation.AspNetCore.Tests\BasicTests.cs(665,29): error SA1204: Static members should appear before non-static members [D:\a\opentelemetry-dotnet\opentelemetry-dotnet\test\OpenTelemetry.Instrumentation.AspNetCore.Tests\OpenTelemetry.Instrumentation.AspNetCore.Tests.csproj]
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.
src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md:3 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Unreleased"]
Fixed! Sorry about that.
Codecov Report
Merging #3475 (dfd3202) into main (968dc52) will increase coverage by
0.03%
. The diff coverage is100.00%
.
@@ 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
Impacted Files | Coverage Δ | |
---|---|---|
...DiagnosticSourceInstrumentation/PropertyFetcher.cs | 92.50% <100.00%> (-4.56%) |
:arrow_down: |
...tation/OpenTelemetryProtocolExporterEventSource.cs | 75.00% <0.00%> (-20.00%) |
:arrow_down: |
...porter.OpenTelemetryProtocol/OtlpMetricExporter.cs | 72.72% <0.00%> (-13.64%) |
:arrow_down: |
src/OpenTelemetry/BatchExportProcessor.cs | 82.24% <0.00%> (-1.87%) |
:arrow_down: |
...Telemetry/Internal/SelfDiagnosticsEventListener.cs | 96.87% <0.00%> (-0.79%) |
:arrow_down: |
...metryProtocol/Implementation/ActivityExtensions.cs | 96.15% <0.00%> (+1.09%) |
:arrow_up: |
...tation.AspNetCore/Implementation/HttpInListener.cs | 91.41% <0.00%> (+1.22%) |
:arrow_up: |
src/OpenTelemetry/Logs/OpenTelemetryLogger.cs | 88.88% <0.00%> (+2.22%) |
:arrow_up: |
...tpListener/Internal/PrometheusCollectionManager.cs | 80.48% <0.00%> (+2.43%) |
:arrow_up: |
... and 3 more |
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.) Given we have reference to AspNetCore.App (for new runtimes..), we should discuss if we can use the Public types which are the payload, instead of relying on reflection.
@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 else if (string.Compare(value.Key, "OnException", StringComparison.OrdinalIgnoreCase) == 0)
. The only concern is if it could break some other use-case, but at this point is valid to consider adding some more else ifs
to the code in order to cover those.
Related issue: #2853
Related issue: https://github.com/open-telemetry/opentelemetry-dotnet/issues/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