Skip to content

feat: support structured logs#416

Merged
adubovik merged 21 commits into
developmentfrom
feat/support-structured-logs
Jul 17, 2026
Merged

feat: support structured logs#416
adubovik merged 21 commits into
developmentfrom
feat/support-structured-logs

Conversation

@adubovik

@adubovik adubovik commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds structured (JSON) console logging and makes trace/span correlation work out of the box, configured entirely through environment variables. See docs/logging.md.

What's new

Log format (env vars, read once at import):

  • DIAL_SDK_LOG_FORMATtext (default, unchanged) or json (one line per record).
  • DIAL_SDK_TEXT_LOG_FORMAT — override the text %-format string.
  • DIAL_SDK_JSON_LOG_FORMAT — override the JSON template (a JSON document whose string leaves are %-format strings, escaped via json.dumps).

New public API:

  • from aidial_sdk import configure_root_logger — opt-in helper that routes all loggers (SDK, uvicorn, and your app's) through a single console handler using the env-selected format. Idempotent; leaves per-logger levels to you.

Trace/span correlation:

  • With tracing enabled (TelemetryConfig + OTEL_TRACES_EXPORTER=otlp), OTel's otel* fields (otelTraceID, otelSpanID, …) are injected onto every log record. The JSON formatter auto-adds them (no template change needed); the text formatter takes them via DIAL_SDK_TEXT_LOG_FORMAT.

Breaking / behavior changes

  • OTEL_PYTHON_LOG_CORRELATION=true is now deprecated (still works). It emits a DeprecationWarning pointing to DIAL_SDK_TEXT_LOG_FORMAT — it double-logs SDK records and can't produce JSON.
  • otel* fields are now injected whenever tracing is on, not only under OTEL_PYTHON_LOG_CORRELATION. This only adds attributes to records; the default text output is unchanged.
  • Internal: the LogConfig model in aidial_sdk.utils.log_config was removed (replaced by configure_sdk_logger()). Not part of the public API, flagged in case it was imported directly.

DIAL_SDK_LOG is unchanged (default WARNING); its README entry moved into docs/logging.md.

@adubovik adubovik self-assigned this Jul 16, 2026
Comment thread aidial_sdk/application.py Fixed
adubovik and others added 2 commits July 16, 2026 17:20
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
@adubovik
adubovik requested a review from AlexFoxalt July 16, 2026 16:55
adubovik and others added 4 commits July 17, 2026 11:47
Move the DIAL_SDK_LOG* resolution into a public LogConfig class whose
typed keyword args take precedence over the env vars (each unset arg
falls back to its env var / default), mirroring LoggingInstrumentor.
configure_root_logger() accepts a LogConfig to override the env vars in
code.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread aidial_sdk/utils/_json_log_formatter.py
Comment thread aidial_sdk/utils/_json_log_formatter.py Dismissed
@adubovik
adubovik enabled auto-merge (squash) July 17, 2026 14:41
@adubovik adubovik changed the title feat: support structured logs feat: support structured logs Jul 17, 2026
@adubovik adubovik changed the title feat: support structured logs feat: support structured logs Jul 17, 2026
@adubovik
adubovik merged commit 20c26ec into development Jul 17, 2026
15 of 16 checks passed
@adubovik
adubovik deleted the feat/support-structured-logs branch July 17, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants