Skip to content

Commit

Permalink
Filter out DevServer and DSN related breadcrumbs
Browse files Browse the repository at this point in the history
  • Loading branch information
antonis committed Nov 6, 2024
1 parent f828fc7 commit 87bdc77
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions packages/core/src/js/integrations/devicecontext.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable complexity */
import { getClient } from '@sentry/core';
import type { Event, Integration } from '@sentry/types';
import type { Breadcrumb, Event, Integration } from '@sentry/types';
import { logger, severityLevelFromString } from '@sentry/utils';
import { AppState } from 'react-native';

import { breadcrumbFromObject } from '../breadcrumb';
import type { NativeDeviceContextsResponse } from '../NativeRNSentry';
import { NATIVE } from '../wrapper';
import { getDevServer } from './debugsymbolicatorutils';

const INTEGRATION_NAME = 'DeviceContext';

Expand Down Expand Up @@ -84,9 +85,27 @@ async function processEvent(event: Event): Promise<Event> {
? native['breadcrumbs'].map(breadcrumbFromObject)
: undefined;
if (nativeBreadcrumbs) {
const maxBreadcrumbs = getClient()?.getOptions().maxBreadcrumbs ?? 100; // Default is 100.
event.breadcrumbs = nativeBreadcrumbs.concat(event.breadcrumbs || []).slice(0, maxBreadcrumbs);
// Concatenate nativeBreadcrumbs first, then event.breadcrumbs
event.breadcrumbs = nativeBreadcrumbs.concat(event.breadcrumbs || []);
}

const options = getClient()?.getOptions();
const maxBreadcrumbs = options.maxBreadcrumbs ?? 100; // Default is 100.
const devServerUrl = getDevServer()?.url || '';
const dsn = options.dsn || '';

let allBreadcrumbs = event.breadcrumbs || [];

// Filter out Dev Server and Sentry DSN request breadcrumbs
allBreadcrumbs = allBreadcrumbs.filter((breadcrumb: Breadcrumb) => {
const type = breadcrumb.type || '';
const url = breadcrumb.data?.url || '';
return !(type === 'http' && (url.includes(devServerUrl) || url.includes(dsn)));
});

// Ensure the maxBreadcrumbs limit is not exceeded after merging event and native breadcrumbs
// and filtering out Dev Server and Sentry DSN request breadcrumbs
event.breadcrumbs = allBreadcrumbs.slice(0, maxBreadcrumbs);

return event;
}

0 comments on commit 87bdc77

Please sign in to comment.