Skip to content

Commit 5a1faed

Browse files
authored
ref(core): Add debug log when dropping a span via ignoreSpans (#17692)
- Emit a debug log when a span matches `ignoreSpans` - Adjust the warning when returning `null` in `beforeSendSpan` to suggest `ignoreSpans` instead closes #17687
1 parent 2cde2a4 commit 5a1faed

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

packages/core/src/utils/should-ignore-span.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
import { DEBUG_BUILD } from '../debug-build';
12
import type { ClientOptions } from '../types-hoist/options';
23
import type { SpanJSON } from '../types-hoist/span';
4+
import { debug } from './debug-logger';
35
import { isMatchingPattern } from './string';
46

7+
function logIgnoredSpan(droppedSpan: Pick<SpanJSON, 'description' | 'op'>): void {
8+
debug.log(`Ignoring span ${droppedSpan.op} - ${droppedSpan.description} because it matches \`ignoreSpans\`.`);
9+
}
10+
511
/**
612
* Check if a span should be ignored based on the ignoreSpans configuration.
713
*/
@@ -16,6 +22,7 @@ export function shouldIgnoreSpan(
1622
for (const pattern of ignoreSpans) {
1723
if (isStringOrRegExp(pattern)) {
1824
if (isMatchingPattern(span.description, pattern)) {
25+
DEBUG_BUILD && logIgnoredSpan(span);
1926
return true;
2027
}
2128
continue;
@@ -33,6 +40,7 @@ export function shouldIgnoreSpan(
3340
// not both op and name actually have to match. This is the most efficient way to check
3441
// for all combinations of name and op patterns.
3542
if (nameMatches && opMatches) {
43+
DEBUG_BUILD && logIgnoredSpan(span);
3644
return true;
3745
}
3846
}

packages/core/src/utils/spanUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ export function showSpanDropWarning(): void {
323323
consoleSandbox(() => {
324324
// eslint-disable-next-line no-console
325325
console.warn(
326-
'[Sentry] Returning null from `beforeSendSpan` is disallowed. To drop certain spans, configure the respective integrations directly.',
326+
'[Sentry] Returning null from `beforeSendSpan` is disallowed. To drop certain spans, configure the respective integrations directly or use `ignoreSpans`.',
327327
);
328328
});
329329
hasShownSpanDropWarning = true;

packages/core/test/lib/client.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,7 @@ describe('Client', () => {
14451445

14461446
expect(consoleWarnSpy).toHaveBeenCalledTimes(1);
14471447
expect(consoleWarnSpy).toHaveBeenCalledWith(
1448-
'[Sentry] Returning null from `beforeSendSpan` is disallowed. To drop certain spans, configure the respective integrations directly.',
1448+
'[Sentry] Returning null from `beforeSendSpan` is disallowed. To drop certain spans, configure the respective integrations directly or use `ignoreSpans`.',
14491449
);
14501450
consoleWarnSpy.mockRestore();
14511451
});

packages/core/test/lib/tracing/sentrySpan.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ describe('SentrySpan', () => {
190190
expect(recordDroppedEventSpy).not.toHaveBeenCalled();
191191

192192
expect(consoleWarnSpy).toHaveBeenCalledWith(
193-
'[Sentry] Returning null from `beforeSendSpan` is disallowed. To drop certain spans, configure the respective integrations directly.',
193+
'[Sentry] Returning null from `beforeSendSpan` is disallowed. To drop certain spans, configure the respective integrations directly or use `ignoreSpans`.',
194194
);
195195
consoleWarnSpy.mockRestore();
196196
});

packages/core/test/lib/utils/should-ignore-span.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { describe, expect, it } from 'vitest';
1+
import { describe, expect, it, vi } from 'vitest';
22
import type { ClientOptions, SpanJSON } from '../../../src';
3+
import { debug } from '../../../src/utils/debug-logger';
34
import { reparentChildSpans, shouldIgnoreSpan } from '../../../src/utils/should-ignore-span';
45

56
describe('shouldIgnoreSpan', () => {
@@ -87,6 +88,16 @@ describe('shouldIgnoreSpan', () => {
8788
expect(shouldIgnoreSpan(span11, ignoreSpans)).toBe(false);
8889
expect(shouldIgnoreSpan(span12, ignoreSpans)).toBe(false);
8990
});
91+
92+
it('emits a debug log when a span is ignored', () => {
93+
const debugLogSpy = vi.spyOn(debug, 'log');
94+
const span = { description: 'testDescription', op: 'testOp' };
95+
const ignoreSpans = [/test/];
96+
expect(shouldIgnoreSpan(span, ignoreSpans)).toBe(true);
97+
expect(debugLogSpy).toHaveBeenCalledWith(
98+
'Ignoring span testOp - testDescription because it matches `ignoreSpans`.',
99+
);
100+
});
90101
});
91102

92103
describe('reparentChildSpans', () => {

0 commit comments

Comments
 (0)