Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add identifiers to event processors that drop events
  • Loading branch information
Luca Forstner committed Apr 13, 2022
commit 105b28df4ed5b2b41fd9920362ff1a90ac39f7db
7 changes: 5 additions & 2 deletions packages/browser/src/integrations/dedupe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class Dedupe implements Integration {
* @inheritDoc
*/
public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
addGlobalEventProcessor((currentEvent: Event) => {
const eventProcessor: EventProcessor = currentEvent => {
const self = getCurrentHub().getIntegration(Dedupe);
if (self) {
// Juuust in case something goes wrong
Expand All @@ -40,7 +40,10 @@ export class Dedupe implements Integration {
return (self._previousEvent = currentEvent);
}
return currentEvent;
});
};

eventProcessor.id = 'DedupeIntegration';
addGlobalEventProcessor(eventProcessor);
}
}

Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/integrations/inboundfilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class InboundFilters implements Integration {
* @inheritDoc
*/
public setupOnce(addGlobalEventProcessor: (processor: EventProcessor) => void, getCurrentHub: () => Hub): void {
addGlobalEventProcessor((event: Event) => {
const eventProcess: EventProcessor = (event: Event) => {
const hub = getCurrentHub();
if (hub) {
const self = hub.getIntegration(InboundFilters);
Expand All @@ -45,7 +45,10 @@ export class InboundFilters implements Integration {
}
}
return event;
});
};

eventProcess.id = 'InboundFiltersIntegration';
addGlobalEventProcessor(eventProcess);
}
}

Expand Down
20 changes: 12 additions & 8 deletions packages/core/test/mocks/integration.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import { getCurrentHub } from '@sentry/hub';
import { configureScope } from '@sentry/minimal';
import { Event, Integration } from '@sentry/types';
import { Event, EventProcessor, Integration } from '@sentry/types';

export class TestIntegration implements Integration {
public static id: string = 'TestIntegration';

public name: string = 'TestIntegration';

public setupOnce(): void {
configureScope(scope => {
scope.addEventProcessor((event: Event) => {
if (!getCurrentHub().getIntegration(TestIntegration)) {
return event;
}
const eventProcessor: EventProcessor = (event: Event) => {
if (!getCurrentHub().getIntegration(TestIntegration)) {
return event;
}

return null;
};

return null;
});
eventProcessor.id = 'TestIntegration';

configureScope(scope => {
scope.addEventProcessor(eventProcessor);
});
}
}
8 changes: 4 additions & 4 deletions packages/hub/src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import {
getGlobalSingleton,
isPlainObject,
isThenable,
SyncPromise,
logger,
SyncPromise,
} from '@sentry/utils';

import { Session } from './session';
import { IS_DEBUG_BUILD } from './flags';
import { Session } from './session';

/**
* Absolute maximum number of breadcrumbs added to an event.
Expand Down Expand Up @@ -467,9 +467,9 @@ export class Scope implements ScopeInterface {
const result = processor({ ...event }, hint) as Event | null;

IS_DEBUG_BUILD &&
processor.identifier &&
processor.id &&
result === null &&
logger.log(`Event processor ${processor.identifier} dropped event.`);
logger.log(`Event processor "${processor.id}" dropped event`);

if (isThenable(result)) {
void result
Expand Down
5 changes: 2 additions & 3 deletions packages/integrations/src/dedupe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class Dedupe implements Integration {
* @inheritDoc
*/
public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
const eventProcessor = (currentEvent: Event): Event | null => {
const eventProcessor: EventProcessor = currentEvent => {
const self = getCurrentHub().getIntegration(Dedupe);
if (self) {
// Juuust in case something goes wrong
Expand All @@ -42,8 +42,7 @@ export class Dedupe implements Integration {
return currentEvent;
};

eventProcessor.identifier = 'dedupe-processor';

eventProcessor.id = 'DedupeIntegration';
addGlobalEventProcessor(eventProcessor);
}
}
Expand Down
9 changes: 7 additions & 2 deletions packages/integrations/src/offline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ export class Offline implements Integration {
});
}

addGlobalEventProcessor((event: Event) => {
const eventProcessor: EventProcessor = event => {
if (this.hub && this.hub.getIntegration(Offline)) {
// cache if we are positively offline
if ('navigator' in this.global && 'onLine' in this.global.navigator && !this.global.navigator.onLine) {
IS_DEBUG_BUILD && logger.log('Event dropped due to being a offline - caching instead');

void this._cacheEvent(event)
.then((_event: Event): Promise<void> => this._enforceMaxEvents())
.catch((_error): void => {
Expand All @@ -96,7 +98,10 @@ export class Offline implements Integration {
}

return event;
});
};

eventProcessor.id = 'OfflineIntegration';
addGlobalEventProcessor(eventProcessor);

// if online now, send any events stored in a previous offline session
if ('navigator' in this.global && 'onLine' in this.global.navigator && this.global.navigator.onLine) {
Expand Down
7 changes: 6 additions & 1 deletion packages/nextjs/src/index.client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { configureScope, init as reactInit, Integrations as BrowserIntegrations } from '@sentry/react';
import { BrowserTracing, defaultRequestInstrumentationOptions } from '@sentry/tracing';
import { EventProcessor } from '@sentry/types';

import { nextRouterInstrumentation } from './performance/client';
import { buildMetadata } from './utils/metadata';
Expand Down Expand Up @@ -42,9 +43,13 @@ export function init(options: NextjsOptions): void {
...options,
integrations,
});

configureScope(scope => {
scope.setTag('runtime', 'browser');
scope.addEventProcessor(event => (event.type === 'transaction' && event.transaction === '/404' ? null : event));
const filterTransactions: EventProcessor = event =>
event.type === 'transaction' && event.transaction === '/404' ? null : event;
filterTransactions.id = 'NextClient404Filter';
scope.addEventProcessor(filterTransactions);
});
}

Expand Down
12 changes: 7 additions & 5 deletions packages/nextjs/src/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Carrier, getHubFromCarrier, getMainCarrier } from '@sentry/hub';
import { RewriteFrames } from '@sentry/integrations';
import { configureScope, getCurrentHub, init as nodeInit, Integrations } from '@sentry/node';
import { hasTracingEnabled } from '@sentry/tracing';
import { Event } from '@sentry/types';
import { Event, EventProcessor } from '@sentry/types';
import { escapeStringForRegex, logger } from '@sentry/utils';
import * as domainModule from 'domain';
import * as path from 'path';
Expand Down Expand Up @@ -71,6 +71,12 @@ export function init(options: NextjsOptions): void {

nodeInit(options);

const filterTransactions: EventProcessor = event => {
return event.type === 'transaction' && event.transaction === '/404' ? null : event;
};

filterTransactions.id = 'NextServer404Filter';

configureScope(scope => {
scope.setTag('runtime', 'node');
if (isVercel) {
Expand Down Expand Up @@ -131,10 +137,6 @@ function addServerIntegrations(options: NextjsOptions): void {
}
}

function filterTransactions(event: Event): Event | null {
return event.type === 'transaction' && event.transaction === '/404' ? null : event;
}

export { withSentryConfig } from './config';
export { SentryWebpackPluginOptions } from './config/types';
export { withSentry } from './utils/withSentry';
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/eventprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import { Event, EventHint } from './event';
* Event processing will be deferred until your Promise is resolved.
*/
export interface EventProcessor {
identifier?: string; // This field can't be named "name" because functions already have this field natively
id?: string; // This field can't be named "name" because functions already have this field natively
(event: Event, hint?: EventHint): PromiseLike<Event | null> | Event | null;
}