From abb866085c6b7b67776bb2a885069a6330c6681a Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Thu, 10 Jul 2025 14:38:15 +0200 Subject: [PATCH 1/3] feat(browser): Add `afterStartPageloadSpan` hook to improve spanId assignment on web vital spans --- packages/browser-utils/src/metrics/utils.ts | 12 ++++-------- .../browser/src/tracing/browserTracingIntegration.ts | 8 +++++++- packages/core/src/client.ts | 11 +++++++++++ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/packages/browser-utils/src/metrics/utils.ts b/packages/browser-utils/src/metrics/utils.ts index ce3da0d4f16d..073a075db525 100644 --- a/packages/browser-utils/src/metrics/utils.ts +++ b/packages/browser-utils/src/metrics/utils.ts @@ -237,13 +237,9 @@ export function listenForWebVitalReportEvents( } }); - const activeSpan = getActiveSpan(); - if (activeSpan) { - const rootSpan = getRootSpan(activeSpan); - const spanJSON = spanToJSON(rootSpan); - if (spanJSON.op === 'pageload') { - pageloadSpanId = rootSpan.spanContext().spanId; - } - } + const unsubscribeAfterStartPageLoadSpan = client.on('afterStartPageLoadSpan', span => { + pageloadSpanId = span.spanContext().spanId; + unsubscribeAfterStartPageLoadSpan?.(); + }); }, 0); } diff --git a/packages/browser/src/tracing/browserTracingIntegration.ts b/packages/browser/src/tracing/browserTracingIntegration.ts index a1eb186d5c1e..f5e6c158c3c9 100644 --- a/packages/browser/src/tracing/browserTracingIntegration.ts +++ b/packages/browser/src/tracing/browserTracingIntegration.ts @@ -644,7 +644,13 @@ export function startBrowserTracingPageLoadSpan( client.emit('startPageLoadSpan', spanOptions, traceOptions); getCurrentScope().setTransactionName(spanOptions.name); - return getActiveIdleSpan(client); + const pageloadSpan = getActiveIdleSpan(client); + + if (pageloadSpan) { + client.emit('afterStartPageLoadSpan', pageloadSpan); + } + + return pageloadSpan; } /** diff --git a/packages/core/src/client.ts b/packages/core/src/client.ts index 869395beea21..fb7717c6a178 100644 --- a/packages/core/src/client.ts +++ b/packages/core/src/client.ts @@ -603,6 +603,12 @@ export abstract class Client { ) => void, ): () => void; + /** + * A hook for the browser tracing integrations to trigger after the pageload span was started. + * @returns {() => void} A function that, when executed, removes the registered callback. + */ + public on(hook: 'afterStartPageLoadSpan', callback: (span: Span) => void): () => void; + /** * A hook for triggering right before a navigation span is started. * @returns {() => void} A function that, when executed, removes the registered callback. @@ -791,6 +797,11 @@ export abstract class Client { traceOptions?: { sentryTrace?: string | undefined; baggage?: string | undefined }, ): void; + /** + * Emit a hook event for browser tracing integrations to trigger aafter the pageload span was started. + */ + public emit(hook: 'afterStartPageLoadSpan', span: Span): void; + /** * Emit a hook event for triggering right before a navigation span is started. */ From 75fc4d2758ac88f829914d14b17e9d920013cfa5 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Fri, 11 Jul 2025 12:05:58 +0200 Subject: [PATCH 2/3] pass in client to avoid setTimeout --- .../src/metrics/browserMetrics.ts | 8 ++- packages/browser-utils/src/metrics/cls.ts | 7 ++- packages/browser-utils/src/metrics/inp.ts | 1 + packages/browser-utils/src/metrics/lcp.ts | 7 ++- packages/browser-utils/src/metrics/utils.ts | 58 +++++++++---------- .../src/tracing/browserTracingIntegration.ts | 1 + packages/core/src/client.ts | 34 +++++------ 7 files changed, 60 insertions(+), 56 deletions(-) diff --git a/packages/browser-utils/src/metrics/browserMetrics.ts b/packages/browser-utils/src/metrics/browserMetrics.ts index 18b274b855e0..e9fa822a431e 100644 --- a/packages/browser-utils/src/metrics/browserMetrics.ts +++ b/packages/browser-utils/src/metrics/browserMetrics.ts @@ -1,5 +1,5 @@ /* eslint-disable max-lines */ -import type { Measurements, Span, SpanAttributes, SpanAttributeValue, StartSpanOptions } from '@sentry/core'; +import type { Client, Measurements, Span, SpanAttributes, SpanAttributeValue, StartSpanOptions } from '@sentry/core'; import { browserPerformanceTimeOrigin, getActiveSpan, @@ -83,6 +83,7 @@ let _clsEntry: LayoutShift | undefined; interface StartTrackingWebVitalsOptions { recordClsStandaloneSpans: boolean; recordLcpStandaloneSpans: boolean; + client: Client; } /** @@ -94,6 +95,7 @@ interface StartTrackingWebVitalsOptions { export function startTrackingWebVitals({ recordClsStandaloneSpans, recordLcpStandaloneSpans, + client, }: StartTrackingWebVitalsOptions): () => void { const performance = getBrowserPerformanceAPI(); if (performance && browserPerformanceTimeOrigin()) { @@ -102,9 +104,9 @@ export function startTrackingWebVitals({ WINDOW.performance.mark('sentry-tracing-init'); } const fidCleanupCallback = _trackFID(); - const lcpCleanupCallback = recordLcpStandaloneSpans ? trackLcpAsStandaloneSpan() : _trackLCP(); + const lcpCleanupCallback = recordLcpStandaloneSpans ? trackLcpAsStandaloneSpan(client) : _trackLCP(); const ttfbCleanupCallback = _trackTtfb(); - const clsCleanupCallback = recordClsStandaloneSpans ? trackClsAsStandaloneSpan() : _trackCLS(); + const clsCleanupCallback = recordClsStandaloneSpans ? trackClsAsStandaloneSpan(client) : _trackCLS(); return (): void => { fidCleanupCallback(); diff --git a/packages/browser-utils/src/metrics/cls.ts b/packages/browser-utils/src/metrics/cls.ts index 8839f038fb49..6504b52d0231 100644 --- a/packages/browser-utils/src/metrics/cls.ts +++ b/packages/browser-utils/src/metrics/cls.ts @@ -1,4 +1,4 @@ -import type { SpanAttributes } from '@sentry/core'; +import type { Client, SpanAttributes } from '@sentry/core'; import { browserPerformanceTimeOrigin, getCurrentScope, @@ -24,7 +24,7 @@ import { listenForWebVitalReportEvents, msToSec, startStandaloneWebVitalSpan, su * Once either of these events triggers, the CLS value is sent as a standalone span and we stop * measuring CLS. */ -export function trackClsAsStandaloneSpan(): void { +export function trackClsAsStandaloneSpan(client: Client): void { let standaloneCLsValue = 0; let standaloneClsEntry: LayoutShift | undefined; @@ -41,7 +41,7 @@ export function trackClsAsStandaloneSpan(): void { standaloneClsEntry = entry; }, true); - listenForWebVitalReportEvents((reportEvent, pageloadSpanId) => { + listenForWebVitalReportEvents(client, (reportEvent, pageloadSpanId) => { sendStandaloneClsSpan(standaloneCLsValue, standaloneClsEntry, pageloadSpanId, reportEvent); cleanupClsHandler(); }); @@ -79,6 +79,7 @@ function sendStandaloneClsSpan( } const span = startStandaloneWebVitalSpan({ + type: 'cls', name, transaction: routeName, attributes, diff --git a/packages/browser-utils/src/metrics/inp.ts b/packages/browser-utils/src/metrics/inp.ts index 30a628b5997f..c93f0f5f3119 100644 --- a/packages/browser-utils/src/metrics/inp.ts +++ b/packages/browser-utils/src/metrics/inp.ts @@ -129,6 +129,7 @@ export const _onInp: InstrumentationHandlerCallback = ({ metric }) => { }; const span = startStandaloneWebVitalSpan({ + type: 'inp', name, transaction: routeName, attributes, diff --git a/packages/browser-utils/src/metrics/lcp.ts b/packages/browser-utils/src/metrics/lcp.ts index dc98b2f8f2b1..da6bae6a975d 100644 --- a/packages/browser-utils/src/metrics/lcp.ts +++ b/packages/browser-utils/src/metrics/lcp.ts @@ -1,4 +1,4 @@ -import type { SpanAttributes } from '@sentry/core'; +import type { Client, SpanAttributes } from '@sentry/core'; import { browserPerformanceTimeOrigin, getCurrentScope, @@ -24,7 +24,7 @@ import { listenForWebVitalReportEvents, msToSec, startStandaloneWebVitalSpan, su * Once either of these events triggers, the LCP value is sent as a standalone span and we stop * measuring LCP for subsequent routes. */ -export function trackLcpAsStandaloneSpan(): void { +export function trackLcpAsStandaloneSpan(client: Client): void { let standaloneLcpValue = 0; let standaloneLcpEntry: LargestContentfulPaint | undefined; @@ -41,7 +41,7 @@ export function trackLcpAsStandaloneSpan(): void { standaloneLcpEntry = entry; }, true); - listenForWebVitalReportEvents((reportEvent, pageloadSpanId) => { + listenForWebVitalReportEvents(client, (reportEvent, pageloadSpanId) => { _sendStandaloneLcpSpan(standaloneLcpValue, standaloneLcpEntry, pageloadSpanId, reportEvent); cleanupLcpHandler(); }); @@ -92,6 +92,7 @@ export function _sendStandaloneLcpSpan( } const span = startStandaloneWebVitalSpan({ + type: 'lcp', name, transaction: routeName, attributes, diff --git a/packages/browser-utils/src/metrics/utils.ts b/packages/browser-utils/src/metrics/utils.ts index 073a075db525..f10d3faa4e4e 100644 --- a/packages/browser-utils/src/metrics/utils.ts +++ b/packages/browser-utils/src/metrics/utils.ts @@ -1,13 +1,14 @@ -import type { Integration, SentrySpan, Span, SpanAttributes, SpanTimeInput, StartSpanOptions } from '@sentry/core'; -import { - getActiveSpan, - getClient, - getCurrentScope, - getRootSpan, - spanToJSON, - startInactiveSpan, - withActiveSpan, +import type { + Client, + Integration, + SentrySpan, + Span, + SpanAttributes, + SpanTimeInput, + StartSpanOptions, } from '@sentry/core'; +import { debug, getClient, getCurrentScope, spanToJSON, startInactiveSpan, withActiveSpan } from '@sentry/core'; +import { DEBUG_BUILD } from '../debug-build'; import { WINDOW } from '../types'; import { onHidden } from './web-vitals/lib/onHidden'; @@ -55,6 +56,7 @@ export function startAndEndSpan( } interface StandaloneWebVitalSpanOptions { + type: 'lcp' | 'cls' | 'inp'; name: string; transaction?: string; attributes: SpanAttributes; @@ -83,7 +85,7 @@ export function startStandaloneWebVitalSpan(options: StandaloneWebVitalSpanOptio return; } - const { name, transaction, attributes: passedAttributes, startTime } = options; + const { name, transaction, attributes: passedAttributes, startTime, type } = options; const { release, environment, sendDefaultPii } = client.getOptions(); // We need to get the replay, user, and activeTransaction from the current scope @@ -125,6 +127,9 @@ export function startStandaloneWebVitalSpan(options: StandaloneWebVitalSpanOptio ...passedAttributes, }; + DEBUG_BUILD && + debug.log('Starting standalone web vital span', { type, name, transaction, startTime }, 'attributes:', attributes); + return startInactiveSpan({ name, attributes, @@ -205,6 +210,7 @@ export function supportsWebVital(entryType: 'layout-shift' | 'largest-contentful * - pageloadSpanId: the span id of the pageload span. This is used to link the web vital span to the pageload span. */ export function listenForWebVitalReportEvents( + client: Client, collectorCallback: (event: WebVitalReportEvent, pageloadSpanId: string) => void, ) { let pageloadSpanId: string | undefined; @@ -218,28 +224,20 @@ export function listenForWebVitalReportEvents( } onHidden(() => { - if (!collected) { - _runCollectorCallbackOnce('pagehide'); - } + _runCollectorCallbackOnce('pagehide'); }); - setTimeout(() => { - const client = getClient(); - if (!client) { - return; + const unsubscribeStartNavigation = client.on('beforeStartNavigationSpan', (_, options) => { + // we only want to collect LCP if we actually navigate. Redirects should be ignored. + if (!options?.isRedirect) { + _runCollectorCallbackOnce('navigation'); + unsubscribeStartNavigation?.(); + unsubscribeAfterStartPageLoadSpan?.(); } + }); - const unsubscribeStartNavigation = client.on('beforeStartNavigationSpan', (_, options) => { - // we only want to collect LCP if we actually navigate. Redirects should be ignored. - if (!options?.isRedirect) { - _runCollectorCallbackOnce('navigation'); - unsubscribeStartNavigation?.(); - } - }); - - const unsubscribeAfterStartPageLoadSpan = client.on('afterStartPageLoadSpan', span => { - pageloadSpanId = span.spanContext().spanId; - unsubscribeAfterStartPageLoadSpan?.(); - }); - }, 0); + const unsubscribeAfterStartPageLoadSpan = client.on('afterStartPageLoadSpan', span => { + pageloadSpanId = span.spanContext().spanId; + unsubscribeAfterStartPageLoadSpan?.(); + }); } diff --git a/packages/browser/src/tracing/browserTracingIntegration.ts b/packages/browser/src/tracing/browserTracingIntegration.ts index f5e6c158c3c9..f010030c47c3 100644 --- a/packages/browser/src/tracing/browserTracingIntegration.ts +++ b/packages/browser/src/tracing/browserTracingIntegration.ts @@ -440,6 +440,7 @@ export const browserTracingIntegration = ((_options: Partial { if (options.dsn) { this._dsn = makeDsn(options.dsn); } else { - DEBUG_BUILD && debug.warn('No DSN provided, client will not send events.'); + DEBUG_BUILD && logger.warn('No DSN provided, client will not send events.'); } if (this._dsn) { @@ -182,7 +182,7 @@ export abstract class Client { // ensure we haven't captured this very object before if (checkOrSetAlreadyCaught(exception)) { - DEBUG_BUILD && debug.log(ALREADY_SEEN_ERROR); + DEBUG_BUILD && logger.log(ALREADY_SEEN_ERROR); return eventId; } @@ -237,7 +237,7 @@ export abstract class Client { // ensure we haven't captured this very object before if (hint?.originalException && checkOrSetAlreadyCaught(hint.originalException)) { - DEBUG_BUILD && debug.log(ALREADY_SEEN_ERROR); + DEBUG_BUILD && logger.log(ALREADY_SEEN_ERROR); return eventId; } @@ -429,7 +429,7 @@ export abstract class Client { if ('aggregates' in session) { const sessionAttrs = session.attrs || {}; if (!sessionAttrs.release && !clientReleaseOption) { - DEBUG_BUILD && debug.warn(MISSING_RELEASE_FOR_SESSION_ERROR); + DEBUG_BUILD && logger.warn(MISSING_RELEASE_FOR_SESSION_ERROR); return; } sessionAttrs.release = sessionAttrs.release || clientReleaseOption; @@ -437,7 +437,7 @@ export abstract class Client { session.attrs = sessionAttrs; } else { if (!session.release && !clientReleaseOption) { - DEBUG_BUILD && debug.warn(MISSING_RELEASE_FOR_SESSION_ERROR); + DEBUG_BUILD && logger.warn(MISSING_RELEASE_FOR_SESSION_ERROR); return; } session.release = session.release || clientReleaseOption; @@ -465,7 +465,7 @@ export abstract class Client { // would be `Partial>>>` // With typescript 4.1 we could even use template literal types const key = `${reason}:${category}`; - DEBUG_BUILD && debug.log(`Recording outcome: "${key}"${count > 1 ? ` (${count} times)` : ''}`); + DEBUG_BUILD && logger.log(`Recording outcome: "${key}"${count > 1 ? ` (${count} times)` : ''}`); this._outcomes[key] = (this._outcomes[key] || 0) + count; } } @@ -877,12 +877,12 @@ export abstract class Client { if (this._isEnabled() && this._transport) { return this._transport.send(envelope).then(null, reason => { - DEBUG_BUILD && debug.error('Error while sending envelope:', reason); + DEBUG_BUILD && logger.error('Error while sending envelope:', reason); return reason; }); } - DEBUG_BUILD && debug.error('Transport disabled'); + DEBUG_BUILD && logger.error('Transport disabled'); return resolvedSyncPromise({}); } @@ -1032,7 +1032,7 @@ export abstract class Client { isolationScope = getIsolationScope(), ): PromiseLike { if (DEBUG_BUILD && isErrorEvent(event)) { - debug.log(`Captured error event \`${getPossibleEventMessages(event)[0] || ''}\``); + logger.log(`Captured error event \`${getPossibleEventMessages(event)[0] || ''}\``); } return this._processEvent(event, hint, currentScope, isolationScope).then( @@ -1042,11 +1042,11 @@ export abstract class Client { reason => { if (DEBUG_BUILD) { if (_isDoNotSendEventError(reason)) { - debug.log(reason.message); + logger.log(reason.message); } else if (_isInternalError(reason)) { - debug.warn(reason.message); + logger.warn(reason.message); } else { - debug.warn(reason); + logger.warn(reason); } } return undefined; @@ -1207,22 +1207,22 @@ export abstract class Client { * Sends client reports as an envelope. */ protected _flushOutcomes(): void { - DEBUG_BUILD && debug.log('Flushing outcomes...'); + DEBUG_BUILD && logger.log('Flushing outcomes...'); const outcomes = this._clearOutcomes(); if (outcomes.length === 0) { - DEBUG_BUILD && debug.log('No outcomes to send'); + DEBUG_BUILD && logger.log('No outcomes to send'); return; } // This is really the only place where we want to check for a DSN and only send outcomes then if (!this._dsn) { - DEBUG_BUILD && debug.log('No dsn provided, will not send outcomes'); + DEBUG_BUILD && logger.log('No dsn provided, will not send outcomes'); return; } - DEBUG_BUILD && debug.log('Sending outcomes:', outcomes); + DEBUG_BUILD && logger.log('Sending outcomes:', outcomes); const envelope = createClientReportEnvelope(outcomes, this._options.tunnel && dsnToString(this._dsn)); From f54d641c5ff0cb2ea7a7b6154ea7860d43a71926 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Fri, 11 Jul 2025 12:41:33 +0200 Subject: [PATCH 3/3] cleanup, remove unnecessary log --- packages/browser-utils/src/metrics/cls.ts | 1 - packages/browser-utils/src/metrics/inp.ts | 1 - packages/browser-utils/src/metrics/lcp.ts | 1 - packages/browser-utils/src/metrics/utils.ts | 9 ++---- packages/core/src/client.ts | 34 ++++++++++----------- 5 files changed, 19 insertions(+), 27 deletions(-) diff --git a/packages/browser-utils/src/metrics/cls.ts b/packages/browser-utils/src/metrics/cls.ts index 6504b52d0231..e300fd28d18b 100644 --- a/packages/browser-utils/src/metrics/cls.ts +++ b/packages/browser-utils/src/metrics/cls.ts @@ -79,7 +79,6 @@ function sendStandaloneClsSpan( } const span = startStandaloneWebVitalSpan({ - type: 'cls', name, transaction: routeName, attributes, diff --git a/packages/browser-utils/src/metrics/inp.ts b/packages/browser-utils/src/metrics/inp.ts index c93f0f5f3119..30a628b5997f 100644 --- a/packages/browser-utils/src/metrics/inp.ts +++ b/packages/browser-utils/src/metrics/inp.ts @@ -129,7 +129,6 @@ export const _onInp: InstrumentationHandlerCallback = ({ metric }) => { }; const span = startStandaloneWebVitalSpan({ - type: 'inp', name, transaction: routeName, attributes, diff --git a/packages/browser-utils/src/metrics/lcp.ts b/packages/browser-utils/src/metrics/lcp.ts index da6bae6a975d..6864a233466c 100644 --- a/packages/browser-utils/src/metrics/lcp.ts +++ b/packages/browser-utils/src/metrics/lcp.ts @@ -92,7 +92,6 @@ export function _sendStandaloneLcpSpan( } const span = startStandaloneWebVitalSpan({ - type: 'lcp', name, transaction: routeName, attributes, diff --git a/packages/browser-utils/src/metrics/utils.ts b/packages/browser-utils/src/metrics/utils.ts index f10d3faa4e4e..e56d0ee98d42 100644 --- a/packages/browser-utils/src/metrics/utils.ts +++ b/packages/browser-utils/src/metrics/utils.ts @@ -7,8 +7,7 @@ import type { SpanTimeInput, StartSpanOptions, } from '@sentry/core'; -import { debug, getClient, getCurrentScope, spanToJSON, startInactiveSpan, withActiveSpan } from '@sentry/core'; -import { DEBUG_BUILD } from '../debug-build'; +import { getClient, getCurrentScope, spanToJSON, startInactiveSpan, withActiveSpan } from '@sentry/core'; import { WINDOW } from '../types'; import { onHidden } from './web-vitals/lib/onHidden'; @@ -56,7 +55,6 @@ export function startAndEndSpan( } interface StandaloneWebVitalSpanOptions { - type: 'lcp' | 'cls' | 'inp'; name: string; transaction?: string; attributes: SpanAttributes; @@ -85,7 +83,7 @@ export function startStandaloneWebVitalSpan(options: StandaloneWebVitalSpanOptio return; } - const { name, transaction, attributes: passedAttributes, startTime, type } = options; + const { name, transaction, attributes: passedAttributes, startTime } = options; const { release, environment, sendDefaultPii } = client.getOptions(); // We need to get the replay, user, and activeTransaction from the current scope @@ -127,9 +125,6 @@ export function startStandaloneWebVitalSpan(options: StandaloneWebVitalSpanOptio ...passedAttributes, }; - DEBUG_BUILD && - debug.log('Starting standalone web vital span', { type, name, transaction, startTime }, 'attributes:', attributes); - return startInactiveSpan({ name, attributes, diff --git a/packages/core/src/client.ts b/packages/core/src/client.ts index 0a5124e1b60e..fb7717c6a178 100644 --- a/packages/core/src/client.ts +++ b/packages/core/src/client.ts @@ -37,7 +37,7 @@ import { dsnToString, makeDsn } from './utils/dsn'; import { addItemToEnvelope, createAttachmentEnvelopeItem } from './utils/envelope'; import { getPossibleEventMessages } from './utils/eventUtils'; import { isParameterizedString, isPlainObject, isPrimitive, isThenable } from './utils/is'; -import { logger } from './utils/logger'; +import { debug } from './utils/logger'; import { merge } from './utils/merge'; import { checkOrSetAlreadyCaught, uuid4 } from './utils/misc'; import { parseSampleRate } from './utils/parseSampleRate'; @@ -154,7 +154,7 @@ export abstract class Client { if (options.dsn) { this._dsn = makeDsn(options.dsn); } else { - DEBUG_BUILD && logger.warn('No DSN provided, client will not send events.'); + DEBUG_BUILD && debug.warn('No DSN provided, client will not send events.'); } if (this._dsn) { @@ -182,7 +182,7 @@ export abstract class Client { // ensure we haven't captured this very object before if (checkOrSetAlreadyCaught(exception)) { - DEBUG_BUILD && logger.log(ALREADY_SEEN_ERROR); + DEBUG_BUILD && debug.log(ALREADY_SEEN_ERROR); return eventId; } @@ -237,7 +237,7 @@ export abstract class Client { // ensure we haven't captured this very object before if (hint?.originalException && checkOrSetAlreadyCaught(hint.originalException)) { - DEBUG_BUILD && logger.log(ALREADY_SEEN_ERROR); + DEBUG_BUILD && debug.log(ALREADY_SEEN_ERROR); return eventId; } @@ -429,7 +429,7 @@ export abstract class Client { if ('aggregates' in session) { const sessionAttrs = session.attrs || {}; if (!sessionAttrs.release && !clientReleaseOption) { - DEBUG_BUILD && logger.warn(MISSING_RELEASE_FOR_SESSION_ERROR); + DEBUG_BUILD && debug.warn(MISSING_RELEASE_FOR_SESSION_ERROR); return; } sessionAttrs.release = sessionAttrs.release || clientReleaseOption; @@ -437,7 +437,7 @@ export abstract class Client { session.attrs = sessionAttrs; } else { if (!session.release && !clientReleaseOption) { - DEBUG_BUILD && logger.warn(MISSING_RELEASE_FOR_SESSION_ERROR); + DEBUG_BUILD && debug.warn(MISSING_RELEASE_FOR_SESSION_ERROR); return; } session.release = session.release || clientReleaseOption; @@ -465,7 +465,7 @@ export abstract class Client { // would be `Partial>>>` // With typescript 4.1 we could even use template literal types const key = `${reason}:${category}`; - DEBUG_BUILD && logger.log(`Recording outcome: "${key}"${count > 1 ? ` (${count} times)` : ''}`); + DEBUG_BUILD && debug.log(`Recording outcome: "${key}"${count > 1 ? ` (${count} times)` : ''}`); this._outcomes[key] = (this._outcomes[key] || 0) + count; } } @@ -877,12 +877,12 @@ export abstract class Client { if (this._isEnabled() && this._transport) { return this._transport.send(envelope).then(null, reason => { - DEBUG_BUILD && logger.error('Error while sending envelope:', reason); + DEBUG_BUILD && debug.error('Error while sending envelope:', reason); return reason; }); } - DEBUG_BUILD && logger.error('Transport disabled'); + DEBUG_BUILD && debug.error('Transport disabled'); return resolvedSyncPromise({}); } @@ -1032,7 +1032,7 @@ export abstract class Client { isolationScope = getIsolationScope(), ): PromiseLike { if (DEBUG_BUILD && isErrorEvent(event)) { - logger.log(`Captured error event \`${getPossibleEventMessages(event)[0] || ''}\``); + debug.log(`Captured error event \`${getPossibleEventMessages(event)[0] || ''}\``); } return this._processEvent(event, hint, currentScope, isolationScope).then( @@ -1042,11 +1042,11 @@ export abstract class Client { reason => { if (DEBUG_BUILD) { if (_isDoNotSendEventError(reason)) { - logger.log(reason.message); + debug.log(reason.message); } else if (_isInternalError(reason)) { - logger.warn(reason.message); + debug.warn(reason.message); } else { - logger.warn(reason); + debug.warn(reason); } } return undefined; @@ -1207,22 +1207,22 @@ export abstract class Client { * Sends client reports as an envelope. */ protected _flushOutcomes(): void { - DEBUG_BUILD && logger.log('Flushing outcomes...'); + DEBUG_BUILD && debug.log('Flushing outcomes...'); const outcomes = this._clearOutcomes(); if (outcomes.length === 0) { - DEBUG_BUILD && logger.log('No outcomes to send'); + DEBUG_BUILD && debug.log('No outcomes to send'); return; } // This is really the only place where we want to check for a DSN and only send outcomes then if (!this._dsn) { - DEBUG_BUILD && logger.log('No dsn provided, will not send outcomes'); + DEBUG_BUILD && debug.log('No dsn provided, will not send outcomes'); return; } - DEBUG_BUILD && logger.log('Sending outcomes:', outcomes); + DEBUG_BUILD && debug.log('Sending outcomes:', outcomes); const envelope = createClientReportEnvelope(outcomes, this._options.tunnel && dsnToString(this._dsn));