Libraries
    Preparing search index...

    Function otelLogSink

    • Creates a LogSink that forwards every event to the OpenTelemetry Logs API.

      Maps each LogEvent to an OTel LogRecord:

      • timestamp → nanoseconds via Date.getTime() × 1e6
      • levelseverityNumber and severityText
      • renderedMessagebody
      • properties → flat attribute map (functions / symbols dropped, nested objects JSON-stringified)
      • messageTemplatecleverbrush.message_template attribute
      • eventIdcleverbrush.event_id attribute
      • exception.* attributes when the event carries an Error

      Trace correlation (traceId, spanId) is filled in automatically by the OTel SDK from the active context — typically established by tracingMiddleware.

      The sink itself is per-event; for high-throughput services wrap it with BatchingSink from @cleverbrush/log.

      Requires that setupOtel({ ... }) has been called so the global LoggerProvider is set; otherwise emissions become no-ops.

      Parameters

      Returns LogSink

      a LogSink that emits to the OTel Logs pipeline

      import { createLogger, consoleSink } from '@cleverbrush/log';
      import { otelLogSink } from '@cleverbrush/otel';

      const logger = createLogger({
      minimumLevel: 'information',
      sinks: [consoleSink(), otelLogSink()],
      });