Skip to content

Commit

Permalink
Merge branch 'tim/sentry_load' into 'master'
Browse files Browse the repository at this point in the history
fix: If using the global Sentry, check if it has finished loading

See merge request TankerHQ/sdk-js!1008
  • Loading branch information
tux3 committed Jan 9, 2024
2 parents c2e6bf4 + 5bff975 commit f90300f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/core/src/Tanker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ export class Tanker extends EventEmitter {
}

if (options.sentryHub === undefined) {
this._sentry = globalThis.Sentry?.getCurrentHub() || null;
// If Sentry is lazy-loaded, the globalThis.Sentry object can exist but be almost empty
// So we have to check if getCurrentHub is defined. Disable integration if it hasn't finished loading.
const getHub = globalThis.Sentry?.getCurrentHub;
this._sentry = getHub ? getHub() : null;
} else {
this._sentry = options.sentryHub;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/global-this/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { getGlobalThis } from './global-this';
import type { Hub } from '@sentry/types';

const myGlobalThis: typeof globalThis & {
Sentry?: { getCurrentHub: () => Hub };
Sentry?: {
getCurrentHub?: () => Hub,
};
} = getGlobalThis();

export { myGlobalThis as globalThis };

0 comments on commit f90300f

Please sign in to comment.