Skip to content

Pass the event sample rate to sentry-cocoa - #2940

Merged
bitsandfoxes merged 6 commits into
mainfrom
snek/sentry-unity-ios-sample-rate
Nov 12, 2026
Merged

bitsandfoxes merged 6 commits into
mainfrom
snek/sentry-unity-ios-sample-rate

Conversation

@bitsandfoxes

@bitsandfoxes bitsandfoxes commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Native iOS and macOS crashes now follow the Event Sample Rate (SampleRate).

Unity passes the sample rate to the Android SDK and to sentry-native, but not to sentry-cocoa. sentry-cocoa applies its own sampleRate to every error event, crashes included, and defaults to 1. So with the C# rate at 0.1, managed errors were sampled while native iOS and macOS crashes were always sent.

The rate now reaches sentry-cocoa on both init paths, only when it is set, as on Android and Native (a rate of 1.0 leaves it out, and sentry-cocoa keeps its default):

  • Runtime init (SentryCocoaBridgeProxy.Init): this is the iOS default and the path macOS uses. It sets sampleRate in the options dictionary through the existing OptionsSetDouble.
  • Build-time init (NativeOptions): writes @"sampleRate" into the options generated into the Xcode project, formatted with the invariant culture.

Tests: CreateOptionsFile_SampleRateSet_WritesSampleRate and CreateOptionsFile_SampleRateSetUnderCommaDecimalCulture_WritesInvariantSampleRate fail without the fix; CreateOptionsFile_SampleRateNotSet_LeavesSampleRateOut covers leaving the key out. The runtime path calls the native bridge directly and, like the other native bridges' option setup, has no unit test.

🤖 Generated with Claude Code

Native iOS and macOS crashes now follow SampleRate with both runtime and build-time initialization.
Drops the setter seam and its runtime tests; Init sets sampleRate the way Android and Native set theirs.
@bitsandfoxes
bitsandfoxes merged commit 1a18ec3 into main Nov 12, 2026
71 of 72 checks passed
@bitsandfoxes
bitsandfoxes deleted the snek/sentry-unity-ios-sample-rate branch November 12, 2026 09:04
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.

4 participants