import { TraceInfo } from '../core/entities/trace_info'; import { Trace } from '../core/entities/trace'; import { TraceData } from '../core/entities/trace_data'; import { AuthProvider } from '../auth'; import { type TraceLocation } from '../core/entities/trace_location'; import type { ReadableSpan as OTelReadableSpan } from '@opentelemetry/sdk-trace-base'; export interface SearchTracesOptions { /** Trace locations (e.g. MLflow experiments) to search over. */ locations: TraceLocation[]; /** Search filter string, e.g. `"tags.env = 'prod'"`. */ filter?: string; /** Maximum number of traces to return in a single page. */ maxResults?: number; /** List of order-by clauses, e.g. `['timestamp_ms DESC']`. */ orderBy?: string[]; /** Pagination token obtained from a previous searchTraces call. */ pageToken?: string; /** * Whether to fetch span data for each matching trace. Defaults to `true`. * When `false`, only trace metadata is returned and the traces have empty * span data. */ includeSpans?: boolean; } export interface SearchTracesResult { traces: Trace[]; nextPageToken?: string; } /** * Client for MLflow tracing operations. * * Supports multiple authentication methods: * - Databricks: PAT tokens, OAuth M2M, Azure CLI/MSI, Google Cloud * - OSS MLflow: Basic auth, Bearer tokens, or no auth */ export declare class MlflowClient { /** Client implementation to upload/download trace data artifacts */ private artifactsClient; /** Headers provider for authenticated requests */ private headersProvider; /** Host URL for API requests */ private hostUrl; /** * Creates a new MlflowClient. * * @param trackingUri - The tracking URI (e.g., "databricks", "http://localhost:5000") * @param authProvider - The authentication provider to get tokens for authenticated requests */ constructor(options: { trackingUri: string; authProvider: AuthProvider; }); /** * Get the host URL for this client. */ getHost(): string; /** * Create a new TraceInfo record in the backend store. * Corresponding to the Python SDK's start_trace_v3() method. * * Note: the backend API is named as "Start" due to unfortunate miscommunication. * The API is indeed called at the "end" of a trace, not the "start". */ createTrace(traceInfo: TraceInfo): Promise; /** * Create a new TraceInfo record in the Databricks V4 (Unity Catalog) * trace-info endpoint. Used for UC-backed traces so that trace-level * tags and metadata persist alongside spans uploaded via OTLP. * * Corresponds to Python's `DatabricksRestStore._start_trace_v4`. * * @param location - The UC location string ("catalog.schema" or * "catalog.schema.table_prefix") that comes from * the trace ID `trace://`. * @param otelTraceId - The hex OTel trace ID portion. * @param traceInfo - The full TraceInfo to persist; the backend reads * `tags`, `trace_metadata`, `state`, durations, etc. */ createTraceInfoV4(location: string, otelTraceId: string, traceInfo: TraceInfo): Promise; /** * Upload OTel spans to a Databricks Unity Catalog location via the OTLP * HTTP+protobuf endpoint. The `spansTableName` is the fully qualified * spans table (catalog.schema.table) and is forwarded as the * `X-Databricks-UC-Table-Name` header used by Databricks to route the * payload to the correct UC location. * * Uses `@opentelemetry/exporter-trace-otlp-proto` which serializes the * spans to the OTLP `ExportTraceServiceRequest` protobuf wire format — * the Databricks endpoint only accepts `application/x-protobuf`, not * the OTLP/HTTP+JSON form. */ exportOtlpSpansToUc(spans: OTelReadableSpan[], spansTableName: string): Promise; /** * Export OTLP spans to an OSS (non-Databricks) tracking server. * * `otlpProtoBytes` is an already-serialized OTLP `ExportTraceServiceRequest` * protobuf (captured at WAL-write time), POSTed as `application/x-protobuf` * with the experiment id forwarded via the `x-mlflow-experiment-id` header. */ exportOtlpSpans(experimentId: string, otlpProtoBytes: Uint8Array): Promise; /** * Get a single trace by ID * Fetches both trace info and trace data from backend * Corresponds to Python: client.get_trace() */ getTrace(traceId: string): Promise; /** * Get trace info using V3 API * Endpoint: GET /api/3.0/mlflow/traces/{trace_id} */ getTraceInfo(traceId: string): Promise; /** * Search for traces that match the given search criteria. * Corresponding to the Python SDK's search_traces() method. * * By default the span data of each matching trace is fetched with one * download per trace; traces whose span data cannot be downloaded are * skipped, matching the Python SDK's behavior. Pass `includeSpans: false` * to return trace metadata only, with empty span data. * * Locations are passed through to the tracking server, which validates * that it supports the requested location types. * * @param options.locations Trace locations (e.g. MLflow experiments) to search over. * @param options.filter Search filter string, e.g. `"tags.env = 'prod'"`. * @param options.maxResults Maximum number of traces to return in a single page. * @param options.orderBy List of order-by clauses, e.g. `['timestamp_ms DESC']`. * @param options.pageToken Pagination token obtained from a previous searchTraces call. * @param options.includeSpans Whether to fetch span data for each trace. Defaults to `true`. * @returns The matching traces and, when more results are available, a token for the next page. * * @example * ```typescript * const { traces, nextPageToken } = await client.searchTraces({ * locations: [ * { type: TraceLocationType.MLFLOW_EXPERIMENT, mlflowExperiment: { experimentId: '123' } }, * ], * filter: "tags.env = 'prod'", * maxResults: 10, * orderBy: ['timestamp_ms DESC'], * }); * ``` */ searchTraces(options: SearchTracesOptions): Promise; /** * Fetch span data for a search result. Returns undefined when the data * cannot be downloaded (e.g. missing or corrupted) so the trace is dropped * from the results with a warning, matching the Python SDK. */ private downloadTraceDataForSearch; /** * Upload trace data to the artifact store. */ uploadTraceData(traceInfo: TraceInfo, traceData: TraceData): Promise; /** * Create a new experiment */ createExperiment(name: string, artifactLocation?: string, tags?: Record): Promise; /** * Get an experiment by ID, including its tags. Used to auto-resolve UC * trace destinations from a Databricks-linked experiment. */ getExperiment(experimentId: string): Promise<{ experimentId: string; name: string; tags: Record; } | null>; /** * Get an experiment by name. */ getExperimentByName(name: string): Promise<{ experimentId: string; name: string; } | null>; /** * Delete an experiment */ deleteExperiment(experimentId: string): Promise; }