Skip to content

ref: Remove & streamline some debug logs #14456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions packages/browser-utils/src/metrics/browserMetrics.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/* eslint-disable max-lines */
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getActiveSpan } from '@sentry/core';
import { setMeasurement } from '@sentry/core';
import { browserPerformanceTimeOrigin, getComponentName, htmlTreeAsString, logger, parseUrl } from '@sentry/core';
import { browserPerformanceTimeOrigin, getComponentName, htmlTreeAsString, parseUrl } from '@sentry/core';
import type { Measurements, Span, SpanAttributes, StartSpanOptions } from '@sentry/types';

import { spanToJSON } from '@sentry/core';
import { DEBUG_BUILD } from '../debug-build';
import { WINDOW } from '../types';
import { trackClsAsStandaloneSpan } from './cls';
import {
Expand Down Expand Up @@ -241,7 +240,6 @@ function _trackCLS(): () => void {
if (!entry) {
return;
}
DEBUG_BUILD && logger.log(`[Measurements] Adding CLS ${metric.value}`);
_measurements['cls'] = { value: metric.value, unit: '' };
_clsEntry = entry;
}, true);
Expand All @@ -255,7 +253,6 @@ function _trackLCP(): () => void {
return;
}

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

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

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

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

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

if (entry.name === 'first-paint' && shouldRecord) {
DEBUG_BUILD && logger.log('[Measurements] Adding FP');
_measurements['fp'] = { value: entry.startTime, unit: 'millisecond' };
}
if (entry.name === 'first-contentful-paint' && shouldRecord) {
DEBUG_BUILD && logger.log('[Measurements] Adding FCP');
_measurements['fcp'] = { value: entry.startTime, unit: 'millisecond' };
}
break;
Expand Down Expand Up @@ -618,8 +610,6 @@ function _trackNavigator(span: Span): void {
/** Add LCP / CLS data to span to allow debugging */
function _setWebVitalAttributes(span: Span): void {
if (_lcpEntry) {
DEBUG_BUILD && logger.log('[Measurements] Adding LCP Data');

// Capture Properties of the LCP element that contributes to the LCP.

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

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

if (requestStart <= responseStart) {
DEBUG_BUILD && logger.log('[Measurements] Adding TTFB Request Time');
_measurements['ttfb.requestTime'] = {
value: responseStart - requestStart,
unit: 'millisecond',
Expand Down
12 changes: 6 additions & 6 deletions packages/browser/src/integrations/httpclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ function _parseCookieHeaders(
if (cookieString) {
cookies = _parseCookieString(cookieString);
}
} catch (e) {
DEBUG_BUILD && logger.log(`Could not extract cookies from header ${cookieHeader}`);
} catch {
// ignore it if parsing fails
}

return [headers, cookies];
Expand Down Expand Up @@ -138,14 +138,14 @@ function _xhrResponseHandler(
if (cookieString) {
responseCookies = _parseCookieString(cookieString);
}
} catch (e) {
DEBUG_BUILD && logger.log('Could not extract cookies from response headers');
} catch {
// ignore it if parsing fails
}

try {
responseHeaders = _getXHRResponseHeaders(xhr);
} catch (e) {
DEBUG_BUILD && logger.log('Could not extract headers from response');
} catch {
// ignore it if parsing fails
}

requestHeaders = headers;
Expand Down
21 changes: 10 additions & 11 deletions packages/browser/src/tracing/browserTracingIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,16 +299,20 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
let activeSpan: Span | undefined;
let startingUrl: string | undefined = WINDOW.location && WINDOW.location.href;

function maybeEndActiveSpan(): void {
if (activeSpan && !spanToJSON(activeSpan).timestamp) {
DEBUG_BUILD && logger.log(`[Tracing] Finishing current active span with op: ${spanToJSON(activeSpan).op}`);
// If there's an open active span, we need to finish it before creating an new one.
activeSpan.end();
}
}

client.on('startNavigationSpan', startSpanOptions => {
if (getClient() !== client) {
return;
}

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

activeSpan = _createRouteSpan(client, {
op: 'navigation',
Expand All @@ -320,12 +324,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
if (getClient() !== client) {
return;
}

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

const sentryTrace = traceOptions.sentryTrace || getMetaContent('sentry-trace');
const baggage = traceOptions.baggage || getMetaContent('baggage');
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/tracing/measurement.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { MeasurementUnit, Measurements, TimedEvent } from '@sentry/types';
import { DEBUG_BUILD } from '../debug-build';
import {
SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT,
SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE,
} from '../semanticAttributes';
import { logger } from '../utils-hoist';
import { getActiveSpan, getRootSpan } from '../utils/spanUtils';

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

if (rootSpan) {
DEBUG_BUILD && logger.log(`[Measurement] Setting measurement on root span: ${name} = ${value} ${unit}`);
rootSpan.addEvent(name, {
[SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE]: value,
[SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT]: unit as string,
Expand Down
Loading