-
Notifications
You must be signed in to change notification settings - Fork 786
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
Throw NotSupportedException when using SetErrorStatusOnException
in Mono Runtime and Native AOT environment.
#5374
Changes from 6 commits
9d179cd
0e9d7a9
5299caf
a46a246
9f4b46e
2b9f993
bbf07b0
72ee3b7
70171d5
7447ccd
2708aff
4a44a7a
957c236
efb3d67
7090344
b7864b0
cf3ac04
b6648f6
a69e9a0
6c57649
6e2e538
0a03b52
8db5d36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,9 @@ | |
|
||
using System.Diagnostics; | ||
using System.Runtime.InteropServices; | ||
#if !NET6_0_OR_GREATER && !NETFRAMEWORK | ||
#if NET6_0_OR_GREATER || NETFRAMEWORK | ||
using System.Runtime.CompilerServices; | ||
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net8.0)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net8.0)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net7.0)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net7.0)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net7.0)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net7.0)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net8.0)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net8.0)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net6.0)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net6.0)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net6.0)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net6.0)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Tests)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Tests)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Api.Tests)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Api.Tests)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (windows-latest, net8.0)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (windows-latest, net8.0)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / validate-packages / run-package-validation-stable
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (windows-latest, net6.0)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (windows-latest, net6.0)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / validate-packages / run-package-validation-experimental
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (windows-latest, net7.0)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (windows-latest, net7.0)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net462)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net462)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net8.0)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net8.0)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (windows-latest, net462)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (windows-latest, net462)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net6.0)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net6.0)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net7.0)
Check failure on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net7.0)
Check warning on line 7 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / lint-dotnet-format / run-dotnet-format-stable
|
||
#else | ||
using System.Linq.Expressions; | ||
using System.Reflection; | ||
#endif | ||
|
@@ -19,7 +21,14 @@ | |
public ExceptionProcessor() | ||
{ | ||
#if NET6_0_OR_GREATER || NETFRAMEWORK | ||
this.fnGetExceptionPointers = Marshal.GetExceptionPointers; | ||
if (RuntimeFeature.IsDynamicCodeSupported) | ||
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net8.0)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net8.0)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net7.0)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net7.0)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net7.0)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net7.0)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net8.0)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net8.0)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net6.0)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (ubuntu-latest, net6.0)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net6.0)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (ubuntu-latest, net6.0)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Tests)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Tests)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Api.Tests)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / concurrency-tests / run-concurrency-tests (windows-latest, net8.0, OpenTelemetry.Api.Tests)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (windows-latest, net8.0)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (windows-latest, net8.0)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / validate-packages / run-package-validation-stable
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (windows-latest, net6.0)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (windows-latest, net6.0)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / validate-packages / run-package-validation-experimental
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (windows-latest, net7.0)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (windows-latest, net7.0)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net462)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net462)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net8.0)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net8.0)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (windows-latest, net462)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-stable / build-test (windows-latest, net462)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net6.0)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net6.0)
Check failure on line 24 in src/OpenTelemetry/Trace/ExceptionProcessor.cs GitHub Actions / build-test-solution-experimental / build-test (windows-latest, net7.0)
|
||
{ | ||
throw new NotSupportedException($"'{typeof(Marshal).FullName}.GetExceptionPointers' is not supported when running native AOT."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to make this a build time error? I think that will help the developers to discover the issue earlier. |
||
} | ||
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. | ||
|
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.
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.PlatformNotSupportedException
upon 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/catch
block. We just have to callMarshal.GetExceptionPointers()
once in theExceptionProcessor
ctor 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.