11import type { AttributeObject , RawAttribute , RawAttributes } from './attributes' ;
2- import { getTraceData } from './browser' ;
3- import { getClient , getCurrentScope , getIsolationScope , withIsolationScope } from './currentScopes' ;
2+ import { getClient , getCurrentScope , getIsolationScope } from './currentScopes' ;
43import { DEBUG_BUILD } from './debug-build' ;
54import type { CaptureContext } from './scope' ;
65import { closeSession , makeSession , updateSession } from './session' ;
7- import { continueTrace , startNewTrace } from './tracing/trace' ;
8- import type { CheckIn , FinishedCheckIn , MonitorConfig } from './types/checkin' ;
96import type { Event , EventHint } from './types/event' ;
107import type { EventProcessor } from './types/eventprocessor' ;
118import type { Extra , Extras } from './types/extra' ;
@@ -14,12 +11,9 @@ import type { Session, SessionContext } from './types/session';
1411import type { SeverityLevel } from './types/severity' ;
1512import type { User } from './types/user' ;
1613import { debug } from './utils/debug-logger' ;
17- import { isThenable } from './utils/is' ;
18- import { uuid4 } from './utils/misc' ;
1914import type { ExclusiveEventHintOrCaptureContext } from './utils/prepareEvent' ;
2015import { parseEventHintOrCaptureContext } from './utils/prepareEvent' ;
2116import { getCombinedScopeData } from './utils/scopeData' ;
22- import { timestampInSeconds } from './utils/time' ;
2317import { GLOBAL_OBJ } from './utils/worldwide' ;
2418
2519/**
@@ -183,88 +177,6 @@ export function lastEventId(): string | undefined {
183177 return getIsolationScope ( ) . lastEventId ( ) ;
184178}
185179
186- /**
187- * Create a cron monitor check in and send it to Sentry.
188- *
189- * @param checkIn An object that describes a check in.
190- * @param upsertMonitorConfig An optional object that describes a monitor config. Use this if you want
191- * to create a monitor automatically when sending a check in.
192- */
193- export function captureCheckIn ( checkIn : CheckIn , upsertMonitorConfig ?: MonitorConfig ) : string {
194- const scope = getCurrentScope ( ) ;
195- const client = getClient ( ) ;
196- if ( ! client ) {
197- DEBUG_BUILD && debug . warn ( 'Cannot capture check-in. No client defined.' ) ;
198- } else if ( ! client . captureCheckIn ) {
199- DEBUG_BUILD && debug . warn ( 'Cannot capture check-in. Client does not support sending check-ins.' ) ;
200- } else {
201- return client . captureCheckIn ( checkIn , upsertMonitorConfig , scope ) ;
202- }
203-
204- return uuid4 ( ) ;
205- }
206-
207- /**
208- * Wraps a callback with a cron monitor check in. The check in will be sent to Sentry when the callback finishes.
209- *
210- * @param monitorSlug The distinct slug of the monitor.
211- * @param callback Callback to be monitored
212- * @param upsertMonitorConfig An optional object that describes a monitor config. Use this if you want
213- * to create a monitor automatically when sending a check in.
214- */
215- export function withMonitor < T > (
216- monitorSlug : CheckIn [ 'monitorSlug' ] ,
217- callback : ( ) => T ,
218- upsertMonitorConfig ?: MonitorConfig ,
219- ) : T {
220- function runCallback ( ) : T {
221- const checkInId = captureCheckIn ( { monitorSlug, status : 'in_progress' } , upsertMonitorConfig ) ;
222- const now = timestampInSeconds ( ) ;
223-
224- function finishCheckIn ( status : FinishedCheckIn [ 'status' ] ) : void {
225- captureCheckIn ( { monitorSlug, status, checkInId, duration : timestampInSeconds ( ) - now } ) ;
226- }
227- // Default behavior without isolateTrace
228- let maybePromiseResult : T ;
229- try {
230- maybePromiseResult = callback ( ) ;
231- } catch ( e ) {
232- finishCheckIn ( 'error' ) ;
233- throw e ;
234- }
235-
236- if ( isThenable ( maybePromiseResult ) ) {
237- return maybePromiseResult . then (
238- r => {
239- finishCheckIn ( 'ok' ) ;
240- return r ;
241- } ,
242- e => {
243- finishCheckIn ( 'error' ) ;
244- throw e ;
245- } ,
246- ) as T ;
247- }
248- finishCheckIn ( 'ok' ) ;
249-
250- return maybePromiseResult ;
251- }
252-
253- // With isolation scope resets the propagation context, so if we do not pass isolateTace, we want to manually continue the trace
254- const traceData = getTraceData ( ) ;
255- return withIsolationScope ( ( ) =>
256- upsertMonitorConfig ?. isolateTrace
257- ? startNewTrace ( runCallback )
258- : continueTrace (
259- {
260- sentryTrace : traceData [ 'sentry-trace' ] ,
261- baggage : traceData [ 'baggage' ] ,
262- } ,
263- runCallback ,
264- ) ,
265- ) ;
266- }
267-
268180/**
269181 * Call `flush()` on the current client, if there is one. See {@link Client.flush}.
270182 *
0 commit comments