|
1 | | -import type { Event, EventType } from '@sentry/core'; |
2 | | -import * as SentryCore from '@sentry/core'; |
3 | | -import * as SentryNode from '@sentry/node'; |
4 | | -import { afterEach, describe, expect, it, vi } from 'vitest'; |
| 1 | +import type { Client, ClientOptions } from '@sentry/core'; |
| 2 | +import { shouldIgnoreSpan } from '@sentry/core'; |
| 3 | +import { describe, expect, it } from 'vitest'; |
5 | 4 | import { lowQualityTransactionsFilterIntegration } from '../../src/server/integration/lowQualityTransactionsFilterIntegration'; |
6 | 5 |
|
7 | | -const debugLoggerLogSpy = vi.spyOn(SentryCore.debug, 'log').mockImplementation(() => {}); |
8 | | - |
9 | | -describe('Low Quality Transactions Filter Integration', () => { |
10 | | - afterEach(() => { |
11 | | - vi.clearAllMocks(); |
12 | | - SentryNode.getGlobalScope().clear(); |
| 6 | +function makeMockClient(initial: Partial<ClientOptions> = {}): Client { |
| 7 | + const options = { ...initial } as ClientOptions; |
| 8 | + return { getOptions: () => options } as Client; |
| 9 | +} |
| 10 | + |
| 11 | +function setupIntegrationAndGetIgnoreSpans(initial: Partial<ClientOptions> = {}) { |
| 12 | + const integration = lowQualityTransactionsFilterIntegration({}); |
| 13 | + const client = makeMockClient(initial); |
| 14 | + integration.beforeSetup!(client); |
| 15 | + return client.getOptions().ignoreSpans!; |
| 16 | +} |
| 17 | + |
| 18 | +describe('lowQualityTransactionsFilterIntegration', () => { |
| 19 | + it('appends the low-quality filters to ignoreSpans', () => { |
| 20 | + expect(setupIntegrationAndGetIgnoreSpans()).toEqual([ |
| 21 | + /GET \/node_modules\//, |
| 22 | + /GET \/favicon\.ico/, |
| 23 | + /GET \/@id\//, |
| 24 | + { attributes: { 'http.target': /\/__manifest/ } }, |
| 25 | + ]); |
13 | 26 | }); |
14 | 27 |
|
15 | | - describe('integration functionality', () => { |
16 | | - describe('filters out low quality transactions', () => { |
17 | | - it.each([ |
18 | | - ['node_modules requests', 'GET /node_modules/some-package/index.js'], |
19 | | - ['favicon.ico requests', 'GET /favicon.ico'], |
20 | | - ['@id/ requests', 'GET /@id/some-id'], |
21 | | - ['manifest requests', 'GET /__manifest?p=%2Fperformance%2Fserver-action'], |
22 | | - ])('%s', (description, transaction) => { |
23 | | - const integration = lowQualityTransactionsFilterIntegration({ debug: true }); |
24 | | - const event = { |
25 | | - type: 'transaction' as EventType, |
26 | | - transaction, |
27 | | - } as Event; |
28 | | - |
29 | | - const result = integration.processEvent!(event, {}, {} as SentryCore.Client); |
30 | | - |
31 | | - expect(result).toBeNull(); |
32 | | - |
33 | | - expect(debugLoggerLogSpy).toHaveBeenCalledWith('[ReactRouter] Filtered node_modules transaction:', transaction); |
34 | | - }); |
35 | | - }); |
36 | | - |
37 | | - describe('allows high quality transactions', () => { |
38 | | - it.each([ |
39 | | - ['normal page requests', 'GET /api/users'], |
40 | | - ['API endpoints', 'POST /data'], |
41 | | - ['app routes', 'GET /projects/123'], |
42 | | - ])('%s', (description, transaction) => { |
43 | | - const integration = lowQualityTransactionsFilterIntegration({}); |
44 | | - const event = { |
45 | | - type: 'transaction' as EventType, |
46 | | - transaction, |
47 | | - } as Event; |
48 | | - |
49 | | - const result = integration.processEvent!(event, {}, {} as SentryCore.Client); |
| 28 | + it('preserves user-provided ignoreSpans entries', () => { |
| 29 | + expect(setupIntegrationAndGetIgnoreSpans({ ignoreSpans: [/keep-me/] })).toEqual([ |
| 30 | + /keep-me/, |
| 31 | + /GET \/node_modules\//, |
| 32 | + /GET \/favicon\.ico/, |
| 33 | + /GET \/@id\//, |
| 34 | + { attributes: { 'http.target': /\/__manifest/ } }, |
| 35 | + ]); |
| 36 | + }); |
50 | 37 |
|
51 | | - expect(result).toEqual(event); |
52 | | - }); |
| 38 | + describe('drops low-quality transactions', () => { |
| 39 | + it.each([ |
| 40 | + ['node_modules requests', { description: 'GET /node_modules/some-package/index.js' }], |
| 41 | + ['favicon.ico requests', { description: 'GET /favicon.ico' }], |
| 42 | + ['@id/ requests', { description: 'GET /@id/some-id' }], |
| 43 | + ['manifest requests', { description: 'GET *', attributes: { 'http.target': '/__manifest?paths=foo' } }], |
| 44 | + ])('%s', (_label, span) => { |
| 45 | + const ignoreSpans = setupIntegrationAndGetIgnoreSpans(); |
| 46 | + expect(shouldIgnoreSpan({ op: 'http.server', ...span }, ignoreSpans)).toBe(true); |
53 | 47 | }); |
| 48 | + }); |
54 | 49 |
|
55 | | - it('does not affect non-transaction events', () => { |
56 | | - const integration = lowQualityTransactionsFilterIntegration({}); |
57 | | - const event = { |
58 | | - type: 'error' as EventType, |
59 | | - transaction: 'GET /node_modules/some-package/index.js', |
60 | | - } as Event; |
61 | | - |
62 | | - const result = integration.processEvent!(event, {}, {} as SentryCore.Client); |
63 | | - |
64 | | - expect(result).toEqual(event); |
| 50 | + describe('keeps high-quality transactions', () => { |
| 51 | + it.each([ |
| 52 | + ['normal page requests', 'GET /api/users'], |
| 53 | + ['API endpoints', 'POST /data'], |
| 54 | + ['app routes', 'GET /projects/123'], |
| 55 | + ])('%s', (_label, name) => { |
| 56 | + const ignoreSpans = setupIntegrationAndGetIgnoreSpans(); |
| 57 | + expect(shouldIgnoreSpan({ description: name, op: 'http.server' }, ignoreSpans)).toBe(false); |
65 | 58 | }); |
66 | 59 | }); |
67 | 60 | }); |
0 commit comments