UNPKG

@arizeai/phoenix-client

Version:
94 lines 3.24 kB
import type { paths } from "../__generated__/api/v1.js"; import type { ClientFn } from "../types/core.js"; import type { ProjectIdentifier } from "../types/projects.js"; type CreateSpansRequestData = paths["/v1/projects/{project_identifier}/spans"]["post"]["requestBody"]["content"]["application/json"]["data"]; /** * A span in Phoenix's simplified span structure, as accepted by {@link logSpans}. * This is the same shape returned by `getSpans`, which makes it possible to read * spans from one project and log them into another. */ export type Span = CreateSpansRequestData[number]; /** Information about a span that failed validation and was not queued. */ export interface InvalidSpanInfo { spanId: string; traceId: string; error: string; } /** Information about a span that was rejected because it already exists. */ export interface DuplicateSpanInfo { spanId: string; traceId: string; } /** * Raised by {@link logSpans} when one or more spans in the request are invalid * or duplicates. If any span in a request fails, none of the spans in that * request are queued. */ export declare class SpanCreationError extends Error { readonly invalidSpans: InvalidSpanInfo[]; readonly duplicateSpans: DuplicateSpanInfo[]; readonly totalReceived: number; readonly totalQueued: number; constructor(params: { message: string; invalidSpans?: InvalidSpanInfo[]; duplicateSpans?: DuplicateSpanInfo[]; totalReceived?: number; totalQueued?: number; }); /** Number of spans rejected as invalid. */ get totalInvalid(): number; /** Number of spans rejected as duplicates. */ get totalDuplicates(): number; } /** * Parameters to log spans to a project */ export interface LogSpansParams extends ClientFn { /** The project to log spans into */ project: ProjectIdentifier; /** The spans to log */ spans: Span[]; } /** * Statistics about a {@link logSpans} call. When successful, `totalQueued` * equals `totalReceived`. */ export interface LogSpansResult { totalReceived: number; totalQueued: number; } /** * Log spans to a project using Phoenix's simplified span structure. * * If any span in the request is invalid or a duplicate of a span that already * exists, none of the spans in the request are queued and a * {@link SpanCreationError} is thrown with details about the failures. * * @experimental this function is experimental and may change in the future * * @param params - The parameters to log spans * @returns Statistics about the operation. When successful, `totalQueued` * equals `totalReceived`. * * @example * ```ts * const result = await logSpans({ * project: { projectName: "my-project" }, * spans: [ * { * name: "test", * context: { trace_id: "123", span_id: "456" }, * span_kind: "CHAIN", * start_time: "2024-01-01T00:00:00Z", * end_time: "2024-01-01T00:00:01Z", * status_code: "OK", * }, * ], * }); * console.log(`Queued ${result.totalQueued} spans`); * ``` */ export declare function logSpans({ client: _client, project, spans, }: LogSpansParams): Promise<LogSpansResult>; export {}; //# sourceMappingURL=logSpans.d.ts.map