import { SpanProcessor, Span, ReadableSpan } from '@opentelemetry/sdk-trace-base';
import { Context } from '@opentelemetry/api';

/**
 * Tail Sampling Span Processor
 *
 * Filters spans based on the `autotel.sampling.tail.keep` attribute set during execution.
 * This enables adaptive sampling where we decide whether to keep a span AFTER
 * the operation completes, based on criteria like errors, duration, etc.
 *
 * How it works:
 * 1. Decorator creates span optimistically (head sampling returns true)
 * 2. Operation executes and completes
 * 3. Decorator calls shouldKeepTrace() and sets autotel.sampling.tail.keep attribute
 * 4. This processor checks the attribute and drops spans marked as false
 */

declare class TailSamplingSpanProcessor implements SpanProcessor {
    private wrappedProcessor;
    constructor(wrappedProcessor: SpanProcessor);
    onStart(span: Span, parentContext: Context): void;
    onEnd(span: ReadableSpan): void;
    forceFlush(): Promise<void>;
    shutdown(): Promise<void>;
}

export { TailSamplingSpanProcessor };
