core.otlp
Elegant OTLP integration for jobmon that prevents global log pollution.
Submodules
Attributes
Classes
Formatter that adds OpenTelemetry span details to jobmon logs. |
|
Universal OTLP logging handler with lazy initialization and attribute extraction. |
|
OTLP logging handler for structlog. |
Functions
|
Structlog processor to add OpenTelemetry span details to log entries. |
|
Get details of the current OpenTelemetry span. |
Package Contents
- class core.otlp.JobmonOTLPFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]
Bases:
logging.FormatterFormatter that adds OpenTelemetry span details to jobmon logs.
Note: For handlers using _JobmonOTLPLoggingHandler, this formatter is not used for OTLP output (handler creates OTLPLogRecord directly). It only affects console/file output.
- format(record: logging.LogRecord) str[source]
Format log record with OpenTelemetry span details.
- class core.otlp.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)
- _SEVERITY_MAP = None
- _exporter_config = None
- _logger_provider = None
- _initialized = False
- _capture_registered = False
- 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.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.
- core.otlp.add_span_details_processor(logger: Any, method_name: str, event_dict: Dict[str, Any]) Dict[str, Any][source]
Structlog processor to add OpenTelemetry span details to log entries.
- Parameters:
logger – The logger instance (not used, but required by Structlog processor signature).
method_name – The logging method name (e.g., “info”, “debug”).
event_dict – The event dictionary representing the log entry.
- Returns:
The modified event dictionary with OpenTelemetry span details added.