diff --git a/packages/core/src/exports.ts b/packages/core/src/exports.ts index b1c7e55776b1..4ff223a20e60 100644 --- a/packages/core/src/exports.ts +++ b/packages/core/src/exports.ts @@ -17,7 +17,7 @@ import type { import { GLOBAL_OBJ, isThenable, logger, timestampInSeconds, uuid4 } from '@sentry/utils'; import { DEFAULT_ENVIRONMENT } from './constants'; -import { getClient, getCurrentScope, getIsolationScope } from './currentScopes'; +import { getClient, getCurrentScope, getIsolationScope, withIsolationScope } from './currentScopes'; import { DEBUG_BUILD } from './debug-build'; import { closeSession, makeSession, updateSession } from './session'; import type { ExclusiveEventHintOrCaptureContext } from './utils/prepareEvent'; @@ -160,28 +160,30 @@ export function withMonitor( captureCheckIn({ monitorSlug, status, checkInId, duration: timestampInSeconds() - now }); } - let maybePromiseResult: T; - try { - maybePromiseResult = callback(); - } catch (e) { - finishCheckIn('error'); - throw e; - } - - if (isThenable(maybePromiseResult)) { - Promise.resolve(maybePromiseResult).then( - () => { - finishCheckIn('ok'); - }, - () => { - finishCheckIn('error'); - }, - ); - } else { - finishCheckIn('ok'); - } - - return maybePromiseResult; + return withIsolationScope(() => { + let maybePromiseResult: T; + try { + maybePromiseResult = callback(); + } catch (e) { + finishCheckIn('error'); + throw e; + } + + if (isThenable(maybePromiseResult)) { + Promise.resolve(maybePromiseResult).then( + () => { + finishCheckIn('ok'); + }, + () => { + finishCheckIn('error'); + }, + ); + } else { + finishCheckIn('ok'); + } + + return maybePromiseResult; + }); } /**