core.otlp.handlers

Custom OTLP logging handlers that prevent global log pollution.

Attributes

JobmonOTLPStructlogHandler

Classes

JobmonOTLPLoggingHandler

Universal OTLP logging handler with lazy initialization and attribute extraction.

Module Contents

class core.otlp.handlers.JobmonOTLPLoggingHandler(level: int = logging.NOTSET, exporter: Any | Dict | None = None, logger_provider: Any | None = None)

Bases: logging.Handler

Universal OTLP logging handler with lazy initialization and attribute extraction.

This handler works with both stdlib logging and structlog. It extracts structured attributes from structlog’s thread-local event_dict when available, enabling rich OTLP exports with queryable fields.

Note: JobmonOTLPStructlogHandler is an alias for this class (kept for backward compatibility). Both names can be used interchangeably in configuration.

Supports flexible configuration patterns:

  1. Inline dict configuration (server pattern):

    handlers:
      otlp_logs:
        class: jobmon.core.otlp.JobmonOTLPLoggingHandler
        level: INFO
        exporter:
          module: opentelemetry.exporter.otlp.proto.grpc._log_exporter
          class: OTLPLogExporter
          endpoint: otelcol.dev.aks.scicomp.ihme.washington.edu:443
          options: [["grpc.max_send_message_length", 16777216]]
          max_export_batch_size: 8
    
  2. Pre-configured exporter instance:

    handler = JobmonOTLPLoggingHandler(exporter=my_exporter)
    
  3. Direct use with logger_provider (for testing):

    handler = JobmonOTLPLoggingHandler(logger_provider=my_provider)
    

Initialize with optional exporter config or pre-configured logger provider.

Parameters:
  • level – Logging level for this handler

  • exporter – Either a dict configuration or pre-configured OTLP exporter instance

  • logger_provider – Optional pre-configured logger provider (for testing/direct use)

close() None

Tidy up any resources used by the handler.

This version removes the handler from an internal map of handlers, _handlers, which is used for handler lookup by name. Subclasses should ensure that this gets called from overridden close() methods.

emit(record: logging.LogRecord) None

Emit log record to OTLP with extracted attributes.

core.otlp.handlers.JobmonOTLPStructlogHandler