Skip to content
Open
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
3 changes: 2 additions & 1 deletion packages/angular/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '@sentry/browser';
import type { Client, Integration } from '@sentry/core';
import {
_INTERNAL_captureOptionsSetByUser,
applySdkMetadata,
consoleIntegration,
conversationIdIntegration,
Expand Down Expand Up @@ -55,7 +56,7 @@ export function getDefaultIntegrations(_options: BrowserOptions = {}): Integrati
export function init(options: BrowserOptions): Client | undefined {
const opts = {
defaultIntegrations: getDefaultIntegrations(),
...options,
..._INTERNAL_captureOptionsSetByUser(options),
};

applySdkMetadata(opts, 'angular');
Expand Down
16 changes: 10 additions & 6 deletions packages/angular/src/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
import { FUNCTION, ROUTER } from '@sentry/conventions/op';
import type { Integration, Span } from '@sentry/core';
import {
defineIntegration,
debug,
hasSpanStreamingEnabled,
NAVIGATION_SPAN_NAME_FALLBACK,
Expand All @@ -54,12 +55,7 @@ import { runOutsideAngular } from './zone';

let instrumentationInitialized: boolean;

/**
* A custom browser tracing integration for Angular.
*
* Use this integration in combination with `TraceService`
*/
export function browserTracingIntegration(
function _browserTracingIntegration(
options: Parameters<typeof originalBrowserTracingIntegration>[0] = {},
): Integration {
// If the user opts out to set this up, we just don't initialize this.
Expand All @@ -74,6 +70,14 @@ export function browserTracingIntegration(
});
}

/**
* A custom browser tracing integration for Angular.
*
* Use this integration in combination with `TraceService`
*/
export const browserTracingIntegration: typeof _browserTracingIntegration =
defineIntegration(_browserTracingIntegration);

/**
* This function is extracted to make unit testing easier.
*/
Expand Down
13 changes: 8 additions & 5 deletions packages/astro/src/client/browserTracingIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
WINDOW,
} from '@sentry/browser';
import type { Client, Integration, TransactionSource } from '@sentry/core';
import { debug, hasSpanStreamingEnabled, PAGELOAD_SPAN_NAME_FALLBACK } from '@sentry/core';
import { defineIntegration, debug, hasSpanStreamingEnabled, PAGELOAD_SPAN_NAME_FALLBACK } from '@sentry/core';
import { _INTERNAL_withCacheOrigin } from '@sentry/core/browser';
import { DEBUG_BUILD } from '../debug-build';
import { SENTRY_SEGMENT_NAME_SOURCE, URL_TEMPLATE, SENTRY_ORIGIN } from '@sentry/conventions/attributes';
Expand All @@ -18,10 +18,7 @@ function getMetaContent(metaName: string): string | undefined {
return metaTag?.getAttribute('content') || undefined;
}

/**
* A custom browser tracing integrations for Astro.
*/
export function browserTracingIntegration(
function _browserTracingIntegration(
options: Parameters<typeof originalBrowserTracingIntegration>[0] = {},
): Integration {
const integration = originalBrowserTracingIntegration({ ...options, instrumentPageLoad: false });
Expand Down Expand Up @@ -56,6 +53,12 @@ export function browserTracingIntegration(
};
}

/**
* A custom browser tracing integrations for Astro.
*/
export const browserTracingIntegration: typeof _browserTracingIntegration =
defineIntegration(_browserTracingIntegration);

function getPageloadSpanName(client: Client): { name: string; source: TransactionSource } {
try {
const routeNameFromMetaTags = getMetaContent('sentry-route-name');
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/client/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { BrowserOptions } from '@sentry/browser';
import { getDefaultIntegrations as getBrowserDefaultIntegrations, init as initBrowserSdk } from '@sentry/browser';
import type { Client, Integration } from '@sentry/core';
import { applySdkMetadata } from '@sentry/core';
import { _INTERNAL_captureOptionsSetByUser, applySdkMetadata } from '@sentry/core';
import { applyAstroTunnelOptions } from '../tunnel';
import { browserTracingIntegration } from './browserTracingIntegration';
import { createAstroRouteProvider } from './routeProvider';
Expand All @@ -20,7 +20,7 @@ export function init(options: BrowserOptions): Client | undefined {
// The middleware injects the route into the document, so route parameterization works from `init` on,
// even with tracing disabled.
routeProvider: createAstroRouteProvider(),
...options,
..._INTERNAL_captureOptionsSetByUser(options),
};

applySdkMetadata(opts, 'astro', ['astro', 'browser']);
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/server/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SENTRY_ORIGIN } from '@sentry/conventions/attributes';
import { HTTP_SERVER } from '@sentry/conventions/op';
import { _INTERNAL_getActiveClient, applySdkMetadata, debug } from '@sentry/core';
import { _INTERNAL_captureOptionsSetByUser, _INTERNAL_getActiveClient, applySdkMetadata, debug } from '@sentry/core';
import type { NodeClient, NodeOptions } from '@sentry/node';
import { init as initNodeSdk } from '@sentry/node';
import { isDeno } from '@sentry/server-utils';
Expand Down Expand Up @@ -30,7 +30,7 @@ export function init(options: NodeOptions): NodeClient | undefined {
}

const opts = {
...options,
..._INTERNAL_captureOptionsSetByUser(options),
};

applySdkMetadata(opts, 'astro', ['astro', 'node']);
Expand Down
1 change: 1 addition & 0 deletions packages/astro/test/client/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('Sentry client SDK', () => {
expect(browserInit).toHaveBeenCalledWith(
expect.objectContaining({
_metadata: {
optionsSetByUser: [],
sdk: {
name: 'sentry.javascript.astro',
version: SDK_VERSION,
Expand Down
1 change: 1 addition & 0 deletions packages/astro/test/server/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ describe('Sentry server SDK', () => {
expect(nodeInit).toHaveBeenCalledWith(
expect.objectContaining({
_metadata: {
optionsSetByUser: [],
sdk: {
name: 'sentry.javascript.astro',
version: SDK_VERSION,
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-serverless/src/init.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HTTP_REQUEST_METHOD, URL_PATH } from '@sentry/conventions/attributes';
import { FUNCTION_AWS } from '@sentry/conventions/op';
import type { Integration, Options } from '@sentry/core';
import { applySdkMetadata, debug, envToBool, getSDKSource } from '@sentry/core';
import { _INTERNAL_captureOptionsSetByUser, applySdkMetadata, debug, envToBool, getSDKSource } from '@sentry/core';
import type { NodeClient, NodeOptions } from '@sentry/node';
import { getDefaultIntegrationsWithoutPerformance, initWithoutDefaultIntegrations } from '@sentry/node';
import { awsIntegration } from '@sentry/server-utils';
Expand Down Expand Up @@ -91,7 +91,7 @@ export function init(options: AwsServerlessOptions = {}): NodeClient | undefined
const opts = {
defaultIntegrations: getDefaultIntegrations(options),
useLayerExtension,
...options,
..._INTERNAL_captureOptionsSetByUser(options),
ignoreSpans: getIgnoreSpans(options),
};

Expand Down
1 change: 1 addition & 0 deletions packages/aws-serverless/test/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ describe('AWSLambda', () => {
expect(mockInit).toBeCalledWith(
expect.objectContaining({
_metadata: {
optionsSetByUser: [],
sdk: {
name: 'sentry.javascript.aws-serverless',
packages: [
Expand Down
33 changes: 21 additions & 12 deletions packages/browser/src/tracing/browserTracingIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
StartSpanOptions,
} from '@sentry/core';
import {
defineIntegration,
addNonEnumerableProperty,
consoleSandbox,
dateTimestampInSeconds,
Expand Down Expand Up @@ -328,16 +329,7 @@ const DEFAULT_FORWARDED_OPTIONS = {
linkPreviousTrace: 'in-memory',
} satisfies Partial<BrowserTracingOptions>;

/**
* The Browser Tracing integration automatically instruments browser pageload/navigation
* actions as transactions, and captures requests, metrics and errors as spans.
*
* The integration can be configured with a variety of options, and can be extended to use
* any routing library.
*
* We explicitly export the proper type here, as this has to be extended in some cases.
*/
export const browserTracingIntegration = ((options: Partial<BrowserTracingOptions> = {}) => {
const browserTracingIntegrationFn = ((options: Partial<BrowserTracingOptions> = {}) => {
if ('enableElementTiming' in options) {
consoleSandbox(() => {
// oxlint-disable-next-line no-console
Expand Down Expand Up @@ -400,14 +392,31 @@ export const browserTracingIntegration = ((options: Partial<BrowserTracingOption
});
}) satisfies IntegrationFn;

/**
* The Browser Tracing integration automatically instruments browser pageload/navigation
* actions as transactions, and captures requests, metrics and errors as spans.
*
* The integration can be configured with a variety of options, and can be extended to use
* any routing library.
*
* We explicitly export the proper type here, as this has to be extended in some cases.
*/
export const browserTracingIntegration = defineIntegration(
browserTracingIntegrationFn,
) as typeof browserTracingIntegrationFn;

const browserTracingCoreIntegrationFn = ((options: Partial<BrowserTracingCoreOptions> = {}) =>
_browserTracingIntegration(options)) satisfies IntegrationFn;

/**
* The pageload and navigation spans of `browserTracingIntegration`, without the features it registers as
* standalone integrations (such as `webVitalsIntegration`).
*
* Use it instead of `browserTracingIntegration` to only bundle the integrations you add yourself.
*/
export const browserTracingCoreIntegration = ((options: Partial<BrowserTracingCoreOptions> = {}) =>
_browserTracingIntegration(options)) satisfies IntegrationFn;
export const browserTracingCoreIntegration = defineIntegration(
browserTracingCoreIntegrationFn,
) as typeof browserTracingCoreIntegrationFn;

function _browserTracingIntegration(
options: Partial<BrowserTracingCoreOptions>,
Expand Down
3 changes: 2 additions & 1 deletion packages/bun/src/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as os from 'node:os';
import type { Integration, Options } from '@sentry/core';
import {
_INTERNAL_captureOptionsSetByUser,
applySdkMetadata,
conversationIdIntegration,
dedupeIntegration,
Expand Down Expand Up @@ -150,7 +151,7 @@ function _init(
applySdkMetadata(userOptions, 'bun');

const options = {
...userOptions,
..._INTERNAL_captureOptionsSetByUser(userOptions),
platform: 'javascript',
runtime: userOptions.runtime || { name: 'bun', version: typeof Bun !== 'undefined' ? Bun.version : 'unknown' },
serverName: userOptions.serverName || global.process.env.SENTRY_NAME || os.hostname(),
Expand Down
8 changes: 5 additions & 3 deletions packages/cloudflare/src/options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isObjectLike, envToBool } from '@sentry/core';
import { _INTERNAL_captureOptionsSetByUser, isObjectLike, envToBool } from '@sentry/core';
import type { CloudflareOptions } from './client';

/**
Expand Down Expand Up @@ -33,12 +33,14 @@ function getEnvVar<T extends Record<string, unknown>>(env: unknown, varName: key
* 2. SENTRY_RELEASE environment variable
* 3. CF_VERSION_METADATA.id binding (if configured in the wrangler config)
*
* @param userOptions - The options passed in from the user.
* @param options - The options passed in from the user.
* @param env - The environment variables.
*
* @returns The final options.
*/
export function getFinalOptions(userOptions: CloudflareOptions = {}, env: unknown): CloudflareOptions {
export function getFinalOptions(options: CloudflareOptions = {}, env: unknown): CloudflareOptions {
const userOptions = _INTERNAL_captureOptionsSetByUser(options);

if (!isObjectLike(env)) {
return userOptions;
}
Expand Down
5 changes: 4 additions & 1 deletion packages/cloudflare/src/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { _INTERNAL_captureOptionsSetByUser } from '@sentry/core';
import { initBaseSdk } from './baseSdk';
import type { CloudflareClient, CloudflareOptions } from './client';
import { setupOpenTelemetryTracer } from './opentelemetry/tracer';
Expand All @@ -11,7 +12,9 @@ export { getDefaultIntegrations } from './baseSdk';
/**
* Initializes the cloudflare SDK.
*/
export function init(options: CloudflareOptions): CloudflareClient | undefined {
export function init(userOptions: CloudflareOptions): CloudflareClient | undefined {
const options = _INTERNAL_captureOptionsSetByUser(userOptions);

// Like most Node-based SDKs, Cloudflare defaults to running without a Sentry OpenTelemetry tracer
// provider. Scope isolation is handled by the entrypoint wrappers' AsyncLocalStorage strategy.
options.enableOpenTelemetrySetup ??= false;
Expand Down
3 changes: 2 additions & 1 deletion packages/cloudflare/src/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { FUNCTION } from '@sentry/conventions/op';
import type { PropagationContext, Scope } from '@sentry/core';
import {
_INTERNAL_captureOptionsSetByUser,
captureException,
checkOrSetAlreadyCaught,
flush,
Expand Down Expand Up @@ -279,7 +280,7 @@ export function instrumentWorkflowWithSentry<
construct(target: C, args: [ctx: ExecutionContext, env: any], newTarget) {
const [ctx, env] = args;
const context = instrumentContext(ctx);
const options = optionsCallback(env);
const options = _INTERNAL_captureOptionsSetByUser(optionsCallback(env) || {});
args[0] = context;
args[1] = instrumentEnv(env as Record<string, unknown>, options) as E;
const instance = Reflect.construct(target, args, newTarget) as T;
Expand Down
2 changes: 1 addition & 1 deletion packages/cloudflare/test/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('getFinalOptions', () => {

const result = getFinalOptions(userOptions, env);

expect(result).toEqual(userOptions);
expect(result).toEqual({ ...userOptions, _metadata: { optionsSetByUser: ['dsn', 'release'] } });
});

it('returns user options when env is null', () => {
Expand Down
11 changes: 10 additions & 1 deletion packages/core/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { Integration, IntegrationFn } from './types/integration';
import type { CoreOptions } from './types/options';
import type { StreamedSpanJSON } from './types/span';
import { debug } from './utils/debug-logger';
import { isPlainObject } from './utils/is';

export const installedIntegrations: string[] = [];

Expand Down Expand Up @@ -167,10 +168,18 @@ export function addIntegration(integration: Integration): void {
* Define an integration function that can be used to create an integration instance.
* Note that this by design hides the implementation details of the integration, as they are considered internal.
*/
/*#__NO_SIDE_EFFECTS__*/
export function defineIntegration<Fn extends IntegrationFn>(
fn: Fn,
): (...args: Parameters<Fn>) => Integration & { name: ReturnType<Fn>['name'] } {
return fn;
return (...args: Parameters<Fn>) => {
// Copied before the integration runs, so its writes into the object it was given aren't reported as the user's.
const options: unknown = isPlainObject(args[0]) ? { ...args[0] } : args[0];
const integration = fn(...args) as ReturnType<Fn>;
integration._options = options;

return integration;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Runtime objects serialized as options

Medium Severity

Wrapping tracing integrations with defineIntegration stores the entire first argument as _options. For Vue, Ember, and React Router v4/v5 that includes live router, appInstance, or history objects. isPlainObject treats class instances as walkable, so the config report can recurse the live object graph and send route query data (PII) or a huge payload. TanStack Router already omits the router for this reason.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 1b0bb70. Configure here.

};
}

// When extending an integration, we allow other properties to be passed-through
Expand Down
Loading
Loading