Skip to content

Commit

Permalink
ref(browser): Move browserTracing into browser pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiPrasad committed Apr 10, 2024
1 parent e4ec09e commit 762fd6d
Show file tree
Hide file tree
Showing 56 changed files with 255 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ sentryTest('should add browser-related spans to pageload transaction', async ({
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
const browserSpans = eventData.spans?.filter(({ op }) => op === 'browser');

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

['domContentLoadedEvent', 'loadEvent', 'request', 'response'].forEach(eventDesc =>
['loadEvent', 'request', 'response'].forEach(eventDesc =>
expect(browserSpans).toContainEqual(
expect.objectContaining({
description: eventDesc,
Expand Down
3 changes: 2 additions & 1 deletion packages/browser-utils/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ module.exports = {
},
},
{
files: ['src/browser/web-vitals/**'],
files: ['src/metrics/**'],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
},
},
],
Expand Down
18 changes: 0 additions & 18 deletions packages/browser-utils/src/browser/index.ts

This file was deleted.

17 changes: 8 additions & 9 deletions packages/browser-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
export {
browserTracingIntegration,
startBrowserTracingNavigationSpan,
startBrowserTracingPageLoadSpan,
BROWSER_TRACING_INTEGRATION_ID,
instrumentOutgoingRequests,
defaultRequestInstrumentationOptions,
addPerformanceInstrumentationHandler,
addClsInstrumentationHandler,
addFidInstrumentationHandler,
addTtfbInstrumentationHandler,
addLcpInstrumentationHandler,
} from './browser';
} from './metrics/instrument';

export {
addPerformanceEntries,
startTrackingInteractions,
startTrackingLongTasks,
startTrackingWebVitals,
} from './metrics/browserMetrics';

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

Expand All @@ -20,5 +21,3 @@ export {
addXhrInstrumentationHandler,
SENTRY_XHR_DATA_KEY,
} from './instrument/xhr';

export type { RequestInstrumentationOptions } from './browser';
2 changes: 1 addition & 1 deletion packages/browser-utils/src/instrument/dom.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { HandlerDataDom } from '@sentry/types';

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

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

Expand Down
2 changes: 1 addition & 1 deletion packages/browser-utils/src/instrument/history.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { HandlerDataHistory } from '@sentry/types';
import { addHandler, fill, maybeInstrument, supportsHistory, triggerHandlers } from '@sentry/utils';
import { WINDOW } from '../browser/types';
import { WINDOW } from '../metrics/types';

let lastHref: string | undefined;

Expand Down
2 changes: 1 addition & 1 deletion packages/browser-utils/src/instrument/xhr.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { HandlerDataXhr, SentryWrappedXMLHttpRequest, WrappedFunction } from '@sentry/types';

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

export const SENTRY_XHR_DATA_KEY = '__sentry_xhr_v3__';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import type { Measurements, Span, SpanAttributes, StartSpanOptions } from '@sent
import { browserPerformanceTimeOrigin, getComponentName, htmlTreeAsString, logger, parseUrl } from '@sentry/utils';

import { spanToJSON } from '@sentry/core';
import { DEBUG_BUILD } from '../../debug-build';
import { DEBUG_BUILD } from '../debug-build';
import {
addClsInstrumentationHandler,
addFidInstrumentationHandler,
addLcpInstrumentationHandler,
addPerformanceInstrumentationHandler,
addTtfbInstrumentationHandler,
} from '../instrument';
import { WINDOW } from '../types';
import { getNavigationEntry } from '../web-vitals/lib/getNavigationEntry';
import { getVisibilityWatcher } from '../web-vitals/lib/getVisibilityWatcher';
} from './instrument';
import { WINDOW } from './types';
import { isMeasurementValue, startAndEndSpan } from './utils';
import { getNavigationEntry } from './web-vitals/lib/getNavigationEntry';
import { getVisibilityWatcher } from './web-vitals/lib/getVisibilityWatcher';

interface NavigatorNetworkInformation {
readonly connection?: NetworkInformation;
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ export const FIDThresholds: MetricRatingThresholds = [100, 300];
* _**Important:** since FID is only reported after the user interacts with the
* page, it's possible that it will not be reported for some page loads._
*/
export const onFID = (onReport: FIDReportCallback, opts: ReportOpts = {}): void => {
export const onFID = (onReport: FIDReportCallback, opts: ReportOpts = {}) => {
whenActivated(() => {
const visibilityWatcher = getVisibilityWatcher();
const metric = initMetric('FID');
// eslint-disable-next-line prefer-const
let report: ReturnType<typeof bindReporter>;

const handleEntry = (entry: PerformanceEventTiming) => {
const handleEntry = (entry: PerformanceEventTiming): void => {
// Only report if the page wasn't hidden prior to the first input.
if (entry.startTime < visibilityWatcher.firstHiddenTime) {
metric.value = entry.processingStart - entry.startTime;
Expand Down
59 changes: 0 additions & 59 deletions packages/browser-utils/test/browser/backgroundtab.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
spanToJSON,
} from '@sentry/core';
import type { Span } from '@sentry/types';
import type { ResourceEntry } from '../../../src/browser/metrics';
import { _addMeasureSpans, _addResourceSpans } from '../../../src/browser/metrics';
import { WINDOW } from '../../../src/browser/types';
import { TestClient, getDefaultClientOptions } from '../../utils/TestClient';
import type { ResourceEntry } from '../../src/metrics/browserMetrics';
import { _addMeasureSpans, _addResourceSpans } from '../../src/metrics/browserMetrics';
import { WINDOW } from '../../src/metrics/types';
import { TestClient, getDefaultClientOptions } from '../utils/TestClient';

const mockWindowLocation = {
ancestorOrigins: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
setCurrentClient,
spanToJSON,
} from '@sentry/core';
import { startAndEndSpan } from '../../../src/browser/metrics/utils';
import { TestClient, getDefaultClientOptions } from '../../utils/TestClient';
import { startAndEndSpan } from '../../src/metrics/utils';
import { TestClient, getDefaultClientOptions } from '../utils/TestClient';

describe('startAndEndSpan()', () => {
beforeEach(() => {
Expand Down
10 changes: 5 additions & 5 deletions packages/browser/src/index.bundle.tracing.replay.feedback.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
browserTracingIntegration,
startBrowserTracingNavigationSpan,
startBrowserTracingPageLoadSpan,
} from '@sentry-internal/browser-utils';
import { feedbackIntegration, getFeedback } from '@sentry-internal/feedback';
import { feedbackModalIntegration } from '@sentry-internal/feedback-modal';
import { feedbackScreenshotIntegration } from '@sentry-internal/feedback-screenshot';
import { replayIntegration } from '@sentry-internal/replay';
import { addTracingExtensions } from '@sentry/core';
import {
browserTracingIntegration,
startBrowserTracingNavigationSpan,
startBrowserTracingPageLoadSpan,
} from './tracing/browserTracingIntegration';

// We are patching the global object with our hub extension methods
addTracingExtensions();
Expand Down
10 changes: 5 additions & 5 deletions packages/browser/src/index.bundle.tracing.replay.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {
browserTracingIntegration,
startBrowserTracingNavigationSpan,
startBrowserTracingPageLoadSpan,
} from '@sentry-internal/browser-utils';
import {
feedbackIntegrationShim,
feedbackModalIntegrationShim,
feedbackScreenshotIntegrationShim,
} from '@sentry-internal/integration-shims';
import { replayIntegration } from '@sentry-internal/replay';
import { addTracingExtensions } from '@sentry/core';
import {
browserTracingIntegration,
startBrowserTracingNavigationSpan,
startBrowserTracingPageLoadSpan,
} from './tracing/browserTracingIntegration';

// We are patching the global object with our hub extension methods
addTracingExtensions();
Expand Down
10 changes: 5 additions & 5 deletions packages/browser/src/index.bundle.tracing.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import {
browserTracingIntegration,
startBrowserTracingNavigationSpan,
startBrowserTracingPageLoadSpan,
} from '@sentry-internal/browser-utils';
// This is exported so the loader does not fail when switching off Replay
import {
feedbackIntegrationShim,
Expand All @@ -11,6 +6,11 @@ import {
replayIntegrationShim,
} from '@sentry-internal/integration-shims';
import { addTracingExtensions } from '@sentry/core';
import {
browserTracingIntegration,
startBrowserTracingNavigationSpan,
startBrowserTracingPageLoadSpan,
} from './tracing/browserTracingIntegration';

// We are patching the global object with our hub extension methods
addTracingExtensions();
Expand Down
66 changes: 34 additions & 32 deletions packages/browser/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,47 @@
export * from './exports';

export { reportingObserverIntegration } from './integrations/reportingobserver';
export { httpClientIntegration } from './integrations/httpclient';
export { contextLinesIntegration } from './integrations/contextlines';

export {
addTracingExtensions,
getActiveSpan,
getRootSpan,
startSpan,
startInactiveSpan,
startSpanManual,
withActiveSpan,
getSpanDescendants,
setMeasurement,
getSpanStatusFromHttpCode,
setHttpStatus,
makeMultiplexedTransport,
moduleMetadataIntegration,
captureConsoleIntegration,
debugIntegration,
extraErrorDataIntegration,
rewriteFramesIntegration,
sessionTimingIntegration,
} from '@sentry/core';

export type { Span } from '@sentry/types';

export { reportingObserverIntegration } from './integrations/reportingobserver';
export { httpClientIntegration } from './integrations/httpclient';
export { contextLinesIntegration } from './integrations/contextlines';

export { makeBrowserOfflineTransport } from './transports/offline';

export {
browserTracingIntegration,
startBrowserTracingNavigationSpan,
startBrowserTracingPageLoadSpan,
} from './tracing/browserTracingIntegration';
export {
instrumentOutgoingRequests,
defaultRequestInstrumentationOptions,
} from './tracing/request';
export type { RequestInstrumentationOptions } from './tracing/request';

export { browserProfilingIntegration } from './profiling/integration';

export {
replayIntegration,
getReplay,
Expand All @@ -27,7 +57,6 @@ export type {
ReplaySpanFrame,
ReplaySpanFrameEvent,
} from '@sentry-internal/replay';

export { replayCanvasIntegration } from '@sentry-internal/replay-canvas';

export {
Expand All @@ -37,30 +66,3 @@ export {
} from '@sentry-internal/feedback';
export { feedbackModalIntegration } from '@sentry-internal/feedback-modal';
export { feedbackScreenshotIntegration } from '@sentry-internal/feedback-screenshot';

export {
defaultRequestInstrumentationOptions,
instrumentOutgoingRequests,
browserTracingIntegration,
startBrowserTracingNavigationSpan,
startBrowserTracingPageLoadSpan,
} from '@sentry-internal/browser-utils';
export type { RequestInstrumentationOptions } from '@sentry-internal/browser-utils';
export {
addTracingExtensions,
getActiveSpan,
getRootSpan,
startSpan,
startInactiveSpan,
startSpanManual,
withActiveSpan,
getSpanDescendants,
setMeasurement,
getSpanStatusFromHttpCode,
setHttpStatus,
makeMultiplexedTransport,
moduleMetadataIntegration,
} from '@sentry/core';
export type { Span } from '@sentry/types';
export { makeBrowserOfflineTransport } from './transports/offline';
export { browserProfilingIntegration } from './profiling/integration';
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { spanToJSON } from '@sentry/core';
import { logger } from '@sentry/utils';

import { DEBUG_BUILD } from '../debug-build';
import { WINDOW } from './types';
import { WINDOW } from '../helpers';

/**
* Add a listener that cancels and finishes a transaction when the global
Expand Down
Loading

0 comments on commit 762fd6d

Please sign in to comment.