From c9ed70583dad0ef81122b9b16f3e9ae1ceb3301a Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Thu, 25 Apr 2024 23:19:22 +0200 Subject: [PATCH 1/2] feat(core): Wrap cron `withMonitor` task in `withIsolationScope` --- packages/core/src/exports.ts | 49 +++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/packages/core/src/exports.ts b/packages/core/src/exports.ts index b1c7e55776b1..ca9ff7bbcf23 100644 --- a/packages/core/src/exports.ts +++ b/packages/core/src/exports.ts @@ -15,9 +15,10 @@ import type { User, } from '@sentry/types'; import { GLOBAL_OBJ, isThenable, logger, timestampInSeconds, uuid4 } from '@sentry/utils'; +import { getAsyncContextStrategy } from './asyncContext'; 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 +161,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; + }); } /** From 18625aaa69a16481001f25e6533c9720059586b0 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Thu, 25 Apr 2024 23:35:54 +0200 Subject: [PATCH 2/2] lint --- packages/core/src/exports.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/core/src/exports.ts b/packages/core/src/exports.ts index ca9ff7bbcf23..4ff223a20e60 100644 --- a/packages/core/src/exports.ts +++ b/packages/core/src/exports.ts @@ -15,7 +15,6 @@ import type { User, } from '@sentry/types'; import { GLOBAL_OBJ, isThenable, logger, timestampInSeconds, uuid4 } from '@sentry/utils'; -import { getAsyncContextStrategy } from './asyncContext'; import { DEFAULT_ENVIRONMENT } from './constants'; import { getClient, getCurrentScope, getIsolationScope, withIsolationScope } from './currentScopes';