Skip to content
Closed

Pr 15307 #15902

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
24 changes: 21 additions & 3 deletions .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ module.exports = [
);

config.optimization.minimize = true;
config.optimization.minimizer = [new TerserPlugin()];
config.optimization.minimizer = [
new TerserPlugin({
terserOptions: {
ecma: 'es2020',
},
}),
];

return config;
},
Expand Down Expand Up @@ -69,7 +75,13 @@ module.exports = [
);

config.optimization.minimize = true;
config.optimization.minimizer = [new TerserPlugin()];
config.optimization.minimizer = [
new TerserPlugin({
terserOptions: {
ecma: 'es2020',
},
}),
];

return config;
},
Expand Down Expand Up @@ -248,7 +260,13 @@ module.exports = [
);

config.optimization.minimize = true;
config.optimization.minimizer = [new TerserPlugin()];
config.optimization.minimizer = [
new TerserPlugin({
terserOptions: {
ecma: 'es2020',
},
}),
];

return config;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const NODE_EXPORTS_IGNORE = [
'setNodeAsyncContextStrategy',
'getDefaultIntegrationsWithoutPerformance',
'initWithoutDefaultIntegrations',
'initWithDefaultIntegrations',
'SentryContextManager',
'validateOpenTelemetrySetup',
'preloadOpenTelemetry',
Expand Down
6 changes: 3 additions & 3 deletions packages/angular/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
browserSessionIntegration,
globalHandlersIntegration,
httpContextIntegration,
init as browserInit,
initWithDefaultIntegrations,
linkedErrorsIntegration,
setContext,
} from '@sentry/browser';
Expand Down Expand Up @@ -49,14 +49,14 @@ export function getDefaultIntegrations(_options: BrowserOptions = {}): Integrati
*/
export function init(options: BrowserOptions): Client | undefined {
const opts = {
defaultIntegrations: getDefaultIntegrations(),
...options,
};

applySdkMetadata(opts, 'angular');

checkAndSetAngularVersion();
return browserInit(opts);

return initWithDefaultIntegrations(opts, getDefaultIntegrations);
}

function checkAndSetAngularVersion(): void {
Expand Down
7 changes: 3 additions & 4 deletions packages/astro/src/client/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import type { BrowserOptions } from '@sentry/browser';
import {
browserTracingIntegration,
getDefaultIntegrations as getBrowserDefaultIntegrations,
init as initBrowserSdk,
initWithDefaultIntegrations,
} from '@sentry/browser';
import { applySdkMetadata } from '@sentry/core';
import type { Client, Integration } from '@sentry/core';
import { applySdkMetadata } from '@sentry/core';

// Tree-shakable guard to remove all code related to tracing
declare const __SENTRY_TRACING__: boolean;
Expand All @@ -17,13 +17,12 @@ declare const __SENTRY_TRACING__: boolean;
*/
export function init(options: BrowserOptions): Client | undefined {
const opts = {
defaultIntegrations: getDefaultIntegrations(options),
...options,
};

applySdkMetadata(opts, 'astro', ['astro', 'browser']);

return initBrowserSdk(opts);
return initWithDefaultIntegrations(opts, getDefaultIntegrations);
}

function getDefaultIntegrations(options: BrowserOptions): Integration[] {
Expand Down
4 changes: 4 additions & 0 deletions packages/astro/src/index.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import sentryAstro from './index.server';

/** Initializes Sentry Astro SDK */
export declare function init(options: Options | clientSdk.BrowserOptions | NodeOptions): Client | undefined;
export declare function initWithDefaultIntegrations(
options: Options | clientSdk.BrowserOptions | NodeOptions,
getDefaultIntegrations: (options: Options) => Integration[],
): Client | undefined;

export declare const linkedErrorsIntegration: typeof clientSdk.linkedErrorsIntegration;
export declare const contextLinesIntegration: typeof clientSdk.contextLinesIntegration;
Expand Down
24 changes: 9 additions & 15 deletions packages/astro/test/client/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { afterEach, describe, expect, it, vi } from 'vitest';

import type { BrowserClient } from '@sentry/browser';
import {
browserTracingIntegration,
getActiveSpan,
Expand All @@ -9,11 +8,11 @@ import {
getIsolationScope,
} from '@sentry/browser';
import * as SentryBrowser from '@sentry/browser';
import { SDK_VERSION, getClient } from '@sentry/browser';
import { SDK_VERSION } from '@sentry/browser';

import { init } from '../../src/client/sdk';

const browserInit = vi.spyOn(SentryBrowser, 'init');
const browserInit = vi.spyOn(SentryBrowser, 'initWithDefaultIntegrations');

describe('Sentry client SDK', () => {
describe('init', () => {
Expand Down Expand Up @@ -45,6 +44,7 @@ describe('Sentry client SDK', () => {
},
},
}),
expect.any(Function),
);
});

Expand All @@ -54,45 +54,39 @@ describe('Sentry client SDK', () => {
['tracesSampler', { tracesSampler: () => 1.0 }],
['no tracing option set', {}],
])('adds browserTracingIntegration if tracing is enabled via %s', (_, tracingOptions) => {
init({
const client = init({
dsn: 'https://[email protected]/1337',
...tracingOptions,
});

const integrationsToInit = browserInit.mock.calls[0]![0]?.defaultIntegrations;
const browserTracing = getClient<BrowserClient>()?.getIntegrationByName('BrowserTracing');

expect(integrationsToInit).toContainEqual(expect.objectContaining({ name: 'BrowserTracing' }));
const browserTracing = client?.getIntegrationByName('BrowserTracing');
expect(browserTracing).toBeDefined();
});

it("doesn't add browserTracingIntegration if `__SENTRY_TRACING__` is set to false", () => {
(globalThis as any).__SENTRY_TRACING__ = false;

init({
const client = init({
dsn: 'https://[email protected]/1337',
tracesSampleRate: 1,
});

const integrationsToInit = browserInit.mock.calls[0]![0]?.defaultIntegrations || [];
const browserTracing = getClient<BrowserClient>()?.getIntegrationByName('BrowserTracing');

expect(integrationsToInit).not.toContainEqual(expect.objectContaining({ name: 'BrowserTracing' }));
const browserTracing = client?.getIntegrationByName('BrowserTracing');
expect(browserTracing).toBeUndefined();

delete (globalThis as any).__SENTRY_TRACING__;
});

it('Overrides the automatically default browserTracingIntegration instance with a a user-provided browserTracingIntegration instance', () => {
init({
const client = init({
dsn: 'https://[email protected]/1337',
integrations: [
browserTracingIntegration({ finalTimeout: 10, instrumentNavigation: false, instrumentPageLoad: false }),
],
tracesSampleRate: 1,
});

const browserTracing = getClient<BrowserClient>()?.getIntegrationByName('BrowserTracing');
const browserTracing = client?.getIntegrationByName('BrowserTracing');
expect(browserTracing).toBeDefined();

// no active span means the settings were respected
Expand Down
5 changes: 2 additions & 3 deletions packages/aws-serverless/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
flush,
getCurrentScope,
getDefaultIntegrationsWithoutPerformance,
initWithoutDefaultIntegrations,
initWithDefaultIntegrations,
startSpanManual,
withScope,
} from '@sentry/node';
Expand Down Expand Up @@ -77,13 +77,12 @@ export function getDefaultIntegrations(_options: Options): Integration[] {
*/
export function init(options: NodeOptions = {}): NodeClient | undefined {
const opts = {
defaultIntegrations: getDefaultIntegrations(options),
...options,
};

applySdkMetadata(opts, 'aws-serverless');

return initWithoutDefaultIntegrations(opts);
return initWithDefaultIntegrations(opts, getDefaultIntegrations);
}

/** */
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-serverless/test/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jest.mock('@sentry/node', () => {
const original = jest.requireActual('@sentry/node');
return {
...original,
initWithoutDefaultIntegrations: (options: unknown) => {
initWithDefaultIntegrations: (options: unknown) => {
mockInit(options);
},
startInactiveSpan: (...args: unknown[]) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/browser/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export * from './exports';

export { initWithDefaultIntegrations } from './sdk';

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