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 all 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
7 changes: 6 additions & 1 deletion src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

## Unreleased

* Throw NotSupportedException when using `SetErrorStatusOnException` method for
Tracing in Mono Runtime and Native AOT environment because the dependent
`Marshal.GetExceptionPointers()` API is not supported on these platforms.
([#5374](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5374))

* Fixed an issue where `LogRecord.Attributes` (or `LogRecord.StateValues` alias)
could become out of sync with `LogRecord.State` if either is set directly via
the public setters. This was done to further mitigate issues introduced in
1.5.0 causing attributes added using custom processor(s) to be missing after
upgrading. For details see:
[#5169](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5169)
([#5169](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5169))

* Fixed an issue where `SimpleExemplarReservoir` was not resetting internal
state for cumulative temporality.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ 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>
/// <remarks>
/// This method is not supported in native AOT or Mono Runtime as of .NET 8.
/// </remarks>
#if NET7_0_OR_GREATER
[RequiresDynamicCode("The code for detecting exception and setting error status might not be available.")]
#endif
public static TracerProviderBuilder SetErrorStatusOnException(this TracerProviderBuilder tracerProviderBuilder, bool enabled = true)
{
tracerProviderBuilder.ConfigureBuilder((sp, builder) =>
Expand Down
18 changes: 6 additions & 12 deletions src/OpenTelemetry/Trace/ExceptionProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,13 @@ public ExceptionProcessor()
#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.
try
{
var flags = BindingFlags.Static | BindingFlags.Public;
var method = typeof(Marshal).GetMethod("GetExceptionPointers", flags, null, Type.EmptyTypes, null)
?? throw new InvalidOperationException("Marshal.GetExceptionPointers method could not be resolved reflectively.");
var lambda = Expression.Lambda<Func<IntPtr>>(Expression.Call(method));
this.fnGetExceptionPointers = lambda.Compile();
}
catch (Exception ex)
{
throw new NotSupportedException($"'{typeof(Marshal).FullName}.GetExceptionPointers' is not supported", ex);
}
var flags = BindingFlags.Static | BindingFlags.Public;
var method = typeof(Marshal).GetMethod("GetExceptionPointers", flags, null, Type.EmptyTypes, null)
?? throw new InvalidOperationException("Marshal.GetExceptionPointers method could not be resolved reflectively.");
reyang marked this conversation as resolved.
Show resolved Hide resolved
var lambda = Expression.Lambda<Func<IntPtr>>(Expression.Call(method));
this.fnGetExceptionPointers = lambda.Compile();
#endif
this.fnGetExceptionPointers(); // attempt to access pointers to test for platform support
}

/// <inheritdoc />
Expand Down