From 87bdc775970787ed364271168dc3f6b8aa245e1e Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Wed, 6 Nov 2024 18:00:39 +0200 Subject: [PATCH] Filter out DevServer and DSN related breadcrumbs --- .../core/src/js/integrations/devicecontext.ts | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/core/src/js/integrations/devicecontext.ts b/packages/core/src/js/integrations/devicecontext.ts index 7302e6eeae..02c4b257bd 100644 --- a/packages/core/src/js/integrations/devicecontext.ts +++ b/packages/core/src/js/integrations/devicecontext.ts @@ -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'; @@ -84,9 +85,27 @@ async function processEvent(event: Event): Promise { ? 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; }