Skip to content

Commit cd56c6d

Browse files
committed
move to ignore spans
1 parent d9a94ba commit cd56c6d

2 files changed

Lines changed: 58 additions & 18 deletions

File tree

packages/browser/src/integrations/spotlight.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Client, Envelope, Event, IntegrationFn } from '@sentry/core';
1+
import type { Client, Envelope, IntegrationFn } from '@sentry/core';
22
import { debug, defineIntegration, serializeEnvelope } from '@sentry/core';
33
import { getNativeImplementation } from '@sentry-internal/browser-utils';
44
import { DEBUG_BUILD } from '../debug-build';
@@ -14,6 +14,8 @@ export type SpotlightConnectionOptions = {
1414

1515
export const INTEGRATION_NAME = 'SpotlightBrowser';
1616

17+
export const SPOTLIGHT_IGNORE_SPANS = [{ op: 'ui.interaction.click', name: '#sentry-spotlight' }];
18+
1719
const _spotlightIntegration = ((options: Partial<SpotlightConnectionOptions> = {}) => {
1820
const sidecarUrl = options.sidecarUrl || 'http://localhost:8969/stream';
1921

@@ -22,10 +24,10 @@ const _spotlightIntegration = ((options: Partial<SpotlightConnectionOptions> = {
2224
setup: () => {
2325
DEBUG_BUILD && debug.log('Using Sidecar URL', sidecarUrl);
2426
},
25-
// We don't want to send interaction transactions/root spans created from
26-
// clicks within Spotlight to Sentry. Neither do we want them to be sent to
27-
// spotlight.
28-
processEvent: event => (isSpotlightInteraction(event) ? null : event),
27+
beforeSetup(client: Client) {
28+
const opts = client.getOptions();
29+
opts.ignoreSpans = [...(opts.ignoreSpans || []), ...SPOTLIGHT_IGNORE_SPANS];
30+
},
2931
afterAllSetup: (client: Client) => {
3032
setupSidecarForwarding(client, sidecarUrl);
3133
},
@@ -73,16 +75,3 @@ function setupSidecarForwarding(client: Client, sidecarUrl: string): void {
7375
* Learn more about spotlight at https://spotlightjs.com
7476
*/
7577
export const spotlightBrowserIntegration = defineIntegration(_spotlightIntegration);
76-
77-
/**
78-
* Flags if the event is a transaction created from an interaction with the spotlight UI.
79-
*/
80-
export function isSpotlightInteraction(event: Event): boolean {
81-
return Boolean(
82-
event.type === 'transaction' &&
83-
event.spans &&
84-
event.contexts?.trace &&
85-
event.contexts.trace.op === 'ui.action.click' &&
86-
event.spans.some(({ description }) => description?.includes('#sentry-spotlight')),
87-
);
88-
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import type { Client, ClientOptions } from '@sentry/core';
2+
import { shouldIgnoreSpan } from '@sentry/core';
3+
import { describe, expect, it } from 'vitest';
4+
import { SPOTLIGHT_IGNORE_SPANS, spotlightBrowserIntegration } from '../../src/integrations/spotlight';
5+
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 = spotlightBrowserIntegration();
13+
const client = makeMockClient(initial);
14+
integration.beforeSetup!(client);
15+
return client.getOptions().ignoreSpans!;
16+
}
17+
18+
describe('spotlightBrowserIntegration', () => {
19+
it('appends spotlight interaction filters to ignoreSpans', () => {
20+
expect(setupIntegrationAndGetIgnoreSpans()).toEqual(SPOTLIGHT_IGNORE_SPANS);
21+
});
22+
23+
it('preserves user-provided ignoreSpans entries', () => {
24+
expect(setupIntegrationAndGetIgnoreSpans({ ignoreSpans: [/keep-me/] })).toEqual([
25+
/keep-me/,
26+
...SPOTLIGHT_IGNORE_SPANS,
27+
]);
28+
});
29+
30+
describe('drops spotlight interaction spans', () => {
31+
it.each([
32+
['click on spotlight overlay', 'body > div#sentry-spotlight > div.overlay'],
33+
['click on spotlight button', 'body > div > div#sentry-spotlight > button.close'],
34+
['click on nested spotlight element', 'html > body > aside#sentry-spotlight'],
35+
])('%s', (_label, name) => {
36+
const ignoreSpans = setupIntegrationAndGetIgnoreSpans();
37+
expect(shouldIgnoreSpan({ description: name, op: 'ui.interaction.click' }, ignoreSpans)).toBe(true);
38+
});
39+
});
40+
41+
describe('keeps non-spotlight interaction spans', () => {
42+
it.each([
43+
['regular click', 'body > div.main > button.submit', 'ui.interaction.click'],
44+
['regular ui action', '/dashboard', 'ui.action.click'],
45+
['non-interaction span', 'GET /api/data', 'http.client'],
46+
])('%s', (_label, name, op) => {
47+
const ignoreSpans = setupIntegrationAndGetIgnoreSpans();
48+
expect(shouldIgnoreSpan({ description: name, op }, ignoreSpans)).toBe(false);
49+
});
50+
});
51+
});

0 commit comments

Comments
 (0)