UNPKG

autotel

Version:
135 lines (131 loc) 3.42 kB
import { SpanExporter, ReadableSpan } from '@opentelemetry/sdk-trace-base'; export { ConsoleSpanExporter, InMemorySpanExporter } from '@opentelemetry/sdk-trace-base'; /** * Pretty Console Exporter * * A developer-friendly span exporter that displays colorized, hierarchical * trace output in the terminal. Zero external dependencies - uses ANSI escape codes. * * @example Basic usage * ```typescript * init({ * service: 'my-app', * debug: 'pretty' // Uses PrettyConsoleExporter * }) * ``` * * @example Explicit usage with options * ```typescript * import { PrettyConsoleExporter } from 'autotel/exporters' * * init({ * service: 'my-app', * spanExporters: [new PrettyConsoleExporter({ * colors: true, * showAttributes: true, * hideAttributes: ['http.user_agent'] * })] * }) * ``` */ /** * Export result type for SpanExporter callback */ interface ExportResult { code: number; error?: Error; } /** * Configuration options for PrettyConsoleExporter */ interface PrettyConsoleExporterOptions { /** * Enable ANSI colors in output * @default auto-detect TTY */ colors?: boolean; /** * Show span attributes in output * @default true */ showAttributes?: boolean; /** * Maximum length for attribute values before truncation * @default 50 */ maxValueLength?: number; /** * Show instrumentation scope name (e.g., [http], [pg]) * @default true */ showScope?: boolean; /** * Attribute keys to always hide from output * @default [] */ hideAttributes?: string[]; /** * Show trace ID for each root span * @default false */ showTraceId?: boolean; } /** * Pretty Console Exporter - colorized, hierarchical span output for development * * Features: * - Colorized status indicators (✓ green, ✗ red) * - Duration with color coding (fast=green, medium=yellow, slow=red) * - Hierarchical tree view showing parent-child relationships * - Attribute display with truncation * - Error message highlighting */ declare class PrettyConsoleExporter implements SpanExporter { private readonly options; constructor(options?: PrettyConsoleExporterOptions); /** * Export spans with pretty formatting */ export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void; /** * Group spans by their trace ID */ private groupByTrace; /** * Print a single trace with all its spans as a tree */ private printTrace; /** * Build a tree structure from flat spans using parent-child relationships */ private buildSpanTree; /** * Print a span node with indentation and tree characters */ private printNode; /** * Get short scope name from instrumentation scope */ private getScopeName; /** * Format span attributes as a comma-separated string */ private formatAttributes; /** * Truncate string to max length with ellipsis */ private truncate; /** * Apply ANSI color if colors are enabled */ private color; /** * Shutdown (no-op for console exporter) */ shutdown(): Promise<void>; /** * Force flush (no-op for console exporter) */ forceFlush(): Promise<void>; } export { PrettyConsoleExporter, type PrettyConsoleExporterOptions };