Skip to content
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: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export { functionToStringIntegration } from './integrations/functiontostring';
export { inboundFiltersIntegration } from './integrations/eventFilters';
export { eventFiltersIntegration } from './integrations/eventFilters';
export { linkedErrorsIntegration } from './integrations/linkederrors';
export { moduleMetadataIntegration } from './integrations/metadata';
export { moduleMetadataIntegration } from './integrations/moduleMetadata';
export { requestDataIntegration } from './integrations/requestdata';
export { captureConsoleIntegration } from './integrations/captureconsole';
export { dedupeIntegration } from './integrations/dedupe';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export const thirdPartyErrorFilterIntegration = defineIntegration((options: Opti
name: 'ThirdPartyErrorsFilter',
setup(client) {
// We need to strip metadata from stack frames before sending them to Sentry since these are client side only.
// TODO(lforst): Move this cleanup logic into a more central place in the SDK.
Copy link
Member Author

Choose a reason for hiding this comment

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

I decided to remove this TODO because for now, we only call this cleanup in the two optional integrations. So moving this to client would allow us to get rid of the double-hook registration but at the same time penalize the core bundle size for something users likely don't use. We can revisit and extract it once this logic is used in a default integration but I don't think there's much benefit in doing it now.

client.on('beforeEnvelope', envelope => {
forEachEnvelopeItem(envelope, (item, type) => {
if (type === 'event') {
Expand Down
40 changes: 11 additions & 29 deletions packages/core/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,46 +53,28 @@ export function getMetadataForUrl(parser: StackParser, filename: string): any |
* Metadata is injected by the Sentry bundler plugins using the `_experiments.moduleMetadata` config option.
*/
export function addMetadataToStackFrames(parser: StackParser, event: Event): void {
try {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
event.exception!.values!.forEach(exception => {
if (!exception.stacktrace) {
event.exception?.values?.forEach(exception => {
exception.stacktrace?.frames?.forEach(frame => {
if (!frame.filename || frame.module_metadata) {
return;
}

for (const frame of exception.stacktrace.frames || []) {
if (!frame.filename || frame.module_metadata) {
continue;
}
const metadata = getMetadataForUrl(parser, frame.filename);

const metadata = getMetadataForUrl(parser, frame.filename);

if (metadata) {
frame.module_metadata = metadata;
}
if (metadata) {
frame.module_metadata = metadata;
}
});
} catch {
// To save bundle size we're just try catching here instead of checking for the existence of all the different objects.
}
});
}

/**
* Strips metadata from stack frames.
*/
export function stripMetadataFromStackFrames(event: Event): void {
try {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
event.exception!.values!.forEach(exception => {
if (!exception.stacktrace) {
return;
}

for (const frame of exception.stacktrace.frames || []) {
delete frame.module_metadata;
}
event.exception?.values?.forEach(exception => {
exception.stacktrace?.frames?.forEach(frame => {
delete frame.module_metadata;
});
} catch {
// To save bundle size we're just try catching here instead of checking for the existence of all the different objects.
}
});
}