import { HrTime } from '@opentelemetry/api'; import type { Span as OTelSpan } from '@opentelemetry/sdk-trace-base'; import { SpanType } from '../constants'; import { SpanEvent } from './span_event'; import { SpanStatus, SpanStatusCode } from './span_status'; /** * MLflow Span interface */ export interface ISpan { /** * The OpenTelemetry span wrapped by MLflow Span */ readonly _span: OTelSpan; /** * The trace ID */ readonly traceId: string; /** * The attributes of the span */ readonly attributes: Record; get spanId(): string; get name(): string; get spanType(): SpanType; get startTime(): HrTime; get endTime(): HrTime | null; get parentId(): string | null; get status(): SpanStatus; get inputs(): any; get outputs(): any; /** * Get an attribute from the span * @param key Attribute key * @returns Attribute value */ getAttribute(key: string): any; /** * Get events from the span */ get events(): SpanEvent[]; /** * Convert this span to JSON format * @returns JSON object representation of the span */ toJson(): SerializedSpan; } /** * MLflow Span class that wraps the OpenTelemetry Span. */ export declare class Span implements ISpan { readonly _span: OTelSpan; readonly _attributesRegistry: SpanAttributesRegistry; allowMutatingEndedSpan: boolean; /** * Create a new MLflowSpan * @param span OpenTelemetry span */ constructor(span: OTelSpan, is_mutable?: boolean); get traceId(): string; get spanId(): string; get spanType(): SpanType; /** * Get the parent span ID */ get parentId(): string | null; get name(): string; get startTime(): HrTime; get endTime(): HrTime | null; get status(): SpanStatus; get inputs(): any; get outputs(): any; get attributes(): Record; getAttribute(key: string): any; get events(): SpanEvent[]; /** * Convert this span to JSON format (OpenTelemetry format) * @returns JSON object representation of the span */ toJson(): SerializedSpan; /** * Create a Span from JSON data (following Python implementation) * Converts the JSON data back into OpenTelemetry-compatible span */ static fromJson(json: SerializedSpan): ISpan; } export declare class LiveSpan extends Span { allowMutatingEndedSpan: boolean; constructor(span: OTelSpan, traceId: string, span_type: SpanType); /** * Set the type of the span * @param spanType The type of the span */ setSpanType(spanType: SpanType): void; /** * Set inputs for the span * @param inputs Input data for the span */ setInputs(inputs: any): void; /** * Set outputs for the span * @param outputs Output data for the span */ setOutputs(outputs: any): void; /** * Set an attribute on the span * @param key Attribute key * @param value Attribute value */ setAttribute(key: string, value: any): void; /** * Set multiple attributes on the span * @param attributes Object containing key-value pairs for attributes */ setAttributes(attributes: Record): void; /** * Add an event to the span * @param event Event object with name and attributes */ addEvent(event: SpanEvent): void; /** * Record an exception event to the span * @param error Error object */ recordException(error: Error): void; /** * Set the status of the span * @param status Status code or SpanStatus object * @param description Optional description for the status */ setStatus(status: SpanStatus | SpanStatusCode | string, description?: string): void; /** * End the span * * @param outputs Optional outputs to set before ending * @param attributes Optional attributes to set before ending * @param status Optional status code * @param endTimeNs Optional end time in nanoseconds */ end(options?: { outputs?: any; attributes?: Record; status?: SpanStatus | SpanStatusCode; endTimeNs?: number; }): void; } /** * A no-operation span implementation that doesn't record anything */ export declare class NoOpSpan implements ISpan { readonly _span: any; readonly _attributesRegistry: SpanAttributesRegistry; allowMutatingEndedSpan: boolean; constructor(span?: any); get traceId(): string; get spanId(): string; get parentId(): string | null; get name(): string; get spanType(): SpanType; get startTime(): HrTime; get endTime(): HrTime | null; get status(): SpanStatus; get inputs(): any; get outputs(): any; get attributes(): Record; getAttribute(_key: string): any; setSpanType(_spanType: SpanType): void; setInputs(_inputs: any): void; setOutputs(_outputs: any): void; setAttribute(_key: string, _value: any): void; setAttributes(_attributes: Record): void; setStatus(_status: SpanStatus | SpanStatusCode | string, _description?: string): void; addEvent(_event: SpanEvent): void; recordException(_error: Error): void; end(_outputs?: any, _attributes?: Record, _status?: SpanStatus | SpanStatusCode, _endTimeNs?: number): void; get events(): SpanEvent[]; toJson(): SerializedSpan; } export interface SerializedSpan { trace_id: string; span_id: string; parent_span_id: string; name: string; start_time_unix_nano: bigint; end_time_unix_nano: bigint | null; status: { code: string; message: string; }; attributes: Record; events: { name: string; time_unix_nano: bigint; attributes: Record; }[]; } /** * A utility class to manage the span attributes. * In MLflow users can add arbitrary key-value pairs to the span attributes, however, * OpenTelemetry only allows a limited set of types to be stored in the attribute values. * Therefore, we serialize all values into JSON string before storing them in the span. * This class provides simple getter and setter methods to interact with the span attributes * without worrying about the serde process. */ declare class SpanAttributesRegistry { private readonly _span; constructor(otelSpan: OTelSpan); /** * Get all attributes as a dictionary */ getAll(): Record; /** * Get a single attribute value */ get(key: string): any; /** * Set a single attribute value */ set(key: string, value: any, allowMutatingEndedSpan?: boolean): void; } /** * Factory function to create a span object. */ export declare function createMlflowSpan(otelSpan: any, traceId: string, spanType?: string): NoOpSpan | Span | LiveSpan; export {};