autotel
Version:
Write Once, Observe Anywhere
59 lines (58 loc) • 2.22 kB
TypeScript
import { ReadableSpan, Span, SpanProcessor } from "@opentelemetry/sdk-trace-base";
import { Context } from "@opentelemetry/api";
//#region src/filtering-span-processor.d.ts
/**
* Predicate function for filtering spans
*
* @param span - The completed span (ReadableSpan) with all attributes and metadata
* @returns true to keep the span, false to drop it
*
* Available span properties for filtering:
* - `span.name` - Span name
* - `span.attributes` - All span attributes
* - `span.instrumentationScope` - `{ name, version }` of the instrumentation
* - `span.status` - Span status code and message
* - `span.duration` - Span duration as `[seconds, nanoseconds]`
* - `span.kind` - SpanKind (INTERNAL, SERVER, CLIENT, etc.)
*/
type SpanFilterPredicate = (span: ReadableSpan) => boolean;
interface FilteringSpanProcessorOptions {
/**
* Predicate function to determine if a span should be kept
* Return true to keep the span, false to drop it
*/
filter: SpanFilterPredicate;
}
/**
* 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).
*/
declare class FilteringSpanProcessor implements SpanProcessor {
private readonly wrappedProcessor;
private readonly filter;
constructor(wrappedProcessor: SpanProcessor, options: FilteringSpanProcessorOptions);
/**
* Pass through onStart - we need spans to start so child spans work
*/
onStart(span: Span, parentContext: Context): void;
/**
* Apply filter predicate on span end
* If filter returns false, span is dropped (not forwarded)
*/
onEnd(span: ReadableSpan): void;
forceFlush(): Promise<void>;
shutdown(): Promise<void>;
}
//#endregion
export { FilteringSpanProcessorOptions as n, SpanFilterPredicate as r, FilteringSpanProcessor as t };
//# sourceMappingURL=filtering-span-processor-B8R8B7Uk.d.ts.map