feat(extensions): add LogInfosFromContext helper (#133) - #331
Merged
Merged
Conversation
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>
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.
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[]LogInfoin a single call. A custom logger can simply append them: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.goasserts the helper returns aLogInfofor 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