Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

### Features

- Option to disable the SentryNative integration ([#4107](https://github.com/getsentry/sentry-dotnet/pull/4107))
- Reintroduced experimental support for Session Replay on Android ([#4097](https://github.com/getsentry/sentry-dotnet/pull/4097))

### Fixes

- Ensure user exception data is not removed by AspNetCoreExceptionProcessor ([#4016](https://github.com/getsentry/sentry-dotnet/pull/4106))
- Prevent users from disabling AndroidEnableAssemblyCompression which leads to untrappable crash ([#4089](https://github.com/getsentry/sentry-dotnet/pull/4089))
- Fixed MSVCRT build warning on Windows ([#4111](https://github.com/getsentry/sentry-dotnet/pull/4111))
Expand Down
16 changes: 14 additions & 2 deletions src/Sentry/Platforms/Native/SentryNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,23 @@ namespace Sentry;
internal static class SentryNative
{
#if NET8_0_OR_GREATER
internal static bool IsAvailable { get; }
// Should be in-sync with Sentry.Native.targets const.
private const string SentryNativeIsEnabledSwitchName = "Sentry.Native.IsEnabled";

private static readonly bool IsAvailableCore;

#if NET9_0_OR_GREATER
// FeatureSwitchDefinition should help with trimming disabled code.
// This way, `SentryNative.IsEnabled` should be treated as a compile-time constant for trimmed apps.
[FeatureSwitchDefinition(SentryNativeIsEnabledSwitchName)]
#endif
private static bool IsEnabled => !AppContext.TryGetSwitch(SentryNativeIsEnabledSwitchName, out var isEnabled) || isEnabled;

internal static bool IsAvailable => IsEnabled && IsAvailableCore;

static SentryNative()
{
IsAvailable = AotHelper.IsTrimmed && !SentryRuntime.Current.IsBrowserWasm();
IsAvailableCore = AotHelper.IsTrimmed && !SentryRuntime.Current.IsBrowserWasm();
}
#else
// This is a compile-time const so that the irrelevant code is removed during compilation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,21 @@
Note:Target framework conditions should be kept synchronized with src/Sentry/buildTransitive/Sentry.Native.targets -->
<Project>

<ItemGroup>
<!-- When user sets <DisableSentryNative>true</DisableSentryNative> in their project -->
<!-- SentryNative.IsEnabled should result in compile-time constant for trimmed applications -->
<!-- Effectively disabling native library -->
<RuntimeHostConfigurationOption Include="Sentry.Native.IsEnabled"
Condition="'$(DisableSentryNative)' != 'true'"
Value="true"
Trim="true" />
</ItemGroup>

<PropertyGroup>
<!-- net8.0 or greater -->
<FrameworkSupportsNative Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0')) and ('$(OutputType)' == 'Exe' or '$(OutputType)' == 'WinExe')">true</FrameworkSupportsNative>
<!-- Make it opt-out -->
<FrameworkSupportsNative Condition="'$(DisableSentryNative)' == 'true'">false</FrameworkSupportsNative>
</PropertyGroup>

<ItemGroup Condition="'$(FrameworkSupportsNative)' == 'true' and '$(RuntimeIdentifier)' == 'win-x64'">
Expand Down
Loading