@zendesk/retrace
Version:
define and capture Product Operation Traces along with computed metrics with an optional friendly React beacon API
37 lines • 1.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.findAncestor = findAncestor;
const ensureMatcherFn_1 = require("./ensureMatcherFn");
/**
* Finds the first span matching the provided SpanMatch in the parent hierarchy
* of the given Span, starting with the span itself and traversing up
* through its parents.
*/
function findAncestor(span,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
spanMatch, traceContext) {
// Convert SpanMatch to a matcher function if needed
const matcherFn = (0, ensureMatcherFn_1.ensureMatcherFn)(spanMatch);
// Start with the current span
let currentSpanAndAnnotation = traceContext?.recordedItems.get(span.id) ?? {
span,
};
while (currentSpanAndAnnotation) {
// Check if current span matches
if (matcherFn(currentSpanAndAnnotation, traceContext)) {
return currentSpanAndAnnotation.span;
}
const parentSpan = currentSpanAndAnnotation.span.getParentSpan({
traceContext,
thisSpanAndAnnotation: currentSpanAndAnnotation,
}, true);
// If no parent span ID, we've reached the top of the known hierarchy
if (!parentSpan) {
break;
}
// Get the parent span
currentSpanAndAnnotation = traceContext?.recordedItems.get(parentSpan.id) ?? { span: parentSpan };
}
return undefined;
}
//# sourceMappingURL=findSpanInParentHierarchy.js.map