-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(core): Add ignoreSpans
option
#17078
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} | ||
Lms24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Span Ignoring Fails for Empty OperationsThe Locations (1) |
||
|
||
// 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; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.