core.otlp.handlers
Custom OTLP logging handlers that prevent global log pollution.
Classes
Universal OTLP logging handler with lazy initialization and attribute extraction. |
|
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.HandlerUniversal 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:
- 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
- Pre-configured exporter instance:
handler = JobmonOTLPLoggingHandler(exporter=my_exporter)
- Direct use with logger_provider (for testing):
handler = JobmonOTLPLoggingHandler(logger_provider=my_provider)
- 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:
JobmonOTLPLoggingHandlerOTLP 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.