feat: support structured logs#416
Merged
Merged
Conversation
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
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>
AlexFoxalt
requested changes
Jul 17, 2026
AlexFoxalt
approved these changes
Jul 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_FORMAT—text(default, unchanged) orjson(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 viajson.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:
TelemetryConfig+OTEL_TRACES_EXPORTER=otlp), OTel'sotel*fields (otelTraceID,otelSpanID, …) are injected onto every log record. The JSON formatter auto-adds them (no template change needed); the text formatter takes them viaDIAL_SDK_TEXT_LOG_FORMAT.Breaking / behavior changes
OTEL_PYTHON_LOG_CORRELATION=trueis now deprecated (still works). It emits aDeprecationWarningpointing toDIAL_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 underOTEL_PYTHON_LOG_CORRELATION. This only adds attributes to records; the default text output is unchanged.LogConfigmodel inaidial_sdk.utils.log_configwas removed (replaced byconfigure_sdk_logger()). Not part of the public API, flagged in case it was imported directly.DIAL_SDK_LOGis unchanged (defaultWARNING); its README entry moved intodocs/logging.md.