Skip to content

Commit fc1d986

Browse files
authored
ref: Remove & streamline some debug logs (#14456)
Streamline some debug logs, esp. also removing some debug logs around browser metrics, in favor of just having a generic log when we add measurements.
1 parent b271bc8 commit fc1d986

File tree

4 files changed

+20
-30
lines changed

4 files changed

+20
-30
lines changed

packages/browser-utils/src/metrics/browserMetrics.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/* eslint-disable max-lines */
22
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getActiveSpan } from '@sentry/core';
33
import { setMeasurement } from '@sentry/core';
4-
import { browserPerformanceTimeOrigin, getComponentName, htmlTreeAsString, logger, parseUrl } from '@sentry/core';
4+
import { browserPerformanceTimeOrigin, getComponentName, htmlTreeAsString, parseUrl } from '@sentry/core';
55
import type { Measurements, Span, SpanAttributes, StartSpanOptions } from '@sentry/types';
66

77
import { spanToJSON } from '@sentry/core';
8-
import { DEBUG_BUILD } from '../debug-build';
98
import { WINDOW } from '../types';
109
import { trackClsAsStandaloneSpan } from './cls';
1110
import {
@@ -241,7 +240,6 @@ function _trackCLS(): () => void {
241240
if (!entry) {
242241
return;
243242
}
244-
DEBUG_BUILD && logger.log(`[Measurements] Adding CLS ${metric.value}`);
245243
_measurements['cls'] = { value: metric.value, unit: '' };
246244
_clsEntry = entry;
247245
}, true);
@@ -255,7 +253,6 @@ function _trackLCP(): () => void {
255253
return;
256254
}
257255

258-
DEBUG_BUILD && logger.log('[Measurements] Adding LCP');
259256
_measurements['lcp'] = { value: metric.value, unit: 'millisecond' };
260257
_lcpEntry = entry as LargestContentfulPaint;
261258
}, true);
@@ -271,7 +268,6 @@ function _trackFID(): () => void {
271268

272269
const timeOrigin = msToSec(browserPerformanceTimeOrigin as number);
273270
const startTime = msToSec(entry.startTime);
274-
DEBUG_BUILD && logger.log('[Measurements] Adding FID');
275271
_measurements['fid'] = { value: metric.value, unit: 'millisecond' };
276272
_measurements['mark.fid'] = { value: timeOrigin + startTime, unit: 'second' };
277273
});
@@ -284,7 +280,6 @@ function _trackTtfb(): () => void {
284280
return;
285281
}
286282

287-
DEBUG_BUILD && logger.log('[Measurements] Adding TTFB');
288283
_measurements['ttfb'] = { value: metric.value, unit: 'millisecond' };
289284
});
290285
}
@@ -305,7 +300,6 @@ export function addPerformanceEntries(span: Span, options: AddPerformanceEntries
305300
return;
306301
}
307302

308-
DEBUG_BUILD && logger.log('[Tracing] Adding & adjusting spans using Performance API');
309303
const timeOrigin = msToSec(browserPerformanceTimeOrigin);
310304

311305
const performanceEntries = performance.getEntries();
@@ -343,11 +337,9 @@ export function addPerformanceEntries(span: Span, options: AddPerformanceEntries
343337
const shouldRecord = entry.startTime < firstHidden.firstHiddenTime;
344338

345339
if (entry.name === 'first-paint' && shouldRecord) {
346-
DEBUG_BUILD && logger.log('[Measurements] Adding FP');
347340
_measurements['fp'] = { value: entry.startTime, unit: 'millisecond' };
348341
}
349342
if (entry.name === 'first-contentful-paint' && shouldRecord) {
350-
DEBUG_BUILD && logger.log('[Measurements] Adding FCP');
351343
_measurements['fcp'] = { value: entry.startTime, unit: 'millisecond' };
352344
}
353345
break;
@@ -618,8 +610,6 @@ function _trackNavigator(span: Span): void {
618610
/** Add LCP / CLS data to span to allow debugging */
619611
function _setWebVitalAttributes(span: Span): void {
620612
if (_lcpEntry) {
621-
DEBUG_BUILD && logger.log('[Measurements] Adding LCP Data');
622-
623613
// Capture Properties of the LCP element that contributes to the LCP.
624614

625615
if (_lcpEntry.element) {
@@ -652,7 +642,6 @@ function _setWebVitalAttributes(span: Span): void {
652642

653643
// See: https://developer.mozilla.org/en-US/docs/Web/API/LayoutShift
654644
if (_clsEntry && _clsEntry.sources) {
655-
DEBUG_BUILD && logger.log('[Measurements] Adding CLS Data');
656645
_clsEntry.sources.forEach((source, index) =>
657646
span.setAttribute(`cls.source.${index + 1}`, htmlTreeAsString(source.node)),
658647
);
@@ -685,7 +674,6 @@ function _addTtfbRequestTimeToMeasurements(_measurements: Measurements): void {
685674
const { responseStart, requestStart } = navEntry;
686675

687676
if (requestStart <= responseStart) {
688-
DEBUG_BUILD && logger.log('[Measurements] Adding TTFB Request Time');
689677
_measurements['ttfb.requestTime'] = {
690678
value: responseStart - requestStart,
691679
unit: 'millisecond',

packages/browser/src/integrations/httpclient.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ function _parseCookieHeaders(
108108
if (cookieString) {
109109
cookies = _parseCookieString(cookieString);
110110
}
111-
} catch (e) {
112-
DEBUG_BUILD && logger.log(`Could not extract cookies from header ${cookieHeader}`);
111+
} catch {
112+
// ignore it if parsing fails
113113
}
114114

115115
return [headers, cookies];
@@ -138,14 +138,14 @@ function _xhrResponseHandler(
138138
if (cookieString) {
139139
responseCookies = _parseCookieString(cookieString);
140140
}
141-
} catch (e) {
142-
DEBUG_BUILD && logger.log('Could not extract cookies from response headers');
141+
} catch {
142+
// ignore it if parsing fails
143143
}
144144

145145
try {
146146
responseHeaders = _getXHRResponseHeaders(xhr);
147-
} catch (e) {
148-
DEBUG_BUILD && logger.log('Could not extract headers from response');
147+
} catch {
148+
// ignore it if parsing fails
149149
}
150150

151151
requestHeaders = headers;

packages/browser/src/tracing/browserTracingIntegration.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -299,16 +299,20 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
299299
let activeSpan: Span | undefined;
300300
let startingUrl: string | undefined = WINDOW.location && WINDOW.location.href;
301301

302+
function maybeEndActiveSpan(): void {
303+
if (activeSpan && !spanToJSON(activeSpan).timestamp) {
304+
DEBUG_BUILD && logger.log(`[Tracing] Finishing current active span with op: ${spanToJSON(activeSpan).op}`);
305+
// If there's an open active span, we need to finish it before creating an new one.
306+
activeSpan.end();
307+
}
308+
}
309+
302310
client.on('startNavigationSpan', startSpanOptions => {
303311
if (getClient() !== client) {
304312
return;
305313
}
306314

307-
if (activeSpan && !spanToJSON(activeSpan).timestamp) {
308-
DEBUG_BUILD && logger.log(`[Tracing] Finishing current root span with op: ${spanToJSON(activeSpan).op}`);
309-
// If there's an open transaction on the scope, we need to finish it before creating an new one.
310-
activeSpan.end();
311-
}
315+
maybeEndActiveSpan();
312316

313317
activeSpan = _createRouteSpan(client, {
314318
op: 'navigation',
@@ -320,12 +324,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
320324
if (getClient() !== client) {
321325
return;
322326
}
323-
324-
if (activeSpan && !spanToJSON(activeSpan).timestamp) {
325-
DEBUG_BUILD && logger.log(`[Tracing] Finishing current root span with op: ${spanToJSON(activeSpan).op}`);
326-
// If there's an open transaction on the scope, we need to finish it before creating an new one.
327-
activeSpan.end();
328-
}
327+
maybeEndActiveSpan();
329328

330329
const sentryTrace = traceOptions.sentryTrace || getMetaContent('sentry-trace');
331330
const baggage = traceOptions.baggage || getMetaContent('baggage');

packages/core/src/tracing/measurement.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import type { MeasurementUnit, Measurements, TimedEvent } from '@sentry/types';
2+
import { DEBUG_BUILD } from '../debug-build';
23
import {
34
SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT,
45
SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE,
56
} from '../semanticAttributes';
7+
import { logger } from '../utils-hoist';
68
import { getActiveSpan, getRootSpan } from '../utils/spanUtils';
79

810
/**
@@ -13,6 +15,7 @@ export function setMeasurement(name: string, value: number, unit: MeasurementUni
1315
const rootSpan = activeSpan && getRootSpan(activeSpan);
1416

1517
if (rootSpan) {
18+
DEBUG_BUILD && logger.log(`[Measurement] Setting measurement on root span: ${name} = ${value} ${unit}`);
1619
rootSpan.addEvent(name, {
1720
[SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE]: value,
1821
[SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT]: unit as string,

0 commit comments

Comments
 (0)