import type { Run, TraceExporter } from '../types/tracing.js'; /** Options for `OtlpTraceExporter`. */ export interface OtlpTraceExporterOptions { /** * The collector's OTLP/HTTP base URL, such as `http://localhost:4318`. Spans are posted to * `/v1/traces` under it. */ endpoint: string; /** * How spans are encoded: `http/json`, the default, or `http/protobuf`, OTLP's binary encoding, * smaller and faster for a collector to read. For OTLP over gRPC, use `OtlpGrpcTraceExporter` * from `nexus-ai-pro/tracing/otlp-grpc`. */ protocol?: 'http/json' | 'http/protobuf'; /** Headers on every request, such as an API key a hosted backend wants. */ headers?: Record; /** `service.name` on every span. Defaults to `nexus-ai-pro`. */ serviceName?: string; /** More resource attributes, such as `deployment.environment.name` or `service.version`. */ resource?: Record; /** Spans sent per request. Defaults to 100. */ maxBatch?: number; /** How long a span waits for others to batch with, in milliseconds. Defaults to 2,000. */ flushIntervalMs?: number; /** Replaces the global `fetch`, for tests or a proxy. */ fetch?: typeof globalThis.fetch; /** * Called when a batch cannot be sent. The batch is dropped; a trace is never worth a retry storm. * To keep it instead, send through `spoolingExporter()`, from `nexus-ai-pro/tracing/spool`. Also * called, with an `OtlpPartialSuccessError`, when the collector took a batch but rejected some of * its spans, which sending again would not change. */ onError?: (error: unknown) => void; } /** A typed attribute value, in OTLP's JSON encoding. */ export type OtlpAttributeValue = { stringValue: string; } | { intValue: string; } | { doubleValue: number; } | { boolValue: boolean; }; /** One attribute, in OTLP's JSON encoding. */ export interface OtlpKeyValue { /** The attribute's name. */ key: string; /** Its typed value. */ value: OtlpAttributeValue; } /** An `ExportTraceServiceRequest` in OTLP's JSON encoding: spans grouped by resource and scope. */ export interface OtlpExportRequest { /** One entry per resource. */ resourceSpans: Array<{ /** The resource's attributes, such as `service.name`. */ resource: { attributes: OtlpKeyValue[]; }; /** The spans, grouped by the instrumentation scope that made them. */ scopeSpans: Array<{ scope: { name: string; version?: string; }; spans: OtlpSpan[]; }>; }>; } /** Thrown to `onError` when a collector took a batch but rejected some of its spans. */ export declare class OtlpPartialSuccessError extends Error { /** Spans the collector rejected. */ readonly rejectedSpans: number; /** Why, in its words. */ readonly errorMessage?: string | undefined; constructor( /** Spans the collector rejected. */ rejectedSpans: number, /** Why, in its words. */ errorMessage?: string | undefined); } /** One span in OTLP's JSON encoding. */ export interface OtlpSpan { /** 32 hex digits. */ traceId: string; /** 16 hex digits. */ spanId: string; /** 16 hex digits, absent for a root span. */ parentSpanId?: string; /** The span's name. */ name: string; /** 1 internal, 3 client. */ kind: number; /** Nanoseconds since the epoch, as a decimal string. */ startTimeUnixNano: string; /** Nanoseconds since the epoch, as a decimal string. */ endTimeUnixNano: string; /** Typed attributes. */ attributes: OtlpKeyValue[]; /** What happened inside it, each at its time. */ events?: OtlpSpanEvent[]; /** Events the run counted rather than kept. */ droppedEventsCount?: number; /** The spans it came from, beside its parent. */ links?: OtlpSpanLink[]; /** 1 ok, 2 error. */ status: { code: number; message?: string; }; } /** A span event in OTLP's JSON encoding. */ export interface OtlpSpanEvent { /** Nanoseconds since the epoch, as a decimal string. */ timeUnixNano: string; /** What happened. */ name: string; /** What it carries. */ attributes: OtlpKeyValue[]; } /** A span link in OTLP's JSON encoding. */ export interface OtlpSpanLink { /** 32 hex digits. */ traceId: string; /** 16 hex digits. */ spanId: string; /** Why it is linked. */ attributes: OtlpKeyValue[]; } /** * Turns one finished run into an OpenTelemetry span, with the GenAI semantic conventions. * * A model run is a client span named `chat ` with `gen_ai.operation.name`, * `gen_ai.provider.name`, `gen_ai.request.model`, `gen_ai.response.model`, and * `gen_ai.usage.input_tokens` and `output_tokens`. A tool run carries `gen_ai.tool.name`, an agent * run `gen_ai.agent.name`. What only Nexus knows goes under `nexus.*`: the run kind, a graph node and * its step, the cost, and the run id. A failed run has `error.type` and an error status. The run's * events become the span's events, and its links the span's links, to the spans of the runs named. */ export declare function runToOtlpSpan(run: Run): OtlpSpan; /** * Sends finished runs to any OpenTelemetry collector as OTLP/HTTP JSON, with no SDK to install. * * Pass it to a tracer's `exporters`, and every run the tracer keeps arrives as a span with the GenAI * semantic conventions, so Grafana Tempo, Jaeger, Honeycomb, Datadog, New Relic, or any OTLP backend * reads it as it reads the rest of the application. Spans are batched; `flush()` sends what is * waiting. Trace ids are the W3C ids `RunHandle.traceparent()` propagates, so a trace that crossed * processes arrives as one. */ export declare class OtlpTraceExporter implements TraceExporter { protected readonly options: OtlpTraceExporterOptions; private readonly queue; private timer; private sending; constructor(options: OtlpTraceExporterOptions); /** Queues a run, sending a batch when one is full. Runs still in progress are skipped. */ export(run: Run): void; /** Sends every span waiting. */ flush(): Promise; /** * Sends finished runs as one batch now, and rejects when the collector does not take them: what a * spooling exporter sends through, so a batch the collector refuses is kept, not dropped. */ send(runs: Run[]): Promise; /** The export request a batch of spans makes, under this exporter's resource. */ protected request(spans: OtlpSpan[]): OtlpExportRequest; /** Sends one batch, rejecting when the collector does not take it. */ protected post(spans: OtlpSpan[]): Promise; /** Reports spans the collector rejected from a batch it took. */ protected partial(partial: { rejectedSpans: number; errorMessage?: string; } | undefined): void; } export { decodeOtlpTraceResponse, encodeOtlpTraceRequest, type OtlpPartialSuccess } from './otlp-proto.js';