class OpenTelemetryExporter

DiagnosticsCollector that exports events to OpenTelemetry.

This class bridges the existing diagnostics system with OpenTelemetry's distributed tracing standard, enabling integration with platforms like Datadog, Honeycomb, Jaeger, and others.

Constructors

new
OpenTelemetryExporter(options?: OpenTelemetryExporterOptions)

Creates a new OpenTelemetry exporter

Properties

private
readonly
activeSpans: Map<string, Span>
private
readonly
enableConsoleLogging: boolean
private
readonly
operationNames: Map<string, string>
private
readonly
serviceName: string
private
readonly
spanContexts: Map<string, unknown>
private
readonly
tracer: Tracer

Methods

clear(): void

Clears all active spans and state

Emits a custom diagnostic event as a span event

private
flattenMetadata(metadata: Record<string, unknown>): Record<string,
string
| number
| boolean
>

Flattens metadata object to simple key-value pairs

private
generateEventId(): string

Generates a unique event ID

Gets all collected events (not applicable for OpenTelemetry)

private
hashKey(key: string): string

Hashes a cache key for privacy

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

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

Records the start of an operation as an OpenTelemetry span

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

Records a cache event as span attributes

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

Records a performance metric as span attributes

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

Records a network event as span attributes

private
sanitizeUrl(url: string): string

Sanitizes URL by removing query params and auth

private
setSpanAttribute(
span: Span,
key: string,
value: unknown,
): void

Safely sets a span attribute handling various types