core.otlp.handlers

Custom OTLP logging handlers that prevent global log pollution.

Classes

JobmonOTLPLoggingHandler

Universal OTLP logging handler with lazy initialization and attribute extraction.

JobmonOTLPStructlogHandler

OTLP logging handler for structlog.

Module Contents

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

Bases: logging.Handler

Universal OTLP logging handler with lazy initialization and attribute extraction.

This handler extracts attributes from structlog’s thread-local event_dict and 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)

_SEVERITY_MAP = None[source]
classmethod _get_severity_map() Dict[str, Any][source]

Get severity map with lazy import.

_exporter_config = None[source]
_logger_provider = None[source]
_logger: Any | None = None[source]
_initialized = False[source]
_capture_registered = False[source]
_ensure_initialized() bool[source]

Ensure logger provider is initialized. Returns True if ready.

close() None[source]

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.

_extract_attributes(event_dict: Dict[str, Any]) Dict[str, Any][source]

Extract OTLP attributes from event_dict.

Strips the ‘telemetry_’ prefix from attribute names for cleaner OTLP exports while maintaining internal namespacing.

_parse_trace_context(event_dict: Dict[str, Any] | None) tuple[int, int][source]

Parse trace and span IDs from event_dict or current span.

emit(record: logging.LogRecord) None[source]

Emit log record to OTLP with extracted attributes.

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

Bases: JobmonOTLPLoggingHandler

OTLP logging handler for structlog.

Identical to JobmonOTLPLoggingHandler - uses the same custom handler that extracts attributes from thread-local event_dict. This class exists for clarity in configuration (to indicate structlog support) but functionally is the same as the parent class.