autotel
Version:
Write Once, Observe Anywhere
50 lines (49 loc) • 1.34 kB
JavaScript
//#region src/filtering-span-processor.ts
/**
* Span processor that filters spans based on a predicate function.
*
* The filter is applied on onEnd() when the span has complete data including:
* - All attributes
* - Status code and message
* - Duration
* - Events and links
* - Instrumentation scope (useful for filtering by library)
*
* onStart() passes through unchanged to ensure child spans can still be created.
*
* Error handling: If the filter predicate throws, the span is forwarded (fail-open).
*/
var FilteringSpanProcessor = class {
wrappedProcessor;
filter;
constructor(wrappedProcessor, options) {
this.wrappedProcessor = wrappedProcessor;
this.filter = options.filter;
}
/**
* Pass through onStart - we need spans to start so child spans work
*/
onStart(span, parentContext) {
this.wrappedProcessor.onStart(span, parentContext);
}
/**
* Apply filter predicate on span end
* If filter returns false, span is dropped (not forwarded)
*/
onEnd(span) {
try {
if (this.filter(span)) this.wrappedProcessor.onEnd(span);
} catch {
this.wrappedProcessor.onEnd(span);
}
}
forceFlush() {
return this.wrappedProcessor.forceFlush();
}
shutdown() {
return this.wrappedProcessor.shutdown();
}
};
//#endregion
export { FilteringSpanProcessor };
//# sourceMappingURL=filtering-span-processor.js.map