core.otlp.handlers ================== .. py:module:: core.otlp.handlers .. autoapi-nested-parse:: Custom OTLP logging handlers that prevent global log pollution. Classes ------- .. autoapisummary:: core.otlp.handlers.JobmonOTLPLoggingHandler core.otlp.handlers.JobmonOTLPStructlogHandler Module Contents --------------- .. py:class:: JobmonOTLPLoggingHandler(level: int = logging.NOTSET, exporter: Optional[Union[Any, Dict]] = None, logger_provider: Optional[Any] = None) Bases: :py:obj:`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) .. py:attribute:: _SEVERITY_MAP :value: None .. py:method:: _get_severity_map() -> Dict[str, Any] :classmethod: Get severity map with lazy import. .. py:attribute:: _exporter_config :value: None .. py:attribute:: _logger_provider :value: None .. py:attribute:: _logger :type: Optional[Any] :value: None .. py:attribute:: _initialized :value: False .. py:attribute:: _capture_registered :value: False .. py:method:: _ensure_initialized() -> bool Ensure logger provider is initialized. Returns True if ready. .. py:method:: 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. .. py:method:: _extract_attributes(event_dict: Dict[str, Any]) -> Dict[str, Any] Extract OTLP attributes from event_dict. Strips the 'telemetry_' prefix from attribute names for cleaner OTLP exports while maintaining internal namespacing. .. py:method:: _parse_trace_context(event_dict: Optional[Dict[str, Any]]) -> tuple[int, int] Parse trace and span IDs from event_dict or current span. .. py:method:: emit(record: logging.LogRecord) -> None Emit log record to OTLP with extracted attributes. .. py:class:: JobmonOTLPStructlogHandler(level: int = logging.NOTSET, exporter: Optional[Union[Any, Dict]] = None, logger_provider: Optional[Any] = None) Bases: :py:obj:`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.