From b5c87af1a3fd3b8a4e807d2f945b156634081821 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Thu, 18 Sep 2025 10:09:42 +0200 Subject: [PATCH 1/3] ref(core): Add debug log when dropping a span via `ignoreSpans` --- packages/core/src/utils/should-ignore-span.ts | 8 ++++++++ packages/core/src/utils/spanUtils.ts | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/core/src/utils/should-ignore-span.ts b/packages/core/src/utils/should-ignore-span.ts index 53aa109a18dc..a8e27813117e 100644 --- a/packages/core/src/utils/should-ignore-span.ts +++ b/packages/core/src/utils/should-ignore-span.ts @@ -1,7 +1,13 @@ +import { DEBUG_BUILD } from '../debug-build'; import type { ClientOptions } from '../types-hoist/options'; import type { SpanJSON } from '../types-hoist/span'; +import { debug } from './debug-logger'; import { isMatchingPattern } from './string'; +function logIgnoredSpan(droppedSpan: Pick): void { + debug.log(`Ignoring span ${droppedSpan.op} - ${droppedSpan.description}`); +} + /** * Check if a span should be ignored based on the ignoreSpans configuration. */ @@ -16,6 +22,7 @@ export function shouldIgnoreSpan( for (const pattern of ignoreSpans) { if (isStringOrRegExp(pattern)) { if (isMatchingPattern(span.description, pattern)) { + DEBUG_BUILD && logIgnoredSpan(span); return true; } continue; @@ -33,6 +40,7 @@ export function shouldIgnoreSpan( // not both op and name actually have to match. This is the most efficient way to check // for all combinations of name and op patterns. if (nameMatches && opMatches) { + DEBUG_BUILD && logIgnoredSpan(span); return true; } } diff --git a/packages/core/src/utils/spanUtils.ts b/packages/core/src/utils/spanUtils.ts index 89ecc6872efb..6e7c62c7631a 100644 --- a/packages/core/src/utils/spanUtils.ts +++ b/packages/core/src/utils/spanUtils.ts @@ -323,7 +323,7 @@ export function showSpanDropWarning(): void { consoleSandbox(() => { // eslint-disable-next-line no-console console.warn( - '[Sentry] Returning null from `beforeSendSpan` is disallowed. To drop certain spans, configure the respective integrations directly.', + '[Sentry] Returning null from `beforeSendSpan` is disallowed. To drop certain spans, configure the respective integrations directly or use `ignoreSpans`.', ); }); hasShownSpanDropWarning = true; From 99786e9f2333e3b5997d72106101b5a8b6fb6934 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Thu, 18 Sep 2025 10:13:57 +0200 Subject: [PATCH 2/3] tests --- packages/core/test/lib/client.test.ts | 2 +- packages/core/test/lib/tracing/sentrySpan.test.ts | 2 +- .../core/test/lib/utils/should-ignore-span.test.ts | 11 ++++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/core/test/lib/client.test.ts b/packages/core/test/lib/client.test.ts index b903b689fb70..afca376393ee 100644 --- a/packages/core/test/lib/client.test.ts +++ b/packages/core/test/lib/client.test.ts @@ -1445,7 +1445,7 @@ describe('Client', () => { expect(consoleWarnSpy).toHaveBeenCalledTimes(1); expect(consoleWarnSpy).toHaveBeenCalledWith( - '[Sentry] Returning null from `beforeSendSpan` is disallowed. To drop certain spans, configure the respective integrations directly.', + '[Sentry] Returning null from `beforeSendSpan` is disallowed. To drop certain spans, configure the respective integrations directly or use `ignoreSpans`.', ); consoleWarnSpy.mockRestore(); }); diff --git a/packages/core/test/lib/tracing/sentrySpan.test.ts b/packages/core/test/lib/tracing/sentrySpan.test.ts index 601e25be0d23..4b70e1c3ef97 100644 --- a/packages/core/test/lib/tracing/sentrySpan.test.ts +++ b/packages/core/test/lib/tracing/sentrySpan.test.ts @@ -190,7 +190,7 @@ describe('SentrySpan', () => { expect(recordDroppedEventSpy).not.toHaveBeenCalled(); expect(consoleWarnSpy).toHaveBeenCalledWith( - '[Sentry] Returning null from `beforeSendSpan` is disallowed. To drop certain spans, configure the respective integrations directly.', + '[Sentry] Returning null from `beforeSendSpan` is disallowed. To drop certain spans, configure the respective integrations directly or use `ignoreSpans`.', ); consoleWarnSpy.mockRestore(); }); diff --git a/packages/core/test/lib/utils/should-ignore-span.test.ts b/packages/core/test/lib/utils/should-ignore-span.test.ts index 92dc0a1435ee..5062152ebf2c 100644 --- a/packages/core/test/lib/utils/should-ignore-span.test.ts +++ b/packages/core/test/lib/utils/should-ignore-span.test.ts @@ -1,5 +1,6 @@ -import { describe, expect, it } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; import type { ClientOptions, SpanJSON } from '../../../src'; +import { debug } from '../../../src/utils/debug-logger'; import { reparentChildSpans, shouldIgnoreSpan } from '../../../src/utils/should-ignore-span'; describe('shouldIgnoreSpan', () => { @@ -87,6 +88,14 @@ describe('shouldIgnoreSpan', () => { expect(shouldIgnoreSpan(span11, ignoreSpans)).toBe(false); expect(shouldIgnoreSpan(span12, ignoreSpans)).toBe(false); }); + + it('emits a debug log when a span is ignored', () => { + const debugLogSpy = vi.spyOn(debug, 'log'); + const span = { description: 'testDescription', op: 'testOp' }; + const ignoreSpans = [/test/]; + expect(shouldIgnoreSpan(span, ignoreSpans)).toBe(true); + expect(debugLogSpy).toHaveBeenCalledWith('Ignoring span testOp - testDescription'); + }); }); describe('reparentChildSpans', () => { From a47d3911941e6385f50f2b4025c1ba5d6ce23755 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Thu, 18 Sep 2025 10:16:52 +0200 Subject: [PATCH 3/3] reword slightly --- packages/core/src/utils/should-ignore-span.ts | 2 +- packages/core/test/lib/utils/should-ignore-span.test.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/core/src/utils/should-ignore-span.ts b/packages/core/src/utils/should-ignore-span.ts index a8e27813117e..a8d3ac0211c7 100644 --- a/packages/core/src/utils/should-ignore-span.ts +++ b/packages/core/src/utils/should-ignore-span.ts @@ -5,7 +5,7 @@ import { debug } from './debug-logger'; import { isMatchingPattern } from './string'; function logIgnoredSpan(droppedSpan: Pick): void { - debug.log(`Ignoring span ${droppedSpan.op} - ${droppedSpan.description}`); + debug.log(`Ignoring span ${droppedSpan.op} - ${droppedSpan.description} because it matches \`ignoreSpans\`.`); } /** diff --git a/packages/core/test/lib/utils/should-ignore-span.test.ts b/packages/core/test/lib/utils/should-ignore-span.test.ts index 5062152ebf2c..dc03d6e032ea 100644 --- a/packages/core/test/lib/utils/should-ignore-span.test.ts +++ b/packages/core/test/lib/utils/should-ignore-span.test.ts @@ -94,7 +94,9 @@ describe('shouldIgnoreSpan', () => { const span = { description: 'testDescription', op: 'testOp' }; const ignoreSpans = [/test/]; expect(shouldIgnoreSpan(span, ignoreSpans)).toBe(true); - expect(debugLogSpy).toHaveBeenCalledWith('Ignoring span testOp - testDescription'); + expect(debugLogSpy).toHaveBeenCalledWith( + 'Ignoring span testOp - testDescription because it matches `ignoreSpans`.', + ); }); });