Skip to content

feat(extensions): pass log infos explicitly instead of via context (#334) - #335

Merged
lerenn merged 1 commit into
mainfrom
feat/334-explicit-log-infos
Jun 14, 2026
Merged

lerenn merged 1 commit into
mainfrom
feat/334-explicit-log-infos

Conversation

@lerenn

@lerenn lerenn commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Closes #334. Follow-up to #133 / #331 — completes the breaking part.

What

Stop relying on the context.Context to carry logging metadata into the loggers.

  • Generated code (v2 & v3 controller templates): every c.logger.Info/Warning/Error(...) call now attaches the contextual values explicitly via extensions.LogInfosFromContext(ctx).... The single call site that already passes extra info uses append(extensions.LogInfosFromContext(ctx), …)....
  • Built-in loggers (Text, ECS): dropped setInfoFromContext; they no longer read from the context and log only what they are given (plus the intrinsic message/@timestamp/log.* keys).
  • The context values are still set in the generated code, so anything else relying on them keeps working — only the loggers stop reading from it.

Design decision

LogInfosFromContext emits generic keys (channel, correlationID, brokerMessage, direction, provider, version) and is the single source of truth. The loggers are now pure pass-through: they print those generic keys rather than re-mapping them.

BREAKING: the built-in Text/ECS loggers now emit the generic keys instead of their previous custom names (e.g. ECS no longer maps to trace.id, event.action, event.original; Text no longer uses Channel/CorrelationID/Content). Custom loggers now receive everything as arguments and never have to unwrap context keys. Documented as a migration note in the README.

Scope / acceptance

  • Generated controller code attaches the contextual LogInfos explicitly at each log call.
  • Text and ECS loggers no longer call setInfoFromContext.
  • Migration/compatibility story documented (README custom-logging section).
  • Regenerated all golden files (52 *.gen.go); examples updated.
  • Added pass-through tests for the built-in loggers.

Testing

  • go build ./..., go vet ./... clean
  • go test ./pkg/codegen/... ./pkg/extensions/... pass (broker integration tests requiring a live NATS server are excluded — unrelated)
  • golangci-lint clean on changed packages and sample generated code

🤖 Generated with Claude Code

)

Generated controllers now attach the contextual values (channel,
correlation ID, direction, provider, broker message, version) to every
logger call as explicit LogInfo arguments, sourced from
extensions.LogInfosFromContext. The built-in Text and ECS loggers drop
their context-enrichment (setInfoFromContext) and log only what they are
given.

The values are still stored in the context, so custom loggers that want
to keep reading from it can still call LogInfosFromContext.

BREAKING CHANGE: the built-in Text/ECS loggers now emit the generic
LogInfosFromContext keys (channel, correlationID, brokerMessage,
direction, provider, version) instead of their previous custom names
(e.g. ECS no longer maps to trace.id, event.action, event.original).

Closes #334

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lerenn
lerenn merged commit 90e966f into main Jun 14, 2026
5 checks passed
@lerenn
lerenn deleted the feat/334-explicit-log-infos branch June 14, 2026 14:12
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.

Loggers: pass contextual info as explicit arguments instead of via context (follow-up to #133)

1 participant