Skip to content

Commit bad6070

Browse files
committed
ref(core): Avoid parsing before send processor name
1 parent ae00784 commit bad6070

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

packages/core/src/baseclient.ts

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
631631

632632
const isTransaction = event.type === 'transaction';
633633
const isError = !event.type;
634-
635-
const beforeSendProcessorName = getBeforeSendMethodName(event);
634+
const eventType = event.type || 'error';
636635

637636
// 1.0 === 100% events are sent
638637
// 0.0 === 0% events are sent
@@ -650,7 +649,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
650649
return this._prepareEvent(event, hint, scope)
651650
.then(prepared => {
652651
if (prepared === null) {
653-
this.recordDroppedEvent('event_processor', event.type || 'error', event);
652+
this.recordDroppedEvent('event_processor', eventType, event);
654653
throw new SentryError('An event processor returned `null`, will not send event.', 'log');
655654
}
656655

@@ -659,13 +658,13 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
659658
return prepared;
660659
}
661660

662-
const beforeSendResult = processBeforeSend(options, prepared, hint);
663-
return _validateBeforeSendResult(beforeSendResult, beforeSendProcessorName);
661+
const result = processBeforeSend(options, prepared, hint);
662+
return _validateBeforeSendResult(result, eventType);
664663
})
665664
.then(processedEvent => {
666665
if (processedEvent === null) {
667666
this.recordDroppedEvent('before_send', event.type || 'error', event);
668-
throw new SentryError(`\`${beforeSendProcessorName}\` returned \`null\`, will not send event.`, 'log');
667+
throw new SentryError(`before send for type \`${eventType}\` returned \`null\`, will not send event.`, 'log');
669668
}
670669

671670
const session = scope && scope.getSession();
@@ -782,9 +781,9 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
782781
*/
783782
function _validateBeforeSendResult(
784783
beforeSendResult: PromiseLike<Event | null> | Event | null,
785-
beforeSendProcessorName: string,
784+
eventType: string,
786785
): PromiseLike<Event | null> | Event | null {
787-
const invalidValueError = `\`${beforeSendProcessorName}\` must return \`null\` or a valid event.`;
786+
const invalidValueError = `before send for type \`${eventType}\` must return \`null\` or a valid event.`;
788787
if (isThenable(beforeSendResult)) {
789788
return beforeSendResult.then(
790789
event => {
@@ -794,7 +793,7 @@ function _validateBeforeSendResult(
794793
return event;
795794
},
796795
e => {
797-
throw new SentryError(`\`${beforeSendProcessorName}\` rejected with ${e}`);
796+
throw new SentryError(`before send for type \`${eventType}\` rejected with ${e}`);
798797
},
799798
);
800799
} else if (!isPlainObject(beforeSendResult) && beforeSendResult !== null) {
@@ -824,20 +823,6 @@ function processBeforeSend<T extends Event>(
824823
return event;
825824
}
826825

827-
/** Get the name of the before send processor for logging purposes. */
828-
function getBeforeSendMethodName<T extends Event>(event: T): string {
829-
if (isErrorEvent(event)) {
830-
return 'beforeSend';
831-
}
832-
833-
if (isTransactionEvent(event)) {
834-
return 'beforeSendTransaction';
835-
}
836-
837-
// This shouldn't happen, but if it does, we need to return a string
838-
return 'unknown';
839-
}
840-
841826
function isErrorEvent(event: Event): event is ErrorEvent {
842827
return event.type === undefined;
843828
}

0 commit comments

Comments
 (0)