iOS: `Sentry.Unmask` / `Sentry.Mask` ignored when replay is started manually with both sample rates at 0

Aperta Adatta ai principianti
#6,996 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
ios, objective-c, react-native, typescript

Direzione di ricerca

Inizia da RNSentryStart.m e controlla la condizione di guardia dell’inizializzazione del replay descritta nell’issue; poi leggi RNSentryReplay postInit per confermare cosa registra. La correzione indicata consiste nel chiamare postInit ogni volta che il replay è supportato, anche quando entrambi i tassi di campionamento sono zero. Il lavoro è completato quando il replay manuale mantiene il comportamento di Sentry.Unmask e Sentry.Mask su iOS con queste impostazioni.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

React-Native
What React Native libraries do you use?

Expo (SDK 57, CNG / expo prebuild), Expo Router, React Native 0.86 (New Architecture), Hermes.

Are you using sentry.io or on-premise?

sentry.io (SaaS, EU region)

@sentry/react-native SDK Version

8.33.0 (sentry-cocoa 9.32.0). The same condition is still present in 8.34.0 and on main.

How does your development environment look like?
@sentry/react-native  8.33.0
sentry-cocoa          9.32.0 (prebuilt xcframework)
react-native          0.86.3, New Architecture enabled
expo                  57
iOS                   TestFlight build, iPhone
Sentry.init()
Sentry.init({
  dsn: '...',
  sendDefaultPii: false,
  // Replay is only recorded on one screen, started and stopped manually
  // (Sentry.getReplay().start() / stop(), available since 8.27).
  replaysSessionSampleRate: 0,
  replaysOnErrorSampleRate: 0,
  integrations: [
    Sentry.mobileReplayIntegration({
      maskAllText: true,
      maskAllImages: true,
      maskAllVectors: true,
    }),
  ],
});

// Later, on the screen we want to record (with user consent):
Sentry.getReplay()?.start();
Steps to Reproduce
  1. Initialize the SDK with replaysSessionSampleRate: 0 and replaysOnErrorSampleRate: 0, and mobileReplayIntegration({ maskAllText: true }).
  2. Wrap a static label in <Sentry.Unmask><Text>Continue</Text></Sentry.Unmask>.
  3. Start the replay manually with Sentry.getReplay().start() and navigate the screen.
  4. Open the replay in Sentry.
Expected Result

The Text wrapped in Sentry.Unmask is visible in the replay, as it is on Android and as it is on iOS when a sample rate is positive. Sentry.Mask masks its subtree.

Actual Result

On iOS, the whole replay is masked: Sentry.Unmask has no effect (and Sentry.Mask is not registered either). Android is fine.

Cause

RNSentryStart.m only registers the replay container classes when a sample rate is positive:

[SentrySDK startWithOptions:options];

#if SENTRY_TARGET_REPLAY_SUPPORTED
    if (options.sessionReplay.sessionSampleRate > 0
        || options.sessionReplay.onErrorSampleRate > 0) {
        [RNSentryReplay postInit];
    }
#endif

+[RNSentryReplay postInit] is what calls setReplayRedactContainerClass: (RNSentryReplayMask), setReplayIgnoreContainerClass: (RNSentryReplayUnmask) and configures the RN breadcrumb converter. Since 8.27, a replay can be started manually with both rates at 0, and sentry-cocoa 9.32.0 always installs SentrySessionReplayIntegration on iOS, whatever the rates. The replay therefore records, but without the container classes: Unmask is ignored, Mask is not applied as a container, and replay breadcrumbs go through the default converter instead of RNSentryReplayBreadcrumbConverter.

Raising a rate is not a workaround for us: it would record (or buffer) replays outside the screen the user consented to, without the on-screen recording indicator we show (App Store Review Guideline 2.5.14).

Suggested fix

Call postInit whenever the replay is supported, regardless of the sample rates:

#if SENTRY_TARGET_REPLAY_SUPPORTED
    [RNSentryReplay postInit];
#endif

postInit does not start any recording: it only registers the two container classes and the breadcrumb converter on the installed integration (SentryInternalReplayApi calls are no-ops if the integration is missing). We apply exactly this change at prebuild time as a local workaround.

Lingua principale
TypeScript
Stelle
1.8k
Fork
373
Merge medio
1g 7h
PR unite (30g)
105

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di getsentry/sentry-react-native

Tutte le issue di getsentry/sentry-react-native

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.