|
1 | 1 | import type { ClientOptions } from '../types-hoist/options';
|
2 | 2 | import type { SpanJSON } from '../types-hoist/span';
|
3 |
| -import { isMatchingPattern, stringMatchesSomePattern } from './string'; |
| 3 | +import { isMatchingPattern } from './string'; |
4 | 4 |
|
5 | 5 | /**
|
6 | 6 | * Check if a span should be ignored based on the ignoreSpans configuration.
|
7 | 7 | */
|
8 | 8 | export function shouldIgnoreSpan(
|
9 | 9 | span: Pick<SpanJSON, 'description' | 'op'>,
|
10 |
| - ignoreSpans: ClientOptions['ignoreSpans'], |
| 10 | + ignoreSpans: Required<ClientOptions>['ignoreSpans'], |
11 | 11 | ): boolean {
|
12 |
| - if (!ignoreSpans?.length) { |
| 12 | + if (!ignoreSpans?.length || !span.description) { |
13 | 13 | return false;
|
14 | 14 | }
|
15 | 15 |
|
16 |
| - if (!span.description) { |
17 |
| - return false; |
18 |
| - } |
19 |
| - |
20 |
| - // First we check the simple string/regex patterns - if the name matches any of them, we ignore the span |
21 |
| - const simplePatterns = ignoreSpans.filter(isStringOrRegExp); |
22 |
| - if (simplePatterns.length && stringMatchesSomePattern(span.description, simplePatterns)) { |
23 |
| - return true; |
24 |
| - } |
25 |
| - |
26 |
| - // Then we check the more complex patterns, where both parts must match |
27 | 16 | for (const pattern of ignoreSpans) {
|
28 |
| - // Have already checked for simple patterns, so we can skip these |
29 |
| - if (isStringOrRegExp(pattern) || (!pattern.name && !pattern.op)) { |
| 17 | + if (isStringOrRegExp(pattern)) { |
| 18 | + if (isMatchingPattern(span.description, pattern)) { |
| 19 | + return true; |
| 20 | + } |
| 21 | + continue; |
| 22 | + } |
| 23 | + |
| 24 | + if (!pattern.name && !pattern.op) { |
30 | 25 | continue;
|
31 | 26 | }
|
32 | 27 |
|
33 | 28 | const nameMatches = pattern.name ? isMatchingPattern(span.description, pattern.name) : true;
|
34 | 29 | const opMatches = pattern.op ? span.op && isMatchingPattern(span.op, pattern.op) : true;
|
35 | 30 |
|
| 31 | + // This check here is only correct because we can guarantee that we ran `isMatchingPattern` |
| 32 | + // for at least one of `nameMatches` and `opMatches`. So in contrary to how this looks, |
| 33 | + // not both op and name actually have to match. This is the most efficient way to check |
| 34 | + // for all combinations of name and op patterns. |
36 | 35 | if (nameMatches && opMatches) {
|
37 | 36 | return true;
|
38 | 37 | }
|
|
0 commit comments