import type { TracingChannel, TracingChannelSubscribers } from 'node:diagnostics_channel';
import type { ExclusiveEventHintOrCaptureContext, Span } from '@sentry/core';
export type TracingChannelPayloadWithSpan<TData extends object> = TData & {
    _sentrySpan?: Span;
};
export interface SentryTracingChannel<TData extends object = object> extends Omit<TracingChannel<TData, TracingChannelPayloadWithSpan<TData>>, 'subscribe' | 'unsubscribe'> {
    subscribe(subscribers: Partial<TracingChannelSubscribers<TracingChannelPayloadWithSpan<TData>>>): void;
    unsubscribe(subscribers: Partial<TracingChannelSubscribers<TracingChannelPayloadWithSpan<TData>>>): void;
}
export interface TracingChannelLifeCycleOptions<TData extends object = object> {
    /**
     * Invoked with the span and the channel context object once the traced operation completes
     * Use it to enrich the span from the result/error (branch on `'error' in data` / `'result' in data`) or to run cleanup.
     */
    beforeSpanEnd?: (span: Span, data: TracingChannelPayloadWithSpan<TData>) => void;
    /**
     * Whether a thrown error is captured as a Sentry event. The span is always marked with error status regardless. Defaults to `false`.
     * You can alternatively pass a function that sets the ExclusiveEventHintOrCaptureContext on the captured error.
     * Set `true` for instrumentations that own the error boundary, (e.g: route handlers)
     * For database drivers, it is not recommended to set this at all.
     */
    captureError?: boolean | ((e: unknown) => ExclusiveEventHintOrCaptureContext);
}
/** Returned by {@link bindTracingChannelToSpan}: the bound channel plus a teardown handle. */
export interface TracingChannelBindingHandle<TData extends object = object> {
    /**
     * The tracing channel with the span bound into async context.
     */
    channel: SentryTracingChannel<TData>;
    /**
     * Tears down the binding: unsubscribes lifecycle handlers, when present, and unbinds the start store.
     * Idempotent, and a no-op when no async context binding was available.
     */
    unbind: () => void;
}
/**
 * Bind a span and its lifecycle to a tracing channel so the span becomes the active async context
 * for the traced operation and is ended when the operation completes.
 *
 * `getSpan` may return `undefined` to opt a payload out entirely: nothing is bound, no span is
 * tracked, and the active context is left untouched. Use it for events that ride the same channel
 * but should reuse the enclosing span instead of opening (and ending) their own — e.g. an agent
 * loop's per-step events, where ending a freshly opened span would close the parent prematurely.
 */
export declare function bindTracingChannelToSpan<TData extends object>(channel: TracingChannel<TData, TData>, getSpan: (data: TracingChannelPayloadWithSpan<TData>) => Span | undefined, opts?: TracingChannelLifeCycleOptions<TData>): TracingChannelBindingHandle<TData>;
//# sourceMappingURL=tracing-channel.d.ts.map