Skip to content

Deterministic per-installation sampling helper #6339

Description

@antonis

tracesSampleRate is random per-transaction — the same device may be sampled for one session and not the next. This makes before/after regression comparison unreliable. A deterministic per-installation sampler that hashes a stable device identifier would ensure the same device is always in/out of sample across launches and releases.

Feasibility Assessment (Jul 2026)

Not yet covered — no deterministic per-installation sampling exists in the RN SDK. tracesSampleRate uses Math.random() per-transaction.

Cross-SDK alignment: No other Sentry SDK offers per-device/installation sampling. Existing "consistent sampling" across SDKs is:

  • Per-trace: sample_rand propagation ensures all spans in a distributed trace get the same decision (JS, Python, Dart)
  • Per-session: JS SDK's consistentTraceSampling ensures linked browser navigations in one session are consistent
  • None hashes a persistent device/installation ID for cross-session, cross-release consistency

Spec: No develop.sentry.dev spec exists for per-device sampling. The sampling spec covers per-trace determinism only.

tracesSampler workaround: The callback is synchronous, but the installation ID is only accessible via async fetchNativeDeviceContexts(). Users would need to pre-fetch and cache before Sentry.init(), which is cumbersome. A sync getInstallationId() native bridge method would be needed.

Native bridge: Installation ID is available on both platforms:

  • iOS: PrivateSentrySDKOnly.installationID (used in RNSentry.mm:499)
  • Android: Via InternalSentrySdk.serializeScope() (RNSentryModuleImpl.java:1093)

Dashboard visibility: Transactions sampled this way appear normally. The value is statistical — same 10% of devices always sampled enables reliable regression comparison — but no dashboard UI exists for cohort comparison.

Implementation

  1. Add a synchronous getInstallationId() native bridge method
  2. Ship a named export like installationBasedSampler(rate) that hashes the installation ID
  3. Users pass it as tracesSampler

Note: Consider proposing a cross-SDK spec at develop.sentry.dev so Cocoa, Java/Android, and Dart/Flutter can follow the same API shape, since all mobile SDKs face the same problem.

Metadata

Metadata

Assignees

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions