import { SpanType } from '@mastra/core/observability';
import type { Span, SpanTypeMap, AnySpan, ChildSpanOptions, ChildEventOptions, EndSpanOptions, ErrorSpanOptions, UpdateSpanOptions, CreateSpanOptions, ObservabilityInstance, ExportedSpan, TraceState, IModelSpanTracker, AIModelGenerationSpan, EntityType, TracingPolicy, CorrelationContext } from '@mastra/core/observability';
import type { DeepCleanOptions } from './serialization.js';
/**
 * Get the external parent span ID from CreateSpanOptions.
 *
 * If the parent is internal, walks up the parent chain to find
 * the closest external ancestor. If the parent is already external,
 * returns its ID directly.
 *
 * This is useful when exporting spans to external observability systems
 * that shouldn't include internal framework spans.
 *
 * @param options - Span creation options
 * @returns The external parent span ID, or undefined if no external parent exists
 *
 * @example
 * ```typescript
 * // Parent is external - returns parent.id
 * const externalParent = { id: 'span-123', isInternal: false };
 * const options = { parent: externalParent, ... };
 * getExternalParentId(options); // 'span-123'
 *
 * // Parent is internal - walks up to find external ancestor
 * const externalGrandparent = { id: 'span-456', isInternal: false };
 * const internalParent = { id: 'span-123', isInternal: true, parent: externalGrandparent };
 * const options = { parent: internalParent, ... };
 * getExternalParentId(options); // 'span-456'
 * ```
 */
export declare function getExternalParentId(options: CreateSpanOptions<any>): string | undefined;
export declare abstract class BaseSpan<TType extends SpanType = any> implements Span<TType> {
    abstract id: string;
    abstract traceId: string;
    name: string;
    type: TType;
    attributes: SpanTypeMap[TType];
    parent?: AnySpan;
    startTime: Date;
    endTime?: Date;
    isEvent: boolean;
    isInternal: boolean;
    tracingPolicy?: TracingPolicy;
    observabilityInstance: ObservabilityInstance;
    input?: any;
    output?: any;
    errorInfo?: {
        message: string;
        id?: string;
        name?: string;
        stack?: string;
        domain?: string;
        category?: string;
        details?: Record<string, any>;
    };
    metadata?: Record<string, any>;
    requestContext?: Record<string, any>;
    tags?: string[];
    traceState?: TraceState;
    /** Entity type that created the span (e.g., agent, workflow) */
    entityType?: EntityType;
    /** Entity ID that created the span */
    entityId?: string;
    /** Entity name that created the span */
    entityName?: string;
    /** Parent span ID (for root spans that are children of external spans) */
    protected parentSpanId?: string;
    /** Deep clean options for serialization */
    protected deepCleanOptions: DeepCleanOptions;
    /**
     * Whether this span is filtered out before export. When true, BaseSpan/
     * DefaultSpan skip attaching attributes/input/output/errorInfo/requestContext
     * entirely -- they are never read on excluded spans, and skipping avoids
     * both the deepClean cost and holding references to large payloads for
     * the lifetime of the span. Set when excludeSpanTypes drops the type,
     * when the span is internal and includeInternalSpans is false, or when
     * the subclass is always excluded (e.g., NoOpSpan).
     *
     * Note: metadata is still attached and deepCleaned because it is read in
     * process by getCorrelationContext() and by getLoggerContext() /
     * getMetricsContext() (which structuredClone it).
     */
    protected isExcluded: boolean;
    /** Cached canonical correlation context for this live span */
    protected correlationContext?: CorrelationContext;
    /**
     * Subclasses can override to unconditionally mark the span as excluded.
     * NoOpSpan uses this because it is never exported regardless of config.
     */
    protected get alwaysExcluded(): boolean;
    constructor(options: CreateSpanOptions<TType>, observabilityInstance: ObservabilityInstance);
    /** End the span */
    abstract end(options?: EndSpanOptions<TType>): void;
    /** Record an error for the span, optionally end the span as well */
    abstract error(options: ErrorSpanOptions<TType>): void;
    /** Update span attributes */
    abstract update(options: UpdateSpanOptions<TType>): void;
    createChildSpan(options: ChildSpanOptions<SpanType.MODEL_GENERATION>): AIModelGenerationSpan;
    createEventSpan<TChildType extends SpanType>(options: ChildEventOptions<TChildType>): Span<TChildType>;
    /**
     * Create a ModelSpanTracker for this span (only works if this is a MODEL_GENERATION span)
     * Returns undefined for non-MODEL_GENERATION spans
     */
    createTracker(): IModelSpanTracker | undefined;
    /** Returns `TRUE` if the span is the root span of a trace */
    get isRootSpan(): boolean;
    /** Returns `TRUE` if the span is a valid span (not a NO-OP Span) */
    abstract get isValid(): boolean;
    /** Get the closest parent span, optionally skipping internal spans */
    getParentSpan(includeInternalSpans?: boolean): AnySpan | undefined;
    /** Get the closest parent spanId that isn't an internal span */
    getParentSpanId(includeInternalSpans?: boolean): string | undefined;
    /** Find the closest parent span of a specific type by walking up the parent chain */
    findParent<T extends SpanType>(spanType: T): Span<T> | undefined;
    /** Build and cache the canonical correlation context for this live span. */
    getCorrelationContext(): CorrelationContext;
    /** Returns a lightweight span ready for export */
    exportSpan(includeInternalSpans?: boolean): ExportedSpan<TType>;
    get externalTraceId(): string | undefined;
    /**
     * Execute an async function within this span's tracing context.
     * Delegates to the bridge if available.
     */
    executeInContext<T>(fn: () => Promise<T>): Promise<T>;
    /**
     * Execute a synchronous function within this span's tracing context.
     * Delegates to the bridge if available.
     */
    executeInContextSync<T>(fn: () => T): T;
}
//# sourceMappingURL=base.d.ts.map