Skip to content
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

Merged
merged 23 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public static class TracerProviderBuilderExtensions
/// <param name="tracerProviderBuilder"><see cref="TracerProviderBuilder"/>.</param>
/// <param name="enabled">Enabled or not. Default value is <c>true</c>.</param>
/// <returns>Returns <see cref="TracerProviderBuilder"/> for chaining.</returns>
#if NET7_0_OR_GREATER
[RequiresDynamicCode("Calling this method will invoke Marshal.GetExceptionPointers(), which is neither supported in MonoRuntime nor in nativeAOT enviornment.")]
#endif
public static TracerProviderBuilder SetErrorStatusOnException(this TracerProviderBuilder tracerProviderBuilder, bool enabled = true)
{
tracerProviderBuilder.ConfigureBuilder((sp, builder) =>
Expand Down
16 changes: 16 additions & 0 deletions src/OpenTelemetry/Trace/ExceptionProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ internal sealed class ExceptionProcessor : BaseProcessor<Activity>
public ExceptionProcessor()
{
#if NET6_0_OR_GREATER || NETFRAMEWORK
bool getExceptionPointersSupported = true;

try
Yun-Ting marked this conversation as resolved.
Show resolved Hide resolved
{
Marshal.GetExceptionPointers();
}
catch
Yun-Ting marked this conversation as resolved.
Show resolved Hide resolved
{
getExceptionPointersSupported = false;
}

if (!getExceptionPointersSupported)
{
throw new PlatformNotSupportedException($"'{typeof(Marshal).FullName}.GetExceptionPointers' is not supported.");
Yun-Ting marked this conversation as resolved.
Show resolved Hide resolved
}

this.fnGetExceptionPointers = Marshal.GetExceptionPointers;
#else
// When running on netstandard or similar the Marshal class is not a part of the netstandard API
Expand Down
Loading