Skip to content

convert internal logging to log/slog with structured attributes - #122

Draft
JoshVanL wants to merge 1 commit into
dapr:mainfrom
JoshVanL:structured-logging
Draft

convert internal logging to log/slog with structured attributes#122
JoshVanL wants to merge 1 commit into
dapr:mainfrom
JoshVanL:structured-logging

Conversation

@JoshVanL

Copy link
Copy Markdown

The backend previously logged through the printf-style backend.Logger interface, building every message eagerly with fmt verbs. Internal logging now goes through *slog.Logger with structured attributes; the public API is unchanged.

backend.Logger and every constructor signature stay exactly as they were. Callers such as dapr satisfy the interface structurally and keep compiling untouched. The new backend.SlogFromLogger adapts an incoming Logger at the constructor boundary:

  • A logger from dapr/kit converts in place: records flow through kit's own slog handler, keeping the dapr log schema, the scope derived from the logger's name, and any runtime configuration applied to it. This is what daprd hits, pinned by a regression test.
  • Any other implementation, including the stdlib-log DefaultLogger, is wrapped in a handler that renders records through its printf methods with attributes appended as key=value pairs, so nothing is dropped. The exact message layout for such sinks changes slightly (attributes as a k=v suffix rather than interpolated); nothing asserts on it.

Call sites gain real attributes in place of interpolation. The pervasive "%v: " instance-ID prefix becomes an instance_id attribute via derived loggers, and the %s/%s#%d composite keys in the executor become separate instance_id/activity/event_id attributes.

Two performance fixes on the per-work-item path: HistoryListSummary and ActionListSummary were built unconditionally on every work item even with debug disabled; they are now deferred through slog.LogValuer and cost nothing unless a record is actually emitted. The workflow state description at orchestration.go is deferred the same way.

Also fixes the postgres backend logging Error("CreateTaskHub", "failed ...", err) through fmt.Sprint concatenation, which produced a message with no separators, and distinguishes the previously identical cleanup-failed and retry-failed warnings in both sqlite and postgres, which now carry the underlying error.

The backend previously logged through the printf-style backend.Logger
interface, building every message eagerly with fmt verbs. Internal
logging now goes through *slog.Logger with structured attributes; the
public API is unchanged.

backend.Logger and every constructor signature stay exactly as they
were. Callers such as dapr satisfy the interface structurally and keep
compiling untouched. The new backend.SlogFromLogger adapts an incoming
Logger at the constructor boundary:

* A logger from dapr/kit converts in place: records flow through kit's
  own slog handler, keeping the dapr log schema, the scope derived from
  the logger's name, and any runtime configuration applied to it. This
  is what daprd hits, pinned by a regression test.
* Any other implementation, including the stdlib-log DefaultLogger, is
  wrapped in a handler that renders records through its printf methods
  with attributes appended as key=value pairs, so nothing is dropped.
  The exact message layout for such sinks changes slightly (attributes
  as a k=v suffix rather than interpolated); nothing asserts on it.

Call sites gain real attributes in place of interpolation. The
pervasive "%v: " instance-ID prefix becomes an instance_id attribute
via derived loggers, and the %s/%s#%d composite keys in the executor
become separate instance_id/activity/event_id attributes.

Two performance fixes on the per-work-item path: HistoryListSummary and
ActionListSummary were built unconditionally on every work item even
with debug disabled; they are now deferred through slog.LogValuer and
cost nothing unless a record is actually emitted. The workflow state
description at orchestration.go is deferred the same way.

Also fixes the postgres backend logging Error("CreateTaskHub",
"failed ...", err) through fmt.Sprint concatenation, which produced a
message with no separators, and distinguishes the previously identical
cleanup-failed and retry-failed warnings in both sqlite and postgres,
which now carry the underlying error.

Signed-off-by: joshvanl <me@joshvanl.dev>
@JoshVanL
JoshVanL requested a balanced review from Copilot August 13, 2026 19:47
@JoshVanL
JoshVanL requested a review from a team as a code owner August 13, 2026 19:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Migrates internal logging to structured log/slog while preserving public logger APIs.

Changes:

  • Adds adapters for Dapr Kit and printf-style loggers.
  • Converts internal logs to structured attributes.
  • Defers expensive debug summaries and improves backend error logs.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
go.mod Updates dependencies and adds Kit fork replacement.
go.sum Updates dependency checksums.
client/client_grpc.go Adapts the client logger to slog.
client/worker_grpc.go Converts worker-client logs to structured records.
backend/worker.go Adds worker-scoped structured logging.
backend/taskhub.go Converts task-hub lifecycle logging.
backend/sqlite/sqlite.go Structures SQLite warnings and errors.
backend/postgres/postgres.go Structures PostgreSQL warnings and errors.
backend/orchestration.go Adds instance attributes and lazy summaries.
backend/logger_slog.go Implements slog adapters and lazy values.
backend/logger_slog_test.go Tests Kit, bridge, and nil logger paths.
backend/executor.go Structures executor and stream logging.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread go.mod
modernc.org/memory v1.8.2 // indirect
)

replace github.com/dapr/kit => github.com/joshvanl/kit v0.0.0-20260813182616-fd5d465c8baa
@JoshVanL
JoshVanL marked this pull request as draft August 14, 2026 18:28
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