core.otlp

Elegant OTLP integration for jobmon that prevents global log pollution.

Submodules

Attributes

OTLP_AVAILABLE

OpenTelemetryLogFormatter

Classes

JobmonOTLPFormatter

Formatter that adds OpenTelemetry span details to jobmon logs.

JobmonOTLPLoggingHandler

Universal OTLP logging handler supporting dict configs and pre-configured exporters.

JobmonOTLPStructlogHandler

OTLP logging handler with structlog formatting for structured logs.

Functions

add_span_details_processor(→ Dict[str, Any])

Structlog processor to add OpenTelemetry span details to log entries.

get_current_span_details(→ Tuple[Optional[str], ...)

Get details of the current OpenTelemetry span.

Package Contents

core.otlp.OTLP_AVAILABLE = True[source]
class core.otlp.JobmonOTLPFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]

Bases: logging.Formatter

Formatter that adds OpenTelemetry span details to jobmon logs.

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)[source]

Bases: logging.Handler

Universal OTLP logging handler supporting dict configs and pre-configured exporters.

This handler follows the principle of single responsibility while being flexible enough to work with different 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)

_exporter_config = None
_otlp_handler: logging.Handler | None = None
_debug_mode
emit(record: logging.LogRecord) None[source]

Emit a log record to OTLP.

_create_handler() logging.Handler | None[source]

Create OTLP handler by processing the exporter configuration.

_create_exporter_from_dict(config: Any) Any | None[source]

Create an OTLP exporter from dictionary configuration (handles ConvertingDict).

_create_processor_from_dict(exporter: Any, config: Any) Any[source]

Create a batch processor with configuration from dict (handles ConvertingDict).

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

Bases: JobmonOTLPLoggingHandler

OTLP logging handler with structlog formatting for structured logs.

This handler extends JobmonOTLPLoggingHandler to provide structured logging using structlog formatting before sending to OTLP.

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.

core.otlp.get_current_span_details() Tuple[str | None, str | None, str | None][source]

Get details of the current OpenTelemetry span.

Returns:

Tuple of (span_id, trace_id, parent_span_id) as hex strings, or (None, None, None)

core.otlp.OpenTelemetryLogFormatter[source]