@@ -5,6 +5,7 @@ import { DEFAULT_ENVIRONMENT, closeSession, makeSession, updateSession } from '@
55import type {
66 Breadcrumb ,
77 BreadcrumbHint ,
8+ CaptureContext ,
89 Client ,
910 Event ,
1011 EventHint ,
@@ -17,9 +18,10 @@ import type {
1718 SeverityLevel ,
1819 User ,
1920} from '@sentry/types' ;
20- import { GLOBAL_OBJ , consoleSandbox , dateTimestampInSeconds , logger } from '@sentry/utils' ;
21+ import { GLOBAL_OBJ , consoleSandbox , dateTimestampInSeconds } from '@sentry/utils' ;
2122
2223import { getScopesFromContext , setScopesOnContext } from '../utils/contextData' ;
24+ import { ExclusiveEventHintOrCaptureContext , parseEventHintOrCaptureContext } from '../utils/prepareEvent' ;
2325import { getGlobalCarrier } from './globals' ;
2426import { Scope } from './scope' ;
2527import type { CurrentScopes , SentryCarrier } from './types' ;
@@ -118,18 +120,22 @@ export function configureScope(callback: (scope: Scope) => void): void {
118120}
119121
120122/** Capture an exception to Sentry. */
121- export function captureException ( exception : unknown , hint ?: EventHint ) : string {
122- return getCurrentScope ( ) . captureException ( exception , hint ) ;
123+ export function captureException ( exception : unknown , hint ?: ExclusiveEventHintOrCaptureContext ) : string {
124+ return getCurrentScope ( ) . captureException ( exception , parseEventHintOrCaptureContext ( hint ) ) ;
123125}
124126
125127/** Capture a message to Sentry. */
126128export function captureMessage (
127129 message : string ,
128130 // eslint-disable-next-line deprecation/deprecation
129- level ?: Severity | SeverityLevel ,
130- hint ?: EventHint ,
131+ captureContext ?: CaptureContext | Severity | SeverityLevel ,
131132) : string {
132- return getCurrentScope ( ) . captureMessage ( message , level , hint ) ;
133+ // This is necessary to provide explicit scopes upgrade, without changing the original
134+ // arity of the `captureMessage(message, level)` method.
135+ const level = typeof captureContext === 'string' ? captureContext : undefined ;
136+ const context = typeof captureContext !== 'string' ? { captureContext } : undefined ;
137+
138+ return getCurrentScope ( ) . captureMessage ( message , level , context ) ;
133139}
134140
135141/** Capture a generic event to Sentry. */
0 commit comments