Skip to content

ref: Make setupOnce optional in integrations #10729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2024
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
2 changes: 0 additions & 2 deletions packages/browser/src/integrations/breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ const _breadcrumbsIntegration = ((options: Partial<BreadcrumbsOptions> = {}) =>

return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
setup(client) {
if (_options.console) {
addConsoleInstrumentationHandler(_getConsoleBreadcrumbHandler(client));
Expand Down
2 changes: 0 additions & 2 deletions packages/browser/src/integrations/dedupe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ const _dedupeIntegration = (() => {

return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
processEvent(currentEvent) {
// We want to ignore any non-error type events, e.g. transactions or replays
// These should never be deduped, and also not be compared against as _previousEvent.
Expand Down
2 changes: 0 additions & 2 deletions packages/browser/src/integrations/httpcontext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ const INTEGRATION_NAME = 'HttpContext';
const _httpContextIntegration = (() => {
return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
preprocessEvent(event) {
// if none of the information we want exists, don't bother
if (!WINDOW.navigator && !WINDOW.location && !WINDOW.document) {
Expand Down
2 changes: 0 additions & 2 deletions packages/browser/src/integrations/linkederrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ const _linkedErrorsIntegration = ((options: LinkedErrorsOptions = {}) => {

return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
preprocessEvent(event, hint, client) {
const options = client.getOptions();

Expand Down
1 change: 0 additions & 1 deletion packages/browser/src/profiling/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const _browserProfilingIntegration = (() => {
return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
setup(client) {
const scope = getCurrentScope();

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export function setupIntegration(client: Client, integration: Integration, integ
integrationIndex[integration.name] = integration;

// `setupOnce` is only called the first time
if (installedIntegrations.indexOf(integration.name) === -1) {
if (installedIntegrations.indexOf(integration.name) === -1 && typeof integration.setupOnce === 'function') {
// eslint-disable-next-line deprecation/deprecation
integration.setupOnce(addGlobalEventProcessor, getCurrentHub);
installedIntegrations.push(integration.name);
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/integrations/inboundfilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ const INTEGRATION_NAME = 'InboundFilters';
const _inboundFiltersIntegration = ((options: Partial<InboundFiltersOptions> = {}) => {
return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
processEvent(event, _hint, client) {
const clientOptions = client.getOptions();
const mergedOptions = _mergeOptions(options, clientOptions);
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/integrations/linkederrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ const _linkedErrorsIntegration = ((options: LinkedErrorsOptions = {}) => {

return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
preprocessEvent(event, hint, client) {
const options = client.getOptions();

Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/integrations/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ const INTEGRATION_NAME = 'ModuleMetadata';
const _moduleMetadataIntegration = (() => {
return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
setup(client) {
// We need to strip metadata from stack frames before sending them to Sentry since these are client side only.
client.on('beforeEnvelope', envelope => {
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/integrations/requestdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ const _requestDataIntegration = ((options: RequestDataIntegrationOptions = {}) =

return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
processEvent(event, _hint, client) {
// Note: In the long run, most of the logic here should probably move into the request data utility functions. For
// the moment it lives here, though, until https://github.com/getsentry/sentry-javascript/issues/5718 is addressed.
Expand Down
2 changes: 0 additions & 2 deletions packages/deno/src/integrations/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ async function addDenoRuntimeContext(event: Event): Promise<Event> {
const _denoContextIntegration = (() => {
return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
processEvent(event) {
return addDenoRuntimeContext(event);
},
Expand Down
2 changes: 0 additions & 2 deletions packages/deno/src/integrations/contextlines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ const _contextLinesIntegration = ((options: ContextLinesOptions = {}) => {

return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
processEvent(event) {
return addSourceContext(event, contextLines);
},
Expand Down
2 changes: 0 additions & 2 deletions packages/deno/src/integrations/globalhandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ const _globalHandlersIntegration = ((options?: GlobalHandlersIntegrations) => {

return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
setup(client) {
if (_options.error) {
installGlobalErrorHandler(client);
Expand Down
2 changes: 0 additions & 2 deletions packages/deno/src/integrations/normalizepaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ const _normalizePathsIntegration = (() => {

return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
processEvent(event) {
// This error.stack hopefully contains paths that traverse the app cwd
const error = new Error();
Expand Down
2 changes: 0 additions & 2 deletions packages/integrations/src/captureconsole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ const _captureConsoleIntegration = ((options: CaptureConsoleOptions = {}) => {

return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
setup(client) {
if (!('console' in GLOBAL_OBJ)) {
return;
Expand Down
2 changes: 0 additions & 2 deletions packages/integrations/src/contextlines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ const _contextLinesIntegration = ((options: ContextLinesOptions = {}) => {

return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
processEvent(event) {
return addSourceContext(event, contextLines);
},
Expand Down
2 changes: 0 additions & 2 deletions packages/integrations/src/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ const _debugIntegration = ((options: DebugOptions = {}) => {

return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
setup(client) {
client.on('beforeSendEvent', (event: Event, hint?: EventHint) => {
if (_options.debugger) {
Expand Down
2 changes: 0 additions & 2 deletions packages/integrations/src/dedupe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ const _dedupeIntegration = (() => {

return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
processEvent(currentEvent) {
// We want to ignore any non-error type events, e.g. transactions or replays
// These should never be deduped, and also not be compared against as _previousEvent.
Expand Down
2 changes: 0 additions & 2 deletions packages/integrations/src/extraerrordata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ const _extraErrorDataIntegration = ((options: Partial<ExtraErrorDataOptions> = {
const { depth = 3, captureErrorCause = true } = options;
return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
processEvent(event, hint) {
return _enhanceEventWithErrorData(event, hint, depth, captureErrorCause);
},
Expand Down
2 changes: 0 additions & 2 deletions packages/integrations/src/httpclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ const _httpClientIntegration = ((options: Partial<HttpClientOptions> = {}) => {

return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
setup(client): void {
_wrapFetch(client, _options);
_wrapXHR(client, _options);
Expand Down
2 changes: 0 additions & 2 deletions packages/integrations/src/rewriteframes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ const _rewriteFramesIntegration = ((options: RewriteFramesOptions = {}) => {

return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
processEvent(originalEvent) {
let processedEvent = originalEvent;

Expand Down
2 changes: 0 additions & 2 deletions packages/integrations/src/sessiontiming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ const _sessionTimingIntegration = (() => {

return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
processEvent(event) {
const now = Date.now();

Expand Down
34 changes: 17 additions & 17 deletions packages/integrations/test/reportingobserver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('ReportingObserver', () => {
const reportingObserver = reportingObserverIntegration();

expect(() => {
reportingObserver.setupOnce();
reportingObserver.setupOnce!();
}).not.toThrow();

expect(mockReportingObserverConstructor).not.toHaveBeenCalled();
Expand All @@ -59,7 +59,7 @@ describe('ReportingObserver', () => {

it('should use default report types', () => {
const reportingObserver = reportingObserverIntegration();
reportingObserver.setupOnce();
reportingObserver.setupOnce!();
reportingObserver.setup?.(mockClient);

expect(mockReportingObserverConstructor).toHaveBeenCalledTimes(1);
Expand All @@ -71,7 +71,7 @@ describe('ReportingObserver', () => {

it('should use user-provided report types', () => {
const reportingObserver = reportingObserverIntegration({ types: ['crash'] });
reportingObserver.setupOnce();
reportingObserver.setupOnce!();
reportingObserver.setup?.(mockClient);

expect(mockReportingObserverConstructor).toHaveBeenCalledTimes(1);
Expand All @@ -83,7 +83,7 @@ describe('ReportingObserver', () => {

it('should use `buffered` option', () => {
const reportingObserver = reportingObserverIntegration();
reportingObserver.setupOnce();
reportingObserver.setupOnce!();
reportingObserver.setup?.(mockClient);

expect(mockReportingObserverConstructor).toHaveBeenCalledTimes(1);
Expand All @@ -95,7 +95,7 @@ describe('ReportingObserver', () => {

it('should call `observe` function', () => {
const reportingObserver = reportingObserverIntegration();
reportingObserver.setupOnce();
reportingObserver.setupOnce!();
reportingObserver.setup?.(mockClient);

expect(mockObserve).toHaveBeenCalledTimes(1);
Expand All @@ -105,7 +105,7 @@ describe('ReportingObserver', () => {
describe('handler', () => {
it('should abort gracefully and not do anything when integration is not installed', () => {
const reportingObserver = reportingObserverIntegration();
reportingObserver.setupOnce();
reportingObserver.setupOnce!();
// without calling setup, the integration is not registered

const handler = mockReportingObserverConstructor.mock.calls[0][0];
Expand All @@ -119,7 +119,7 @@ describe('ReportingObserver', () => {

it('should capture messages', () => {
const reportingObserver = reportingObserverIntegration();
reportingObserver.setupOnce();
reportingObserver.setupOnce!();
reportingObserver.setup?.(mockClient);
const handler = mockReportingObserverConstructor.mock.calls[0][0];

Expand All @@ -133,7 +133,7 @@ describe('ReportingObserver', () => {

it('should set extra including the url of a report', () => {
const reportingObserver = reportingObserverIntegration();
reportingObserver.setupOnce();
reportingObserver.setupOnce!();
reportingObserver.setup?.(mockClient);
const handler = mockReportingObserverConstructor.mock.calls[0][0];

Expand All @@ -148,7 +148,7 @@ describe('ReportingObserver', () => {

it('should set extra including the report body if available', () => {
const reportingObserver = reportingObserverIntegration();
reportingObserver.setupOnce();
reportingObserver.setupOnce!();
reportingObserver.setup?.(mockClient);
const handler = mockReportingObserverConstructor.mock.calls[0][0];

Expand All @@ -163,7 +163,7 @@ describe('ReportingObserver', () => {

it('should not set extra report body extra when no body is set', () => {
const reportingObserver = reportingObserverIntegration();
reportingObserver.setupOnce();
reportingObserver.setupOnce!();
reportingObserver.setup?.(mockClient);
const handler = mockReportingObserverConstructor.mock.calls[0][0];

Expand All @@ -174,7 +174,7 @@ describe('ReportingObserver', () => {

it('should capture report details from body on crash report', () => {
const reportingObserver = reportingObserverIntegration();
reportingObserver.setupOnce();
reportingObserver.setupOnce!();
reportingObserver.setup?.(mockClient);
const handler = mockReportingObserverConstructor.mock.calls[0][0];

Expand All @@ -192,7 +192,7 @@ describe('ReportingObserver', () => {

it('should capture report message from body on deprecation report', () => {
const reportingObserver = reportingObserverIntegration();
reportingObserver.setupOnce();
reportingObserver.setupOnce!();
reportingObserver.setup?.(mockClient);
const handler = mockReportingObserverConstructor.mock.calls[0][0];

Expand All @@ -209,7 +209,7 @@ describe('ReportingObserver', () => {

it('should capture report message from body on intervention report', () => {
const reportingObserver = reportingObserverIntegration();
reportingObserver.setupOnce();
reportingObserver.setupOnce!();
reportingObserver.setup?.(mockClient);
const handler = mockReportingObserverConstructor.mock.calls[0][0];

Expand All @@ -226,7 +226,7 @@ describe('ReportingObserver', () => {

it('should use fallback message when no body is available', () => {
const reportingObserver = reportingObserverIntegration();
reportingObserver.setupOnce();
reportingObserver.setupOnce!();
reportingObserver.setup?.(mockClient);
const handler = mockReportingObserverConstructor.mock.calls[0][0];

Expand All @@ -242,7 +242,7 @@ describe('ReportingObserver', () => {

it('should use fallback message when no body details are available for crash report', () => {
const reportingObserver = reportingObserverIntegration();
reportingObserver.setupOnce();
reportingObserver.setupOnce!();
reportingObserver.setup?.(mockClient);
const handler = mockReportingObserverConstructor.mock.calls[0][0];

Expand All @@ -255,7 +255,7 @@ describe('ReportingObserver', () => {

it('should use fallback message when no body message is available for deprecation report', () => {
const reportingObserver = reportingObserverIntegration();
reportingObserver.setupOnce();
reportingObserver.setupOnce!();
reportingObserver.setup?.(mockClient);
const handler = mockReportingObserverConstructor.mock.calls[0][0];

Expand All @@ -272,7 +272,7 @@ describe('ReportingObserver', () => {

it('should use fallback message when no body message is available for intervention report', () => {
const reportingObserver = reportingObserverIntegration();
reportingObserver.setupOnce();
reportingObserver.setupOnce!();
reportingObserver.setup?.(mockClient);
const handler = mockReportingObserverConstructor.mock.calls[0][0];

Expand Down
2 changes: 0 additions & 2 deletions packages/node/src/integrations/anr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ const INTEGRATION_NAME = 'Anr';
const _anrIntegration = ((options: Partial<AnrIntegrationOptions> = {}) => {
return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
setup(client: NodeClient) {
if (NODE_VERSION.major < 16 || (NODE_VERSION.major === 16 && NODE_VERSION.minor < 17)) {
throw new Error('ANR detection requires Node 16.17.0 or later');
Expand Down
2 changes: 0 additions & 2 deletions packages/node/src/integrations/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ const INTEGRATION_NAME = 'Console';
const _consoleIntegration = (() => {
return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
setup(client) {
addConsoleInstrumentationHandler(({ args, level }) => {
if (getClient() !== client) {
Expand Down
2 changes: 0 additions & 2 deletions packages/node/src/integrations/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ const _nodeContextIntegration = ((options: ContextOptions = {}) => {

return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
processEvent(event) {
return addContext(event);
},
Expand Down
2 changes: 0 additions & 2 deletions packages/node/src/integrations/contextlines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ const _contextLinesIntegration = ((options: ContextLinesOptions = {}) => {

return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
processEvent(event) {
return addSourceContext(event, contextLines);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@ const _localVariablesAsyncIntegration = ((options: LocalVariablesIntegrationOpti

return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
setup(client: NodeClient) {
const clientOptions = client.getOptions();

Expand Down
Loading