Skip to content

Add DisableSentryNative build property #4107

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

maxkatz6
Copy link

This PR adds a new DisableSentryNative build property, allowing to opt-out from linking and using Sentry.Native on .NET 8+ builds. By default, DisableSentryNative is false, so old behavior is kept unchanged.

Two main changes of this PR:

  1. DirectPInvoke/NativeLibrary are only set when DisableSentryNative is false.
  2. SentryNative.IsAvailable returns false, if DisableSentryNative was set to true.

Runtime switches (RuntimeHostConfigurationOption and AppContext.TryGetSwitch) were used to pass build property to the runtime library. FeatureSwitchDefinition used should make this switch into a compile-time variable.

Closes #4102

NOTE: while it should work, I haven't tested the build yet. Need to figure out how to prepare a local build with native bits and everything included.

@maxkatz6 maxkatz6 changed the title Make native lib actually optional Add DisableSentryNative build parameter Apr 13, 2025
@maxkatz6 maxkatz6 changed the title Add DisableSentryNative build parameter Add DisableSentryNative build property Apr 13, 2025
@jamescrosswell
Copy link
Collaborator

NOTE: while it should work, I haven't tested the build yet. Need to figure out how to prepare a local build with native bits and everything included.

@maxkatz6 the PR where @vaind added SentryNative.IsAvailable might be helpful to look at. There are some integration tests build in PowerShell in that PR that demonstrate at least the conditions for SentryNative being available:

Your code is looking at a couple of different scenarios/variants within that, I imagine (when it's enabled/disabled).

Copy link

codecov bot commented Apr 13, 2025

Codecov Report

Attention: Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.

Project coverage is 72.64%. Comparing base (495e742) to head (6eb1020).
Report is 542 commits behind head on main.

Files with missing lines Patch % Lines
src/Sentry/Platforms/Native/SentryNative.cs 33.33% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4107      +/-   ##
==========================================
- Coverage   75.73%   72.64%   -3.09%     
==========================================
  Files         357      444      +87     
  Lines       13466    15996    +2530     
  Branches     2671     3153     +482     
==========================================
+ Hits        10198    11621    +1423     
- Misses       2593     3561     +968     
- Partials      675      814     +139     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A way to disable "sentry-native"
2 participants