Skip to content

feat(core): emit beforeEnvelope hook #7448

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 5 commits into from
Mar 14, 2023
Merged
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
8 changes: 7 additions & 1 deletion packages/core/src/transports/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
updateRateLimits,
} from '@sentry/utils';

import { getCurrentHub } from '../hub';

export const DEFAULT_TRANSPORT_BUFFER_SIZE = 30;

/**
Expand All @@ -40,14 +42,18 @@ export function createTransport(
),
): Transport {
let rateLimits: RateLimits = {};

const flush = (timeout?: number): PromiseLike<boolean> => buffer.drain(timeout);
const client = getCurrentHub().getClient();

function send(envelope: Envelope): PromiseLike<void | TransportMakeRequestResponse> {
const filteredEnvelopeItems: EnvelopeItem[] = [];

// Drop rate limited items from envelope
forEachEnvelopeItem(envelope, (item, type) => {
if (client && client.emit) {
client.emit('beforeEnvelope', envelope);
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this be called above forEachEnvelopeItem?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah right, idk why I placed it here but yes, it def should be. Do I even need to feature check here btw, can I just client.emit...?

Copy link
Member

Choose a reason for hiding this comment

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

emit may be unavailable when using a custom client, so until v8 we need to guard this, sadly!

}

const envelopeItemDataCategory = envelopeItemTypeToDataCategory(type);
if (isRateLimited(rateLimits, envelopeItemDataCategory)) {
const event: Event | undefined = getEventForEnvelopeItem(item, type);
Expand Down