Skip to content

Structured Logging

OJS defines structured logging conventions for backends, workers, and SDKs. Structured JSON logs enable consistent querying, correlation with traces, and integration with log aggregation platforms.

Every log entry MUST include:

{
"timestamp": "2026-02-15T10:30:00.123Z",
"severity": "INFO",
"severity_number": 9,
"message": "job completed",
"component": "worker"
}
FieldTypeRequiredDescription
timestampstringYesRFC 3339 with milliseconds
severitystringYesLog level name
severity_numberintegerYesOpenTelemetry severity number
messagestringYesHuman-readable message
componentstringYesSource component (api, worker, scheduler, etc.)

Aligned with OpenTelemetry Logs:

LevelNumberDescription
TRACE1Detailed debugging (per-field, per-step)
DEBUG5Diagnostic information
INFO9Normal operational events
WARN13Unexpected but handled conditions
ERROR17Errors requiring attention
FATAL21Unrecoverable errors
{"severity": "INFO", "message": "job enqueued", "job_id": "...", "job_type": "email.send", "queue": "default"}
{"severity": "INFO", "message": "job started", "job_id": "...", "job_type": "email.send", "worker_id": "worker-1"}
{"severity": "INFO", "message": "job completed", "job_id": "...", "duration_ms": 245}
{"severity": "ERROR", "message": "job failed", "job_id": "...", "error_type": "connection_timeout", "attempt": 2}
{"severity": "WARN", "message": "slow job", "job_id": "...", "duration_ms": 15000, "threshold_ms": 10000}

All log entries related to a job SHOULD include job_id for filtering.

Include trace_id and span_id when available:

{
"timestamp": "2026-02-15T10:30:00.123Z",
"severity": "INFO",
"message": "job completed",
"job_id": "01961234-5678-7abc-def0-123456789abc",
"trace_id": "0af7651916cd43dd8448eb211c80319c",
"span_id": "b7ad6b7169203331"
}

HTTP API logs SHOULD include request_id for correlating request processing.

  • Never log full args or result values. They may contain PII.
  • Log job_type, job_id, queue, and attempt only.
  • If args must be logged for debugging, use a configurable redaction filter.
  • API keys and credentials MUST never appear in logs.

For high-throughput deployments, log sampling reduces volume:

StrategyDescription
Rate-basedLog 1 in N events
Error-biasedAlways log errors, sample successes
Tail-basedBuffer logs; flush all if error occurs, sample if not

Error-biased sampling is recommended: always log errors and warnings, sample INFO-level logs at high volume.