Skip to content

Commit f6a3e02

Browse files
authored
ref(browser): Move browserTracing into browser pkg (#11484)
This PR moves `browserTracingIntegration` into the browser package, leaving `browser-utils` only existing purely for utils/instrumentation (and our vendored web vitals implementation). resolves #9885
1 parent dd41c2e commit f6a3e02

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+213
-207
lines changed

dev-packages/browser-integration-tests/suites/tracing/metrics/pageload-browser-spans/test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ sentryTest('should add browser-related spans to pageload transaction', async ({
1414
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
1515
const browserSpans = eventData.spans?.filter(({ op }) => op === 'browser');
1616

17-
// Spans `connect`, `cache` and `DNS` are not always inside `pageload` transaction.
17+
// Spans `domContentLoadedEvent`, `connect`, `cache` and `DNS` are not
18+
// always inside `pageload` transaction.
1819
expect(browserSpans?.length).toBeGreaterThanOrEqual(4);
1920

20-
['domContentLoadedEvent', 'loadEvent', 'request', 'response'].forEach(eventDesc =>
21+
['loadEvent', 'request', 'response'].forEach(eventDesc =>
2122
expect(browserSpans).toContainEqual(
2223
expect.objectContaining({
2324
description: eventDesc,

packages/browser-utils/.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ module.exports = {
1111
},
1212
},
1313
{
14-
files: ['src/browser/web-vitals/**'],
14+
files: ['src/metrics/**'],
1515
rules: {
1616
'@typescript-eslint/explicit-function-return-type': 'off',
17+
'@typescript-eslint/no-non-null-assertion': 'off',
1718
},
1819
},
1920
],

packages/browser-utils/src/browser/index.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

packages/browser-utils/src/index.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
export {
2-
browserTracingIntegration,
3-
startBrowserTracingNavigationSpan,
4-
startBrowserTracingPageLoadSpan,
5-
BROWSER_TRACING_INTEGRATION_ID,
6-
instrumentOutgoingRequests,
7-
defaultRequestInstrumentationOptions,
82
addPerformanceInstrumentationHandler,
93
addClsInstrumentationHandler,
104
addFidInstrumentationHandler,
115
addTtfbInstrumentationHandler,
126
addLcpInstrumentationHandler,
13-
} from './browser';
7+
} from './metrics/instrument';
8+
9+
export {
10+
addPerformanceEntries,
11+
startTrackingInteractions,
12+
startTrackingLongTasks,
13+
startTrackingWebVitals,
14+
} from './metrics/browserMetrics';
1415

1516
export { addClickKeypressInstrumentationHandler } from './instrument/dom';
1617

@@ -20,5 +21,3 @@ export {
2021
addXhrInstrumentationHandler,
2122
SENTRY_XHR_DATA_KEY,
2223
} from './instrument/xhr';
23-
24-
export type { RequestInstrumentationOptions } from './browser';

packages/browser-utils/src/instrument/dom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { HandlerDataDom } from '@sentry/types';
22

33
import { addHandler, addNonEnumerableProperty, fill, maybeInstrument, triggerHandlers, uuid4 } from '@sentry/utils';
4-
import { WINDOW } from '../browser/types';
4+
import { WINDOW } from '../metrics/types';
55

66
type SentryWrappedTarget = HTMLElement & { _sentryId?: string };
77

packages/browser-utils/src/instrument/history.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { HandlerDataHistory } from '@sentry/types';
22
import { addHandler, fill, maybeInstrument, supportsHistory, triggerHandlers } from '@sentry/utils';
3-
import { WINDOW } from '../browser/types';
3+
import { WINDOW } from '../metrics/types';
44

55
let lastHref: string | undefined;
66

packages/browser-utils/src/instrument/xhr.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { HandlerDataXhr, SentryWrappedXMLHttpRequest, WrappedFunction } from '@sentry/types';
22

33
import { addHandler, fill, isString, maybeInstrument, triggerHandlers } from '@sentry/utils';
4-
import { WINDOW } from '../browser/types';
4+
import { WINDOW } from '../metrics/types';
55

66
export const SENTRY_XHR_DATA_KEY = '__sentry_xhr_v3__';
77

packages/browser-utils/src/browser/metrics/index.ts renamed to packages/browser-utils/src/metrics/browserMetrics.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ import type { Measurements, Span, SpanAttributes, StartSpanOptions } from '@sent
55
import { browserPerformanceTimeOrigin, getComponentName, htmlTreeAsString, logger, parseUrl } from '@sentry/utils';
66

77
import { spanToJSON } from '@sentry/core';
8-
import { DEBUG_BUILD } from '../../debug-build';
8+
import { DEBUG_BUILD } from '../debug-build';
99
import {
1010
addClsInstrumentationHandler,
1111
addFidInstrumentationHandler,
1212
addLcpInstrumentationHandler,
1313
addPerformanceInstrumentationHandler,
1414
addTtfbInstrumentationHandler,
15-
} from '../instrument';
16-
import { WINDOW } from '../types';
17-
import { getNavigationEntry } from '../web-vitals/lib/getNavigationEntry';
18-
import { getVisibilityWatcher } from '../web-vitals/lib/getVisibilityWatcher';
15+
} from './instrument';
16+
import { WINDOW } from './types';
1917
import { isMeasurementValue, startAndEndSpan } from './utils';
18+
import { getNavigationEntry } from './web-vitals/lib/getNavigationEntry';
19+
import { getVisibilityWatcher } from './web-vitals/lib/getVisibilityWatcher';
2020

2121
interface NavigatorNetworkInformation {
2222
readonly connection?: NetworkInformation;

packages/browser-utils/src/browser/web-vitals/getFID.ts renamed to packages/browser-utils/src/metrics/web-vitals/getFID.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ export const FIDThresholds: MetricRatingThresholds = [100, 300];
3535
* _**Important:** since FID is only reported after the user interacts with the
3636
* page, it's possible that it will not be reported for some page loads._
3737
*/
38-
export const onFID = (onReport: FIDReportCallback, opts: ReportOpts = {}): void => {
38+
export const onFID = (onReport: FIDReportCallback, opts: ReportOpts = {}) => {
3939
whenActivated(() => {
4040
const visibilityWatcher = getVisibilityWatcher();
4141
const metric = initMetric('FID');
4242
// eslint-disable-next-line prefer-const
4343
let report: ReturnType<typeof bindReporter>;
4444

45-
const handleEntry = (entry: PerformanceEventTiming) => {
45+
const handleEntry = (entry: PerformanceEventTiming): void => {
4646
// Only report if the page wasn't hidden prior to the first input.
4747
if (entry.startTime < visibilityWatcher.firstHiddenTime) {
4848
metric.value = entry.processingStart - entry.startTime;

packages/browser-utils/test/browser/backgroundtab.test.ts

Lines changed: 0 additions & 59 deletions
This file was deleted.

packages/browser-utils/test/browser/metrics/index.test.ts renamed to packages/browser-utils/test/browser/browserMetrics.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import {
99
spanToJSON,
1010
} from '@sentry/core';
1111
import type { Span } from '@sentry/types';
12-
import type { ResourceEntry } from '../../../src/browser/metrics';
13-
import { _addMeasureSpans, _addResourceSpans } from '../../../src/browser/metrics';
14-
import { WINDOW } from '../../../src/browser/types';
15-
import { TestClient, getDefaultClientOptions } from '../../utils/TestClient';
12+
import type { ResourceEntry } from '../../src/metrics/browserMetrics';
13+
import { _addMeasureSpans, _addResourceSpans } from '../../src/metrics/browserMetrics';
14+
import { WINDOW } from '../../src/metrics/types';
15+
import { TestClient, getDefaultClientOptions } from '../utils/TestClient';
1616

1717
const mockWindowLocation = {
1818
ancestorOrigins: {},

packages/browser-utils/test/browser/metrics/utils.test.ts renamed to packages/browser-utils/test/browser/utils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {
66
setCurrentClient,
77
spanToJSON,
88
} from '@sentry/core';
9-
import { startAndEndSpan } from '../../../src/browser/metrics/utils';
10-
import { TestClient, getDefaultClientOptions } from '../../utils/TestClient';
9+
import { startAndEndSpan } from '../../src/metrics/utils';
10+
import { TestClient, getDefaultClientOptions } from '../utils/TestClient';
1111

1212
describe('startAndEndSpan()', () => {
1313
beforeEach(() => {

packages/browser/src/index.bundle.tracing.replay.feedback.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ export {
2828
browserTracingIntegration,
2929
startBrowserTracingNavigationSpan,
3030
startBrowserTracingPageLoadSpan,
31-
} from '@sentry-internal/browser-utils';
31+
} from './tracing/browserTracingIntegration';
3232

3333
export { replayIntegration } from '@sentry-internal/replay';

packages/browser/src/index.bundle.tracing.replay.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export {
2626
browserTracingIntegration,
2727
startBrowserTracingNavigationSpan,
2828
startBrowserTracingPageLoadSpan,
29-
} from '@sentry-internal/browser-utils';
29+
} from './tracing/browserTracingIntegration';
3030

3131
export {
3232
feedbackIntegrationShim as feedbackIntegration,

packages/browser/src/index.bundle.tracing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export {
2828
browserTracingIntegration,
2929
startBrowserTracingNavigationSpan,
3030
startBrowserTracingPageLoadSpan,
31-
} from '@sentry-internal/browser-utils';
31+
} from './tracing/browserTracingIntegration';
3232

3333
export {
3434
feedbackIntegrationShim as feedbackIntegration,

packages/browser/src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ export {
4141
export {
4242
defaultRequestInstrumentationOptions,
4343
instrumentOutgoingRequests,
44+
} from './tracing/request';
45+
export {
4446
browserTracingIntegration,
4547
startBrowserTracingNavigationSpan,
4648
startBrowserTracingPageLoadSpan,
47-
} from '@sentry-internal/browser-utils';
48-
export type { RequestInstrumentationOptions } from '@sentry-internal/browser-utils';
49+
} from './tracing/browserTracingIntegration';
50+
export type { RequestInstrumentationOptions } from './tracing/request';
4951
export {
5052
addTracingExtensions,
5153
getActiveSpan,

packages/browser-utils/src/browser/backgroundtab.ts renamed to packages/browser/src/tracing/backgroundtab.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { spanToJSON } from '@sentry/core';
33
import { logger } from '@sentry/utils';
44

55
import { DEBUG_BUILD } from '../debug-build';
6-
import { WINDOW } from './types';
6+
import { WINDOW } from '../helpers';
77

88
/**
99
* Add a listener that cancels and finishes a transaction when the global

packages/browser-utils/src/browser/browserTracingIntegration.ts renamed to packages/browser/src/tracing/browserTracingIntegration.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import {
2+
addHistoryInstrumentationHandler,
3+
addPerformanceEntries,
4+
startTrackingInteractions,
5+
startTrackingLongTasks,
6+
startTrackingWebVitals,
7+
} from '@sentry-internal/browser-utils';
18
import {
29
SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON,
310
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
@@ -19,16 +26,9 @@ import type { Span } from '@sentry/types';
1926
import { browserPerformanceTimeOrigin, getDomElement, logger, uuid4 } from '@sentry/utils';
2027

2128
import { DEBUG_BUILD } from '../debug-build';
22-
import { addHistoryInstrumentationHandler } from '../instrument/history';
29+
import { WINDOW } from '../helpers';
2330
import { registerBackgroundTabDetection } from './backgroundtab';
24-
import {
25-
addPerformanceEntries,
26-
startTrackingInteractions,
27-
startTrackingLongTasks,
28-
startTrackingWebVitals,
29-
} from './metrics';
3031
import { defaultRequestInstrumentationOptions, instrumentOutgoingRequests } from './request';
31-
import { WINDOW } from './types';
3232

3333
export const BROWSER_TRACING_INTEGRATION_ID = 'BrowserTracing';
3434

@@ -224,8 +224,6 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
224224

225225
return {
226226
name: BROWSER_TRACING_INTEGRATION_ID,
227-
// eslint-disable-next-line @typescript-eslint/no-empty-function
228-
setupOnce: () => {},
229227
afterAllSetup(client) {
230228
const { markBackgroundSpan, traceFetch, traceXHR, shouldCreateSpanForRequest, enableHTTPTimings, _experiments } =
231229
options;
@@ -249,7 +247,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
249247
});
250248
});
251249

252-
client.on('startPageLoadSpan', (startSpanOptions, traceOptions) => {
250+
client.on('startPageLoadSpan', (startSpanOptions, traceOptions = {}) => {
253251
if (getClient() !== client) {
254252
return;
255253
}
@@ -260,8 +258,8 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
260258
activeSpan.end();
261259
}
262260

263-
const sentryTrace = traceOptions?.sentryTrace || getMetaContent('sentry-trace');
264-
const baggage = traceOptions?.baggage || getMetaContent('baggage');
261+
const sentryTrace = traceOptions.sentryTrace || getMetaContent('sentry-trace');
262+
const baggage = traceOptions.baggage || getMetaContent('baggage');
265263

266264
// Continue trace updates the scope in the callback only, but we want to break out of it again...
267265
// This is a bit hacky, because we want to get the span to use both the correct scope _and_ the correct propagation context

packages/browser-utils/src/browser/request.ts renamed to packages/browser/src/tracing/request.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import {
2+
SENTRY_XHR_DATA_KEY,
3+
addPerformanceInstrumentationHandler,
4+
addXhrInstrumentationHandler,
5+
} from '@sentry-internal/browser-utils';
16
import {
27
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
38
SentryNonRecordingSpan,
@@ -22,10 +27,7 @@ import {
2227
generateSentryTraceHeader,
2328
stringMatchesSomePattern,
2429
} from '@sentry/utils';
25-
import { SENTRY_XHR_DATA_KEY, addXhrInstrumentationHandler } from '../instrument/xhr';
26-
27-
import { addPerformanceInstrumentationHandler } from './instrument';
28-
import { WINDOW } from './types';
30+
import { WINDOW } from '../helpers';
2931

3032
/** Options for Request Instrumentation */
3133
export interface RequestInstrumentationOptions {

packages/browser/test/unit/helper/browser-client-options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { BrowserClientOptions } from '../../../src/client';
55

66
export function getDefaultBrowserClientOptions(options: Partial<BrowserClientOptions> = {}): BrowserClientOptions {
77
return {
8+
dsn: 'http://examplePublicKey@localhost/0',
89
integrations: [],
910
transport: () => createTransport({ recordDroppedEvent: () => undefined }, _ => resolvedSyncPromise({})),
1011
stackParser: () => [],

packages/browser/test/unit/index.bundle.tracing.replay.feedback.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { browserTracingIntegration } from '@sentry-internal/browser-utils';
21
import {
2+
browserTracingIntegration,
33
feedbackIntegration,
44
feedbackModalIntegration,
55
feedbackScreenshotIntegration,
66
replayIntegration,
7-
} from '@sentry/browser';
8-
7+
} from '../../src';
98
import * as TracingReplayFeedbackBundle from '../../src/index.bundle.tracing.replay.feedback';
109

1110
describe('index.bundle.tracing.replay.feedback', () => {

packages/browser/test/unit/index.bundle.tracing.replay.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { browserTracingIntegration } from '@sentry-internal/browser-utils';
21
import {
32
feedbackIntegrationShim,
43
feedbackModalIntegrationShim,
54
feedbackScreenshotIntegrationShim,
65
} from '@sentry-internal/integration-shims';
7-
import { replayIntegration } from '@sentry/browser';
86

7+
import { browserTracingIntegration, replayIntegration } from '../../src';
98
import * as TracingReplayBundle from '../../src/index.bundle.tracing.replay';
109

1110
describe('index.bundle.tracing.replay', () => {

0 commit comments

Comments
 (0)