Skip to content

feat(extensions): add LogInfosFromContext helper (#133) - #331

Merged
lerenn merged 1 commit into
mainfrom
feat/133-loginfos-from-context
Jun 12, 2026
Merged

lerenn merged 1 commit into
mainfrom
feat/133-loginfos-from-context

Conversation

@lerenn

@lerenn lerenn commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Issue

Addresses #133 — the controller stores contextual information (channel, correlation ID, direction, …) in the context.Context, and the built-in loggers unwrap it. A custom logger had to know and unwrap each context key itself, which the issue calls out as tedious.

Change

Adds extensions.LogInfosFromContext(ctx) []LogInfo, which extracts all the asyncapi-codegen context values (provider, channel, direction, correlation ID, broker message, version) that are set into a []LogInfo in a single call. A custom logger can simply append them:

func (l MyLogger) Info(ctx context.Context, msg string, info ...extensions.LogInfo) {
    info = append(info, extensions.LogInfosFromContext(ctx)...)
    // ...
}

This is non-breaking and additive. The full refactor proposed in the issue (passing everything as explicit arguments from the generated code and dropping context enrichment from the built-in loggers) is a breaking, repo-wide change and is intentionally left out of this PR — hence "Addresses" rather than "Fixes".

Test

pkg/extensions/logger_test.go asserts the helper returns a LogInfo for each value present (and only those), and nothing for an empty context. It fails to compile before the change (function undefined) and passes after.

🤖 Generated with Claude Code

Custom loggers received the controller's contextual data (channel,
correlation ID, direction, ...) only through individual context keys,
making them tedious to extract. Add LogInfosFromContext to pull all of
them into a []LogInfo in one call. Non-breaking and additive; the larger
refactor of moving this off the context entirely is left for a separate
change.

Addresses #133

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lerenn
lerenn merged commit 3516904 into main Jun 12, 2026
5 checks passed
@lerenn
lerenn deleted the feat/133-loginfos-from-context branch June 12, 2026 16:22
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.

1 participant