-
Notifications
You must be signed in to change notification settings - Fork 854
Throw NotSupportedException when using SetErrorStatusOnException in Mono Runtime and Native AOT environment.
#5374
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
utpilla
merged 23 commits into
open-telemetry:main
from
Yun-Ting:yunl/ExceptionProcessor
Mar 2, 2024
Merged
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
9d179cd
initial commit
Yun-Ting 0e9d7a9
sequence
Yun-Ting 5299caf
Merge branch 'main' into yunl/ExceptionProcessor
Yun-Ting a46a246
using
Yun-Ting 9f4b46e
Merge branch 'yunl/ExceptionProcessor' of https://github.com/Yun-Ting…
Yun-Ting 2b9f993
using
Yun-Ting bbf07b0
Merge branch 'main' into yunl/ExceptionProcessor
Yun-Ting 72ee3b7
addressed comments
Yun-Ting 70171d5
spelling
Yun-Ting 7447ccd
Merge branch 'main' into yunl/ExceptionProcessor
Yun-Ting 2708aff
comments
Yun-Ting 4a44a7a
addressed comments
Yun-Ting 957c236
Merge branch 'main' into yunl/ExceptionProcessor
Yun-Ting efb3d67
changelog
Yun-Ting 7090344
spelling
Yun-Ting b7864b0
comments
Yun-Ting cf3ac04
lint
Yun-Ting b6648f6
update
Yun-Ting a69e9a0
tweak
Yun-Ting 6c57649
Merge branch 'main' into yunl/ExceptionProcessor
Yun-Ting 6e2e538
Update src/OpenTelemetry/Trace/Builder/TracerProviderBuilderExtension…
Yun-Ting 0a03b52
Merge branch 'main' into yunl/ExceptionProcessor
Yun-Ting 8db5d36
Update src/OpenTelemetry/CHANGELOG.md
utpilla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,10 +2,13 @@ | |
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| using System.Diagnostics; | ||
| #if NET6_0_OR_GREATER || NETFRAMEWORK | ||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
| #if !NET6_0_OR_GREATER && !NETFRAMEWORK | ||
| #else | ||
| using System.Linq.Expressions; | ||
| using System.Reflection; | ||
| using System.Runtime.InteropServices; | ||
| #endif | ||
|
|
||
| namespace OpenTelemetry.Trace; | ||
|
|
@@ -19,7 +22,14 @@ internal sealed class ExceptionProcessor : BaseProcessor<Activity> | |
| public ExceptionProcessor() | ||
| { | ||
| #if NET6_0_OR_GREATER || NETFRAMEWORK | ||
| this.fnGetExceptionPointers = Marshal.GetExceptionPointers; | ||
| if (RuntimeFeature.IsDynamicCodeSupported) | ||
| { | ||
| throw new NotSupportedException($"'{typeof(Marshal).FullName}.GetExceptionPointers' is not supported when running native AOT."); | ||
|
||
| } | ||
| else | ||
| { | ||
| this.fnGetExceptionPointers = Marshal.GetExceptionPointers; | ||
| } | ||
| #else | ||
| // When running on netstandard or similar the Marshal class is not a part of the netstandard API | ||
| // but it would still most likely be available in the underlying framework, so use reflection to retrieve it. | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Instead of calling
RuntimeFeature.IsDynamicCodeSupported, can this just call the API to see whether it is supported?Note that this API is also not supported in Mono (irrespective of whether IsDynamicCodeSupported is true or false), so it would cover the Mono.
Uh oh!
There was an error while loading. Please reload this page.
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.
Thank you! I agree above is the proper way to handle the situation. Shall I log this feature request in the runtime repo?
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.
Yes, please.
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.
I've filed a request to implement the API in runtime: dotnet/runtime#98878.
Chatted with @eerhardt, @jkotas and @reyang offline.
While the above API is being implemented, we may do the followings to avoid crashing the consumer's app:
SetErrorStatusOnException()with [RequiresDynamicCode] to serve as a compile time warning for the consumer. One caveat of this approach is IsDynamicCode does not really explain the nature of this issue and may further confuse the consumer.System.PlatformNotSupportedExceptionupon callingMarshal.GetExceptionPointer(). Store the state inExceptionProcessor()and dump the Message "Exception processor not supported" insideOnEnd(Activity activity).Not sure which one is a better stopgap of this issue?
cc @MichalStrehovsky, @agocke
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.
Discussed in today's SIG meeting.
I'll go with adding the compile time warning as was mentioned in 1. above.
Plus, guarding the extension method
opentelemetry-dotnet/src/OpenTelemetry/Trace/Builder/TracerProviderBuilderSdk.cs
Line 144 in e7cbbbb
with a try/catch on Marshal.GetExceptionPointers to avoid adding useless Processor at runtime (if user ever decided to suppress the compile time AOT warning.)
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.
There is no need to add
try/catchblock. We just have to callMarshal.GetExceptionPointers()once in theExceptionProcessorctor and rethrow the exception with our custom message.@CodeBlanch Just to confirm this is what you suggested, right?
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.
I'm OK with either re-throwing or just silently failing & not adding the processor. Probably re-throwing is better to alert the users 🤔
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.
+1 on re-throwing the exception at start-up.