Skip to content
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
{
Marshal.GetExceptionPointers();
}
catch
{
getExceptionPointersSupported = false;
}

if (!getExceptionPointersSupported)
{
throw new PlatformNotSupportedException($"'{typeof(Marshal).FullName}.GetExceptionPointers' is not supported.");
}

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