import { WithInterceptor } from "../util/type-utils.mjs"; import { CommandTypesBase } from "../types/command.mjs"; //#region src/extension/tracing.d.ts /** Minimal subset of OTEL `SpanStatusCode`. */ type SpanStatusCode = 0 | 1 | 2; /** Minimal subset of OTEL `SpanStatus`. */ type SpanStatus = { code: SpanStatusCode; message?: string; }; /** Minimal subset of OTEL `Span`. */ interface OtelSpan { setAttribute(key: string, value: string | number | boolean): this; addEvent(name: string, attributes?: Record): this; setStatus(status: SpanStatus): this; recordException(error: unknown): this; end(): void; spanContext(): { traceId: string; spanId: string; }; } /** Minimal subset of OTEL `Tracer`. */ interface OtelTracer { startSpan(name: string): OtelSpan; } /** Minimal subset of OTEL `TracerProvider`. */ interface OtelTracerProvider { getTracer(name: string, version?: string): OtelTracer; } /** Tracing handle injected into the command context. */ type PadroneTracer = { /** The underlying OTEL tracer. */tracer: OtelTracer; /** Root span covering the full command execution. */ rootSpan: OtelSpan; /** Run `fn` inside a child span that is automatically ended when `fn` returns (or rejects). */ span: (name: string, fn: (span: OtelSpan) => T) => T; }; /** Configuration for the tracing extension. */ type PadroneTracingConfig = { /** OTEL `TracerProvider`. Required — there is no global fallback. */provider: OtelTracerProvider; /** Service / tracer name. Defaults to the CLI program name. */ serviceName?: string; }; /** Builder/program type after applying `padroneTracing()`. Adds `{ tracing: PadroneTracer }` to the command context. */ type WithTracing = WithInterceptor; /** * Extension that adds OpenTelemetry tracing to command execution. * * Creates a root span for each command invocation and provides a `PadroneTracer` * on the command context for creating child spans in action handlers. * * When used with `padroneLogger()`, the logger automatically emits span events * for each log call — no extra configuration needed. The logger detects the * tracing context and bridges log output to span events. * * Uses minimal OTEL-compatible interfaces — pass any `TracerProvider` that * implements `getTracer()`. Works with `@opentelemetry/api` or compatible * libraries. * * Provides `{ tracing: PadroneTracer }` on the command context. * Access it in action handlers as `ctx.context.tracing`. * * Usage: * ```ts * import { trace } from '@opentelemetry/api'; * import { createPadrone, padroneLogger } from 'padrone'; * import { padroneTracing } from 'padrone/tracing'; * * createPadrone('my-cli') * .extend(padroneTracing({ provider: trace.getTracerProvider() })) * .extend(padroneLogger()) * .command('deploy', (c) => * c.action((_args, ctx) => { * ctx.context.logger.info('deploying'); // also emits a span event * ctx.context.tracing.span('build', (span) => { * span.setAttribute('target', 'production'); * }); * }) * ) * ``` */ declare function padroneTracing(config: PadroneTracingConfig): (builder: T) => WithTracing; //#endregion export { OtelSpan, OtelTracer, OtelTracerProvider, PadroneTracer, PadroneTracingConfig, WithTracing, padroneTracing }; //# sourceMappingURL=tracing.d.mts.map