Skip to content

Commit

Permalink
fix(wrap): Warn users if root component mounts before Sentry.init (#…
Browse files Browse the repository at this point in the history
…3227)

Co-authored-by: LucasZF <[email protected]>
  • Loading branch information
krystofwoldrich and lucas-zimerman authored Aug 9, 2023
1 parent 43dbc9e commit 155c6ad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Fixes

- `Sentry.init` must be called before `Sentry.wrap`([#3227](https://github.com/getsentry/sentry-react-native/pull/3227))
- The SDK now shows warning if incorrect order is detected
- Stall Time is no longer counted when App is in Background. ([#3211](https://github.com/getsentry/sentry-react-native/pull/3211))
- Use application variant instead of variant output to hook to correct package task for modules cleanup ([#3161](https://github.com/getsentry/sentry-react-native/pull/3161))
- Fix `isNativeAvailable` after SDK reinitialization ([#3200](https://github.com/getsentry/sentry-react-native/pull/3200))
Expand Down
26 changes: 16 additions & 10 deletions src/js/tracing/reactnativeprofiler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@ export class ReactNativeProfiler extends Profiler {
*/
public componentDidMount(): void {
super.componentDidMount();
getCurrentHub().getClient()?.addIntegration?.(createIntegration(this.name));
const hub = getCurrentHub();
const client = hub.getClient();

const tracingIntegration = getCurrentHub().getIntegration(
ReactNativeTracing
);

if (this._mountSpan && tracingIntegration) {
if (typeof this._mountSpan.endTimestamp !== 'undefined') {
// The first root component mount is the app start finish.
tracingIntegration.onAppStartFinish(this._mountSpan.endTimestamp);
}
if (!client) {
// We can't use logger here because this will be logged before the `Sentry.init`.
// eslint-disable-next-line no-console
__DEV__ && console.warn('App Start Span could not be finished. `Sentry.wrap` was called before `Sentry.init`.');
return;
}

client.addIntegration && client.addIntegration(createIntegration(this.name));

const tracingIntegration = hub.getIntegration(ReactNativeTracing);
tracingIntegration
&& this._mountSpan
&& typeof this._mountSpan.endTimestamp !== 'undefined'
// The first root component mount is the app start finish.
&& tracingIntegration.onAppStartFinish(this._mountSpan.endTimestamp);
}
}

0 comments on commit 155c6ad

Please sign in to comment.