sentry-react-native icon indicating copy to clipboard operation
sentry-react-native copied to clipboard

Late Init of sentry

Open daniel-johns-99 opened this issue 1 year ago • 12 comments

I read in the documentation that it's better to retrieve the Sentry DSN dynamically rather than embedding it in the app. But if I wait to fetch this configuration dynamically, I might miss events that occur during the wait, especially during app startup. Am I understanding this correctly? If I initialize Sentry 500ms after app start, will I lose events from the first 500ms?

Alternatively, is there a way to change configuration values after initialization? Specifically, I want to dynamically retrieve values for tracesSampleRate, sampleRate, and ignoreErrors, but I don't want to miss any events while waiting for these values before calling sentry.init. I know I can achieve this with an event processor, but I'd prefer using these built-in options before resorting to a custom solution.

Overall, I'm trying to understand the impact of delaying Sentry initialization versus initializing it immediately on app start and then adjusting configuration values once they're received (If that is even possible)

daniel-johns-99 avatar Apr 02 '24 08:04 daniel-johns-99

Hi @daniel-johns-99, thank you for the message,

you understand it correctly, when the SDK initialization is delayed all events (errors) that happened before the init will be lost.

Generally, when changing the options we recommend closing and re-initializing the SDK. As the options are used during the initialization process and later changes might not have the desired effect, a module where the value is used might not be included.

Typically undefined and 0 lead to the exclusion of a module during init.

Let us know if this helps.

krystofwoldrich avatar Apr 02 '24 10:04 krystofwoldrich

Generally, when changing the options we recommend closing and re-initializing the SDK.

Are there any impacts on doing this?

daniel-johns-99 avatar Apr 03 '24 08:04 daniel-johns-99

Closing the SDK flushes events which are currently being processed, how this takes depends on the current state of the app, the amount of events and the connection speed.

krystofwoldrich avatar Apr 04 '24 11:04 krystofwoldrich

Closing this due to inactivity. If this is still an issue feel free to comment here or open a new issue if the context changed.

krystofwoldrich avatar Apr 19 '24 11:04 krystofwoldrich

Closing the SDK flushes events which are currently being processed, how this takes depends on the current state of the app, the amount of events and the connection speed.

@krystofwoldrich is close() synchronous or will close(); init(); result in potential loss of events?

I see that javascript supports then() + timeout while Shutdown and Draining page for React Native looks generic and suggests Sentry.flush() (presumably right before close()?).

maxkosty avatar May 04 '24 03:05 maxkosty

@realkosty

Yes, errors between the close() and init() would be lost. The same way as any errors before the SDK is initialized the first time.

The Sentry.close() calls flush() internally.

Yes, the Shutdown and Draining page for React Native is missing the close() function.

krystofwoldrich avatar May 06 '24 18:05 krystofwoldrich

@krystofwoldrich would it be a valid feature request to have an api similar to JS SDK or is this not possible in React Native because of architectural limitations?

Sentry.close(2000).then(function () { // ...

maxkosty avatar May 07 '24 15:05 maxkosty

@realkosty We already have it, without the timeout option.

import * as Sentry from `@sentry/react-native`;

Sentry.close(/* RN doesn't have the timeout property */).then(function () {});

krystofwoldrich avatar May 08 '24 14:05 krystofwoldrich

Oh nice! So it is possible then to implement close/re-init in such way that no events are lost.

maxkosty avatar May 08 '24 17:05 maxkosty

@krystofwoldrich Customer is reporting that

Calling Sentry.close().finally(() => Sentry.init(options)) is resulting in this error from Sentry "Transport Disabled". As a result, app start and other transactions are failing to send.

any idea why that could be happening?

their Sentry configuration: https://github.com/getsentry/sentry-react-native/issues/3816#issuecomment-2109115627

maxkosty avatar May 08 '24 17:05 maxkosty

I'm not sure, I will try to reproduce it and update my post here.

krystofwoldrich avatar May 17 '24 15:05 krystofwoldrich

@realkosty As a question. If I reinit sentry as proposed. Does it track as a new session in the release health? In addition what happens to any other transactions which are already open. Are they lost? I seem to be losing the mobile performance metrics of time to start by doing the reinit of Sentry

daniel-johns-99 avatar May 22 '24 05:05 daniel-johns-99

Hi @daniel-johns-99, when the SDK is re-initialized, the currently running transactions will be lost.

A new session will be created.

Note that Sentry.close() closes the native SDKs, therefore when calling Sentry.init(options) the options should enabled the auto native init function or the native SDKs should be initialized manually as well.

krystofwoldrich avatar May 27 '24 10:05 krystofwoldrich

Closing this due to inactivity. If this is still an issue feel free to comment here or open a new issue if the context changed.

krystofwoldrich avatar Jun 14 '24 11:06 krystofwoldrich