getsentry / sentry-react-native

Official Sentry SDK for React Native
https://sentry.io
MIT License
1.57k stars 337 forks source link

MobileReplay not sampled even though replaysSessionSampleRate is set to 1 #4199

Open dusanristic opened 1 week ago

dusanristic commented 1 week ago

What React Native libraries do you use?

Hermes, React Navigation

Are you using sentry.io or on-premise?

sentry.io (SaS)

@sentry/react-native SDK Version

5.34.0

How does your development environment look like?

OS: Sonoma 14.1.1 Node: 18.7.1 yarn: 1.22.22 react-native: 0.72.7 hermesEnabled: true newArchEnabled: false

Sentry.init()

 Sentry.init({
    debug: true,
    autoInitializeNativeSdk: false,
    dsn: SENTRY_DSN,
    _experiments: {
      replaysSessionSampleRate: 1.0,
      replaysOnErrorSampleRate: 1.0,
    },
    integrations: [Sentry.mobileReplayIntegration()],
    environment: NativeConfig.loggerEnvironment,
    release: releaseName,
    dist: getBuildNumber(),
    attachScreenshot: true,
    attachViewHierarchy: true,
    enabled,
    enableNative: enabled,
    ignoreErrors: [...ignoreErrors],
  });
};

Steps to Reproduce

/

Expected Result

Because the replaysSessionSampleRate parameter is set to 1, I expect that every session is recorded and sent to Sentry. Additionally, when I dispatch an error, that replay is not logged to Sentry either.

My Replay dashboard is empty.

Actual Result

Nothing is logged to Sentry, and my Replay session dashboard is empty. When I run the app, this is my output:

 LOG  Sentry Logger [log]: Unhandled promise rejections will be caught by Sentry.
 LOG  Sentry Logger [log]: Integration installed: ReactNativeErrorHandlers
 LOG  Sentry Logger [log]: Integration installed: NativeLinkedErrors
 LOG  Sentry Logger [log]: Integration installed: InboundFilters
 LOG  Sentry Logger [log]: Integration installed: FunctionToString
 LOG  Sentry Logger [log]: Integration installed: Breadcrumbs
 LOG  Sentry Logger [log]: Integration installed: Dedupe
 LOG  Sentry Logger [log]: Integration installed: HttpContext
 LOG  Sentry Logger [log]: Integration installed: Release
 LOG  Sentry Logger [log]: Integration installed: EventOrigin
 LOG  Sentry Logger [log]: Integration installed: SdkInfo
 LOG  Sentry Logger [log]: Integration installed: ReactNativeInfo
 LOG  Sentry Logger [log]: Integration installed: DebugSymbolicator
 LOG  Sentry Logger [log]: Integration installed: RewriteFrames
 LOG  Sentry Logger [log]: Integration installed: DeviceContext
 LOG  Sentry Logger [log]: Integration installed: ModulesLoader
 LOG  Sentry Logger [log]: Integration installed: Screenshot
 LOG  Sentry Logger [log]: Integration installed: ViewHierarchy
 LOG  Sentry Logger [log]: Integration installed: MobileReplay
 WARN  Sentry Logger [warn]: Note: Native Sentry SDK was not initialized automatically, you will need to initialize it manually. If you wish to disable the native SDK and get rid of this warning, pass enableNative: false
 LOG  Sentry Logger [log]: Integration installed: ReactNativeProfiler
 LOG  Sentry Logger [log]: Integration installed: TouchEventBoundary
 LOG  Sentry Logger [log]: [ReactNavigationInstrumentation] Navigation container registered, but integration has not been setup yet.
 LOG  [Error: Error: 400: An update check must include a valid deployment key - please check that your app has been configured correctly. To view available deployment keys, run 'code-push deployment ls <appName> -k'.]
 DEBUG  Sentry Logger [debug]: [Sentry] MobileReplay not sampled for event 9f45775265274cd794fbdc23aa5d5306.

I am getting that MobileReplay is not sampled even though replaysSessionSampleRate is set to 1.

krystofwoldrich commented 1 week ago

Hi @dusanristic, thank you for the message,

from the Sentry.init I see that you have set autoInitializeNativeSdk: false which means you initialize the platform SDK manually.

For Session Replay to work in RN, it has to be enabled in the platform SDK as well.

Please add the replay sample rates to iOS and Android inits.

dusanristic commented 3 days ago

Hey @krystofwoldrich, I do have these params on native side as well (apologise for not adding them in the first place). Below is the snippet code for iOS in AppDelegate.mm file:

 [SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
        options.dsn = @"https://63b8941d39cb0367e993da924c5f21e1@o4506870128181248.ingest.us.sentry.io/4506904420286464";
        options.debug = true;
        options.tracesSampleRate = [NSNumber numberWithDouble:1.0];
        options.profilesSampleRate = [NSNumber numberWithDouble:1.0];
        // Load values from Info.plist as dictionary
        NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary];
        // Extract version and dist from dictonary
        NSString* version =  [infoDict objectForKey:@"CFBundleShortVersionString"];
        NSString* dist  = [infoDict objectForKey:@"CFBundleVersion"];
        options.releaseName = [NSString stringWithFormat:@"%@%@", @"XXXXXXX@", version];
        options.dist = dist;
        options.environment = [infoDict objectForKey:@"logger_environment"];
  }];
krystofwoldrich commented 2 days ago

@dusanristic No worries, thank you for sharing the iOS init.

For Session replay to work, you need to add the following to your iOS init.

options.experimental.sessionReplay.onErrorSampleRate = 1.0
options.experimental.sessionReplay.sessionSampleRate = 1.0

Let us know if this fixed the issue.

dusanristic commented 1 day ago

Thanks for your help and fast response! I have one more question though.

When I add the mentioned lines to iOS init, I get the following error: Property 'sessionReplay' cannot be found in forward class object 'SentryExperimentalOptions'.

Image

Is there anything else I need to do to enable experimental features on iOS? I went through the documentation, and the only thing I found is that I need to have at least Sentry Cocoa SDK v8.31.1, but my Sentry pod version is already v8.37.0.