-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathshould-ignore-span.ts
More file actions
66 lines (56 loc) · 2.11 KB
/
should-ignore-span.ts
File metadata and controls
66 lines (56 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import type { ClientOptions } from '../types-hoist/options';
import type { SpanJSON } from '../types-hoist/span';
import { isMatchingPattern } from './string';
/**
* Check if a span should be ignored based on the ignoreSpans configuration.
*/
export function shouldIgnoreSpan(
span: Pick<SpanJSON, 'description' | 'op'>,
ignoreSpans: Required<ClientOptions>['ignoreSpans'],
): boolean {
if (!ignoreSpans?.length || !span.description) {
return false;
}
for (const pattern of ignoreSpans) {
if (isStringOrRegExp(pattern)) {
if (isMatchingPattern(span.description, pattern)) {
return true;
}
continue;
}
if (!pattern.name && !pattern.op) {
continue;
}
const nameMatches = pattern.name ? isMatchingPattern(span.description, pattern.name) : true;
const opMatches = pattern.op ? span.op && isMatchingPattern(span.op, pattern.op) : true;
// This check here is only correct because we can guarantee that we ran `isMatchingPattern`
// for at least one of `nameMatches` and `opMatches`. So in contrary to how this looks,
// 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) {
return true;
}
}
return false;
}
/**
* Takes a list of spans, and a span that was dropped, and re-parents the child spans of the dropped span to the parent of the dropped span, if possible.
* This mutates the spans array in place!
*/
export function reparentChildSpans(spans: SpanJSON[], dropSpan: SpanJSON): void {
const droppedSpanParentId = dropSpan.parent_span_id;
const droppedSpanId = dropSpan.span_id;
// This should generally not happen, as we do not apply this on root spans
// but to be safe, we just bail in this case
if (!droppedSpanParentId) {
return;
}
for (const span of spans) {
if (span.parent_span_id === droppedSpanId) {
span.parent_span_id = droppedSpanParentId;
}
}
}
function isStringOrRegExp(value: unknown): value is string | RegExp {
return typeof value === 'string' || value instanceof RegExp;
}