UNPKG

@zendesk/retrace

Version:

define and capture Product Operation Traces along with computed metrics with an optional friendly React beacon API

79 lines (78 loc) 2.45 kB
import type { TraceManager } from './TraceManager'; import type { RelationSchemasBase } from './types'; type SimpleLoggerFn = (message: string) => void; interface ConsoleLike { log: (...args: any[]) => void; group: (...args: any[]) => void; groupCollapsed: (...args: any[]) => void; groupEnd: () => void; } /** * Options for configuring the ConsoleTraceLogger */ export interface ConsoleTraceLoggerOptions { /** * The logging mechanism. Can be a console-like object (supporting .log, .group, etc.) * or a simple function that accepts a string message. * Defaults to the global `console` object. */ logger?: ConsoleLike | SimpleLoggerFn; /** * Whether to enable verbose logging with more details. * Defaults to false. */ verbose?: boolean; /** * Prefix added to all log messages. * Defaults to '[retrace]'. */ prefix?: string; /** * Maximum string length for attributes/relatedTo objects before truncation. * Defaults to 500. */ maxObjectStringLength?: number; /** * Enable console grouping (.group, .groupCollapsed, .groupEnd). * Only effective if the logger is a console-like object. * Defaults to true. */ enableGrouping?: boolean; /** * Enable ANSI color codes in the output. * Only effective if the logger is a console-like object. * Defaults to true. */ enableColors?: boolean; } /** * Information about an active or completed trace */ interface TraceInfo<_RelationSchemasT> { id: string; name: string; variant: string; startTime: number; attributes?: Record<string, unknown>; relatedTo?: Record<string, unknown>; requiredSpans: { name: string; isMatched: boolean; matcher: Function; }[]; parentTraceId?: string; liveDuration: number; totalSpanCount: number; hasErrorSpan: boolean; hasSuppressedErrorSpan: boolean; definitionModifications: unknown[]; } /** * A utility for logging trace information */ export declare function createConsoleTraceLogger<RelationSchemasT extends RelationSchemasBase<RelationSchemasT>>(traceManager: TraceManager<RelationSchemasT>, optionsInput?: ConsoleTraceLoggerOptions): { getActiveTraces: () => Map<string, TraceInfo<RelationSchemasT>>; setOptions: (newOptions: Partial<ConsoleTraceLoggerOptions>) => void; cleanup: () => void; }; export {};