Skip to content
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
11 changes: 10 additions & 1 deletion packages/browser-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,13 @@ export { isElement } from './is';

export { getAbsoluteUrl } from './instrumentation/location';

export type { FetchHint, NetworkMetaWarning, XhrHint } from './types';
export type {
FetchHint,
HandlerDataDom,
HandlerDataHistory,
HandlerDataXhr,
NetworkMetaWarning,
SentryWrappedXMLHttpRequest,
SentryXhrData,
XhrHint,
} from './types';
2 changes: 1 addition & 1 deletion packages/browser-utils/src/instrumentation/dom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { HandlerDataDom } from '@sentry/core';
import { addHandler, addNonEnumerableProperty, fill, maybeInstrument, triggerHandlers, uuid4 } from '@sentry/core';
import type { HandlerDataDom } from '../types';
import { WINDOW } from '../types';

type SentryWrappedTarget = HTMLElement & { _sentryId?: string };
Expand Down
2 changes: 1 addition & 1 deletion packages/browser-utils/src/instrumentation/history.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { HandlerDataHistory } from '@sentry/core';
import { addHandler, fill, maybeInstrument, supportsHistory, triggerHandlers } from '@sentry/core';
import type { HandlerDataHistory } from '../types';
import { WINDOW } from '../types';

let lastHref: string | undefined;
Expand Down
2 changes: 1 addition & 1 deletion packages/browser-utils/src/instrumentation/xhr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { HandlerDataXhr, SentryWrappedXMLHttpRequest } from '@sentry/core';
import { addHandler, isString, maybeInstrument, timestampInSeconds, triggerHandlers } from '@sentry/core';
import type { HandlerDataXhr, SentryWrappedXMLHttpRequest } from '../types';
import { WINDOW } from '../types';

export const SENTRY_XHR_DATA_KEY = '__sentry_xhr_v3__';
Expand Down
54 changes: 48 additions & 6 deletions packages/browser-utils/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import type {
FetchBreadcrumbHint,
HandlerDataFetch,
SentryWrappedXMLHttpRequest,
XhrBreadcrumbHint,
} from '@sentry/core';
import type { FetchBreadcrumbHint, HandlerDataFetch, XhrBreadcrumbHint } from '@sentry/core';
import { GLOBAL_OBJ } from '@sentry/core';

export const WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ &
Expand All @@ -29,3 +24,50 @@ export type FetchHint = FetchBreadcrumbHint & {
input: HandlerDataFetch['args'];
response: Response;
};

// This should be: null | Blob | BufferSource | FormData | URLSearchParams | string
// But since not all of those are available in node, we just use `unknown` here for now
type XHRSendInput = unknown;

export interface SentryWrappedXMLHttpRequest {
__sentry_xhr_v3__?: SentryXhrData;
__sentry_own_request__?: boolean;
// span id for the xhr request
__sentry_xhr_span_id__?: string;
setRequestHeader?: (key: string, val: string) => void;
getResponseHeader?: (key: string) => string | null;
}

// WARNING: When the shape of this type is changed bump the version in `SentryWrappedXMLHttpRequest`
export interface SentryXhrData {
method: string;
url: string;
status_code?: number;
body?: XHRSendInput;
request_body_size?: number;
response_body_size?: number;
request_headers: Record<string, string>;
}

export interface HandlerDataXhr {
xhr: SentryWrappedXMLHttpRequest;
startTimestamp?: number;
endTimestamp?: number;
error?: unknown;
// This is to be consumed by the HttpClient integration
virtualError?: unknown;
}

export interface HandlerDataDom {
// TODO: Replace `object` here with a vendored type for browser Events. We can't depend on the `DOM` or `react` TS types package here.
event: object | { target: object };
name: string;
global?: boolean;
}

export interface HandlerDataHistory {
/** The full URL of the previous page */
from: string | undefined;
/** The full URL of the new page */
to: string;
}
2 changes: 1 addition & 1 deletion packages/browser-utils/test/instrumentation/xhr.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { HandlerDataXhr } from '@sentry/core';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { addXhrInstrumentationHandler, instrumentXHR } from '../../src/instrumentation/xhr';
import type { HandlerDataXhr } from '../../src/types';
import { WINDOW } from '../../src/types';

const win = WINDOW as typeof WINDOW & { XMLHttpRequest?: typeof XMLHttpRequest };
Expand Down
24 changes: 23 additions & 1 deletion packages/browser/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {
BrowserClientProfilingOptions,
BrowserClientReplayOptions,
ClientOptions,
Event,
Expand All @@ -19,6 +18,29 @@ import type { BrowserTransportOptions } from './transports/types';
*/
declare const __SENTRY_RELEASE__: string | undefined;

export type BrowserClientProfilingOptions = {
/**
* Sets profiling session sample rate for the entire profiling session.
*
* A profiling session corresponds to a user session, meaning it is set once at integration initialization and
* persisted until the next page reload. This rate determines what percentage of user sessions will have profiling enabled.
* @default 0
*/
profileSessionSampleRate?: number;

/**
* Set the lifecycle mode of the profiler.
* - **manual**: The profiler will be manually started and stopped via `startProfiler`/`stopProfiler`.
* If a session is sampled, is dependent on the `profileSessionSampleRate`.
* - **trace**: The profiler will be automatically started when a root span exists and stopped when there are no
* more sampled root spans. Whether a session is sampled, is dependent on the `profileSessionSampleRate` and the
* existing sampling configuration for tracing (`tracesSampleRate`/`tracesSampler`).
*
* @default 'manual'
*/
profileLifecycle?: 'manual' | 'trace';
};

type BrowserSpecificOptions = BrowserClientReplayOptions &
BrowserClientProfilingOptions & {
/** If configured, this URL will be used as base URL for lazy loading integration. */
Expand Down
5 changes: 1 addition & 4 deletions packages/browser/src/integrations/breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import type {
FetchBreadcrumbData,
FetchBreadcrumbHint,
HandlerDataConsole,
HandlerDataDom,
HandlerDataFetch,
HandlerDataHistory,
HandlerDataXhr,
IntegrationFn,
XhrBreadcrumbData,
XhrBreadcrumbHint,
Expand All @@ -28,7 +25,7 @@ import {
safeJoin,
severityLevelFromString,
} from '@sentry/core/browser';
import type { FetchHint, XhrHint } from '@sentry/browser-utils';
import type { FetchHint, HandlerDataDom, HandlerDataHistory, HandlerDataXhr, XhrHint } from '@sentry/browser-utils';
import {
addClickKeypressInstrumentationHandler,
addHistoryInstrumentationHandler,
Expand Down
3 changes: 2 additions & 1 deletion packages/browser/src/integrations/httpclient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Client, Event as SentryEvent, IntegrationFn, SentryWrappedXMLHttpRequest } from '@sentry/core/browser';
import type { Client, Event as SentryEvent, IntegrationFn } from '@sentry/core/browser';
import {
_INTERNAL_filterCookies,
_INTERNAL_filterKeyValueData,
Expand All @@ -12,6 +12,7 @@ import {
isSentryRequestUrl,
supportsNativeFetch,
} from '@sentry/core/browser';
import type { SentryWrappedXMLHttpRequest } from '@sentry/browser-utils';
import { addXhrInstrumentationHandler, SENTRY_XHR_DATA_KEY } from '@sentry/browser-utils';
import { DEBUG_BUILD } from '../debug-build';

Expand Down
12 changes: 2 additions & 10 deletions packages/browser/src/tracing/request.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
/* eslint-disable max-lines */
import type {
Client,
HandlerDataXhr,
RequestHookInfo,
ResponseHookInfo,
SentryWrappedXMLHttpRequest,
Span,
SpanTimeInput,
} from '@sentry/core/browser';
import type { Client, RequestHookInfo, ResponseHookInfo, Span, SpanTimeInput } from '@sentry/core/browser';
import {
addFetchInstrumentationHandler,
getActiveSpan,
Expand All @@ -32,7 +24,7 @@ import {
stripUrlQueryAndFragment,
timestampInSeconds,
} from '@sentry/core/browser';
import type { XhrHint } from '@sentry/browser-utils';
import type { HandlerDataXhr, SentryWrappedXMLHttpRequest, XhrHint } from '@sentry/browser-utils';
import { filterCollectedUrl, filterCollectedUrlQuery } from '@sentry/core';
import {
addPerformanceInstrumentationHandler,
Expand Down
8 changes: 4 additions & 4 deletions packages/browser/test/tracing/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('instrumentOutgoingRequests', () => {
});

it('creates a QUERY XHR span with the QUERY method attribute', () => {
let xhrHandler: ((data: utils.HandlerDataXhr) => void) | undefined;
let xhrHandler: ((data: browserUtils.HandlerDataXhr) => void) | undefined;
let requestSpan: utils.Span | undefined;

vi.spyOn(browserUtils, 'addXhrInstrumentationHandler').mockImplementation(handler => {
Expand All @@ -117,7 +117,7 @@ describe('instrumentOutgoingRequests', () => {
setRequestHeader: vi.fn(),
},
startTimestamp: Date.now(),
} as utils.HandlerDataXhr);
} as browserUtils.HandlerDataXhr);

expect(xhrHandler).toBeDefined();
expect(requestSpan).toBeDefined();
Expand All @@ -134,7 +134,7 @@ describe('instrumentOutgoingRequests', () => {
it('uses the active propagation context for an ignored child span', () => {
const activeSpan = new utils.SentryNonRecordingSpan();
const ignoredSpan = new utils.SentryNonRecordingSpan({ dropReason: 'ignored' });
let xhrHandler: ((data: utils.HandlerDataXhr) => void) | undefined;
let xhrHandler: ((data: browserUtils.HandlerDataXhr) => void) | undefined;

vi.spyOn(browserUtils, 'addXhrInstrumentationHandler').mockImplementation(handler => {
xhrHandler = handler;
Expand Down Expand Up @@ -163,7 +163,7 @@ describe('instrumentOutgoingRequests', () => {
setRequestHeader: vi.fn(),
},
startTimestamp: Date.now(),
} as utils.HandlerDataXhr);
} as browserUtils.HandlerDataXhr);

expect(xhrHandler).toBeDefined();
expect(getTraceDataSpy).toHaveBeenCalledWith({
Expand Down
9 changes: 1 addition & 8 deletions packages/core/src/browser-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,4 @@ export { spanStreamingIntegration } from './integrations/browserSpanStreaming';
export { getLocationHref } from './utils/browser';
export { supportsDOMError, supportsHistory, supportsNativeFetch, supportsReportingObserver } from './utils/supports';
export type { XhrBreadcrumbData, XhrBreadcrumbHint } from './types/breadcrumb';
export type {
HandlerDataXhr,
HandlerDataDom,
HandlerDataHistory,
SentryXhrData,
SentryWrappedXMLHttpRequest,
} from './types/instrument';
export type { BrowserClientReplayOptions, BrowserClientProfilingOptions } from './types/browseroptions';
export type { BrowserClientReplayOptions } from './types/browseroptions';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Public types removed without deprecation

Medium Severity

HandlerDataXhr, HandlerDataDom, HandlerDataHistory, SentryWrappedXMLHttpRequest, SentryXhrData, and BrowserClientProfilingOptions are removed from @sentry/core and @sentry/core/browser with no deprecated re-exports or changelog note. BrowserClientProfilingOptions is also missing from @sentry/browser's public entry, so existing type imports fail to compile. Flagged because the review rules call out public API removals without deprecation.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit 5fe62fa. Configure here.

23 changes: 0 additions & 23 deletions packages/core/src/types/browseroptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,3 @@ export type BrowserClientReplayOptions = {
*/
replaysOnErrorSampleRate?: number;
};

export type BrowserClientProfilingOptions = {
/**
* Sets profiling session sample rate for the entire profiling session.
*
* A profiling session corresponds to a user session, meaning it is set once at integration initialization and
* persisted until the next page reload. This rate determines what percentage of user sessions will have profiling enabled.
* @default 0
*/
profileSessionSampleRate?: number;

/**
* Set the lifecycle mode of the profiler.
* - **manual**: The profiler will be manually started and stopped via `startProfiler`/`stopProfiler`.
* If a session is sampled, is dependent on the `profileSessionSampleRate`.
* - **trace**: The profiler will be automatically started when a root span exists and stopped when there are no
* more sampled root spans. Whether a session is sampled, is dependent on the `profileSessionSampleRate` and the
* existing sampling configuration for tracing (`tracesSampleRate`/`tracesSampler`).
*
* @default 'manual'
*/
profileLifecycle?: 'manual' | 'trace';
};
49 changes: 0 additions & 49 deletions packages/core/src/types/instrument.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,7 @@
// This should be: null | Blob | BufferSource | FormData | URLSearchParams | string
// But since not all of those are available in node, we just export `unknown` here for now

import type { WebFetchHeaders } from './webfetchapi';

// Make sure to cast it where needed!
type XHRSendInput = unknown;

export type ConsoleLevel = 'debug' | 'info' | 'warn' | 'error' | 'log' | 'assert' | 'trace';

export interface SentryWrappedXMLHttpRequest {
__sentry_xhr_v3__?: SentryXhrData;
__sentry_own_request__?: boolean;
// span id for the xhr request
__sentry_xhr_span_id__?: string;
setRequestHeader?: (key: string, val: string) => void;
getResponseHeader?: (key: string) => string | null;
}

// WARNING: When the shape of this type is changed bump the version in `SentryWrappedXMLHttpRequest`
export interface SentryXhrData {
method: string;
url: string;
status_code?: number;
body?: XHRSendInput;
request_body_size?: number;
response_body_size?: number;
request_headers: Record<string, string>;
}

export interface HandlerDataXhr {
xhr: SentryWrappedXMLHttpRequest;
startTimestamp?: number;
endTimestamp?: number;
error?: unknown;
// This is to be consumed by the HttpClient integration
virtualError?: unknown;
}

interface SentryFetchData {
method: string;
url: string;
Expand Down Expand Up @@ -66,26 +31,12 @@ export interface HandlerDataFetch {
headers?: WebFetchHeaders;
}

export interface HandlerDataDom {
// TODO: Replace `object` here with a vendored type for browser Events. We can't depend on the `DOM` or `react` TS types package here.
event: object | { target: object };
name: string;
global?: boolean;
}

export interface HandlerDataConsole {
level: ConsoleLevel;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
args: any[];
}

export interface HandlerDataHistory {
/** The full URL of the previous page */
from: string | undefined;
/** The full URL of the new page */
to: string;
}

export interface HandlerDataError {
column?: number;
error?: Error;
Expand Down
3 changes: 2 additions & 1 deletion packages/replay-internal/src/coreHandlers/handleDom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { HandlerDataDom } from '@sentry/browser-utils';
import { htmlTreeAsString } from '@sentry/browser-utils';
import type { Breadcrumb, HandlerDataDom } from '@sentry/core';
import type { Breadcrumb } from '@sentry/core';
import { record } from '@sentry/rrweb';
import type { serializedElementNodeWithId, serializedNodeWithId } from '@sentry/rrweb-snapshot';
import { NodeType } from '@sentry/rrweb-snapshot';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { HandlerDataHistory } from '@sentry/core';
import type { HandlerDataHistory } from '@sentry/browser-utils';
import type { HistoryData, ReplayContainer, ReplayPerformanceEntry } from '../types';
import { createPerformanceSpans } from '../util/createPerformanceSpans';

Expand Down
2 changes: 1 addition & 1 deletion packages/replay-internal/test/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import type { HandlerDataDom } from '@sentry/core';
import type { HandlerDataDom } from '@sentry/browser-utils';

export type DomHandler = (data: HandlerDataDom) => void;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @vitest-environment jsdom
*/

import type { HandlerDataDom } from '@sentry/core';
import type { HandlerDataDom } from '@sentry/browser-utils';
import { describe, expect, test } from 'vitest';
import { handleDom } from '../../../src/coreHandlers/handleDom';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
*/

import '../../utils/mock-internal-setTimeout';
import type {
Breadcrumb,
BreadcrumbHint,
FetchBreadcrumbHint,
SentryWrappedXMLHttpRequest,
XhrBreadcrumbHint,
} from '@sentry/core';
import type { Breadcrumb, BreadcrumbHint, FetchBreadcrumbHint, XhrBreadcrumbHint } from '@sentry/core';
import type { SentryWrappedXMLHttpRequest } from '@sentry/browser-utils';
import { SENTRY_XHR_DATA_KEY } from '@sentry/browser-utils';
import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
import { NETWORK_BODY_MAX_SIZE } from '../../../src/constants';
Expand Down
Loading