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.

Implementation

Native side (minor): Add a synchronous getInstallationId() method to the native bridge on both platforms. The value already exists:

  • iOS: PrivateSentrySDKOnly.installationID (already computed and stored)
  • Android: Installation ID from InternalSentrySdk.serializeScope() (already available)

Currently only accessible via the async fetchNativeDeviceContexts() call, which is unsuitable for the synchronous tracesSampler callback.

JS side:

  1. Implement a pure-JS hash (e.g. FNV-1a) that maps hash(installationId) / MAX_HASH_VALUE to a float in [0, 1).
  2. Export a helper: installationBasedSampler(rate: number) that returns a tracesSampler-compatible function.
  3. Usage: tracesSampler: installationBasedSampler(0.1) — 10% of installations, consistent across launches.

Notes

  • The installation ID persists across app launches but resets on reinstall — acceptable for this use case.
  • No third-party device info libraries needed.
  • The tracesSampler callback interface is unchanged — the helper just returns a function compatible with the existing API.

Scope

JS + thin native. Sync getInstallationId() bridge method on iOS and Android + JS hash utility + exported helper.

Metadata

Metadata

Assignees

No one assigned
    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