Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(wrap): Warn users if root component mounts before Sentry.init #3227

Merged
merged 4 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading