/** * OpenTelemetry (P3.6): spans + W3C trace-context propagation. * * This module depends only on `@opentelemetry/api`, which is a standard * no-op implementation until an application registers a real SDK * (`NodeSDK`, a `TracerProvider`, and a propagator) via * `@opentelemetry/api`'s global registration functions. memoflow's SDK does * NOT ship or start the Node SDK itself — bring your own, see README.md * "Enabling OpenTelemetry". * * Because the API is a no-op by default, every function here is always safe * to call: with no SDK registered, `trace.getTracer(...).startSpan(...)` * returns a non-recording span, `propagation.inject` writes nothing (no * active/valid span context), and `propagation.extract` of an empty carrier * returns the context unchanged. This is what satisfies "the no-SDK path * doesn't throw" and "trace_context is empty when OTel is off". */ import { type Context, type Span } from '@opentelemetry/api'; export type ProviderTelemetryName = 'openai' | 'anthropic' | 'ai-sdk'; export type ProviderTelemetryOperation = 'generate'; export interface ProviderSpanHandle { run(fn: () => T): T; end(error?: unknown): void; } /** * Return a bounded error summary safe for logs and telemetry. Error messages, * stacks, causes, response bodies, and arbitrary string codes are deliberately * excluded because provider/client libraries commonly embed payloads or * credentials in them. */ export declare function safeErrorSummary(error: unknown): string; /** * Inject the currently active OpenTelemetry context into a fresh * `Record` suitable for `StartWorkflowRequest.trace_context`. * Empty when no SDK is registered or no span is active — matches the wire * contract documented on the proto field. */ export declare function injectCurrentContext(): Record; /** * Extract an OpenTelemetry parent `Context` from a propagated * `trace_context` map (as carried on `WorkflowTaskPayload` / * `ActivityTaskPayload`). Returns the active/root context unchanged when the * map is empty or absent. */ export declare function extractContext(traceContext: Record | undefined): Context; /** * Run `fn` inside a new span named `name`, parented to the context extracted * from `traceContext` (if any), with `attributes` set on the span. Handles * both sync and async `fn`; the span is ended and, on throw, marked as an * error, either way. Safe with no SDK registered (produces a non-recording * span; `fn` still runs normally) — Law 6: observability only, never * load-bearing. */ export declare function withSpan(name: string, traceContext: Record | undefined, attributes: Record, fn: (span: Span) => Promise): Promise; /** * Run one provider network operation inside a payload-free client span. * Provider adapters intentionally cannot attach arbitrary attributes here: * prompts, responses, model aliases, URLs, and provider errors commonly * contain tenant data and must never cross the telemetry boundary. */ export declare function withProviderSpan(provider: ProviderTelemetryName, operation: ProviderTelemetryOperation, fn: () => PromiseLike): Promise; /** Start a provider span whose lifetime may extend across a returned stream. */ export declare function startProviderSpan(provider: ProviderTelemetryName, operation: ProviderTelemetryOperation): ProviderSpanHandle;