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 15 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 `ExceptionProcessor` for Tracing in
Yun-Ting marked this conversation as resolved.
Show resolved Hide resolved
Mono Runtime and Native AOT environment because the the dependent
Yun-Ting marked this conversation as resolved.
Show resolved Hide resolved
`Marshal.GetExceptionPointers()` API is not supported in these platforms.
([#5347](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5347))
utpilla marked this conversation as resolved.
Show resolved Hide resolved

* 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
18 changes: 6 additions & 12 deletions src/OpenTelemetry/Trace/ExceptionProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,16 @@ internal sealed class ExceptionProcessor : BaseProcessor<Activity>
public ExceptionProcessor()
{
#if NET6_0_OR_GREATER || NETFRAMEWORK
Marshal.GetExceptionPointers(); // attempt to access pointers to test for platform support
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.
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
}

Expand Down