Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Lms24 committed Jul 25, 2024
1 parent 9b4de9f commit 10d58d8
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 30 deletions.
20 changes: 5 additions & 15 deletions packages/browser-utils/src/metrics/browserMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import {
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
getActiveSpan,
getClient,
getCurrentScope,
startInactiveSpan,
} from '@sentry/core';
import { setMeasurement } from '@sentry/core';
import type { Integration, Measurements, Span, SpanAttributes, StartSpanOptions } from '@sentry/types';
import type { Measurements, Span, SpanAttributes, StartSpanOptions } from '@sentry/types';
import {
browserPerformanceTimeOrigin,
dropUndefinedKeys,
Expand Down Expand Up @@ -41,7 +40,6 @@ import {
} from './utils';
import { getNavigationEntry } from './web-vitals/lib/getNavigationEntry';
import { getVisibilityWatcher } from './web-vitals/lib/getVisibilityWatcher';
import { onFCP } from './web-vitals/onFCP';
import type { Metric } from './web-vitals/types';

interface NavigatorNetworkInformation {
Expand Down Expand Up @@ -89,6 +87,7 @@ let _performanceCursor: number = 0;
let _measurements: Measurements = {};
let _lcpEntry: LargestContentfulPaint | undefined;
let _clsEntry: LayoutShift | undefined;

interface StartTrackingWebVitalsOptions {
recordClsStandaloneSpans: boolean;
}
Expand Down Expand Up @@ -243,25 +242,15 @@ export { startTrackingINP, registerInpInteractionListener } from './inp';

/** Starts tracking the Cumulative Layout Shift on the current page. */
function _trackCLS(sendAsStandaloneSpan: boolean): () => void {
let _emittedFcp = false;
if (sendAsStandaloneSpan) {
onFCP(
() => {
_emittedFcp = true;
},
{ reportAllChanges: true },
);
}

const cleanupClsCallback = addClsInstrumentationHandler(({ metric }) => {
const entry = metric.entries[metric.entries.length - 1] as LayoutShift | undefined;
if (!entry) {
return;
}

if (sendAsStandaloneSpan && _emittedFcp) {
if (sendAsStandaloneSpan) {
sendStandaloneClsSpan(metric, entry);
// For now, we only emit once CLS span for the initial page load.
// For now, we only emit one CLS span for the initial page load.
// Once we send this, we don't need to track CLS anymore.
setTimeout(() => {
cleanupClsCallback();
Expand Down Expand Up @@ -472,6 +461,7 @@ export function addPerformanceEntries(span: Span, options: AddPerformanceEntries

// If FCP is not recorded we should not record the cls value
// according to the new definition of CLS.
// TODO: Check if the first condition is still necessary: `onCLS` already only fires once `onFCP` was called.
if (!('fcp' in _measurements) || !options.recordClsOnPageloadSpan) {
delete _measurements.cls;
}
Expand Down
2 changes: 0 additions & 2 deletions packages/browser-utils/src/metrics/instrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ function instrumentCls(): StopListening {
});
_previousCls = metric;
},
// We want the callback to be called whenever the CLS value updates.
// By default, the callback is only called when the tab goes to the background.
{ reportAllChanges: false },
);
}
Expand Down
9 changes: 1 addition & 8 deletions packages/browser-utils/src/metrics/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import type { SentrySpan } from '@sentry/core';
import {
SEMANTIC_ATTRIBUTE_EXCLUSIVE_TIME,
getClient,
getCurrentScope,
spanToJSON,
startInactiveSpan,
withActiveSpan,
} from '@sentry/core';
import { getClient, getCurrentScope, spanToJSON, startInactiveSpan, withActiveSpan } from '@sentry/core';
import type { Integration, Span, SpanAttributes, SpanTimeInput, StartSpanOptions } from '@sentry/types';
import { WINDOW } from '../types';

Expand Down
5 changes: 0 additions & 5 deletions packages/browser-utils/src/metrics/web-vitals/getCLS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/

import { getClient } from '@sentry/core';
import { logger } from '@sentry/utils';
import { DEBUG_BUILD } from '../../debug-build';
import { WINDOW } from '../../types';
import { bindReporter } from './lib/bindReporter';
import { initMetric } from './lib/initMetric';
import { observe } from './lib/observe';
Expand Down Expand Up @@ -49,8 +46,6 @@ export const CLSThresholds: MetricRatingThresholds = [0.1, 0.25];
* `callback` is always called when the page's visibility state changes to
* hidden. As a result, the `callback` function might be called multiple times
* during the same page load._
*
* SENTRY-SPECIFIC-CHANGE:
*/
export const onCLS = (onReport: CLSReportCallback, opts: ReportOpts = {}): void => {
// Start monitoring FCP so we can only report CLS if FCP is also reported.
Expand Down

0 comments on commit 10d58d8

Please sign in to comment.