class DiagnosticsCollector

Default implementation of IDiagnosticsCollector that stores events in memory and can optionally emit them to console for debugging.

Constructors

new
DiagnosticsCollector(
correlationId?: string,
emitToConsole?: boolean,
)

Creates a new DiagnosticsCollector

Properties

private
readonly
correlationId: string
private
readonly
emitToConsole: boolean
private
operationNames: Map<string, string>
private
operationStartTimes: Map<string, number>

Methods

clear(): void

Clears all collected events

emit(event: DiagnosticEvent): void

Emits a custom diagnostic event

Gets the correlation ID for this collector

Gets all collected events

operationComplete(
eventId: string,
output?: Record<string, unknown>,
): void

Records successful completion of an operation

operationError(
eventId: string,
error: Error,
): void

Records an error during an operation. Extracts additional metadata from BaseError subclasses.

operationStart(
operation: string,
input?: Record<string, unknown>,
): string

Records the start of an operation

recordCacheEvent(
operation:
"hit"
| "miss"
| "write"
| "evict"
,
key: string,
size?: number,
): void

Records a cache event

recordMetric(
metric: string,
value: number,
unit: string,
dimensions?: Record<string, string>,
): void

Records a performance metric

recordNetworkEvent(
method: string,
url: string,
statusCode?: number,
durationMs?: number,
responseSize?: number,
): void

Records a network event