Libraries v5.2.0
    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 → milliseconds, converted internally by the OTel SDK
      • level → severityNumber and severityText
      • renderedMessage → body
      • properties → flat attribute map (functions / symbols dropped, nested objects JSON-stringified)
      • messageTemplate → cleverbrush.message_template attribute
      • eventId → cleverbrush.event_id attribute
      • exception.* attributes only when the exception policy allows them

      Passes each event's captured context explicitly to the OTel Logs API, preserving trace correlation through asynchronous queues and retries. Manually constructed events without a snapshot use the calling context.

      The OTel SDK batches export; additional BatchingSink buffering is optional.

      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()],
      });