[LFXV2-1701] fix: consolidate duplicate error logging to boundary callers#88
Open
andrest50 wants to merge 3 commits into
Open
[LFXV2-1701] fix: consolidate duplicate error logging to boundary callers#88andrest50 wants to merge 3 commits into
andrest50 wants to merge 3 commits into
Conversation
Errors returned from the service orchestration layer were being logged both at the point of origin and again by the boundary caller (wrapError for HTTP, committee_handler for NATS, stream_consumer for JetStream), producing 2-3 redundant log lines per error. Remove the intermediate slog.ErrorContext calls so each error is logged exactly once at the outermost handler. Per-member error logs inside the sync loop are kept because they carry unique member_uid context not available to the caller. Generated with [Claude Code](https://claude.ai/code) Signed-off-by: Andres Tobon <andrest2455@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces duplicated error logging by removing slog.ErrorContext calls from service/orchestration code paths and relying on boundary-layer logging (HTTP wrapError, NATS message handler, JetStream consumer) to emit a single error log per failure.
Changes:
- Removed redundant
slog.ErrorContextcalls frominternal/service/message_handler.gowhere errors are simply returned to callers. - Removed redundant
slog.ErrorContextcalls frominternal/service/committee_reader.gowhere errors are simply returned to callers. - Preserved per-member sync error logs that carry unique
member_uidcontext.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| internal/service/message_handler.go | Removes per-error logs in NATS/stream handlers, intending to defer logging to boundary callers. |
| internal/service/committee_reader.go | Removes per-error logs in reader orchestrator methods, intending to defer logging to boundary callers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…red identifiers Address review comments from copilot-pull-request-reviewer: - committee_reader.go GetBase: append committee_uid to ctx via log.AppendCtx so boundary error logs (wrapError) include this field without per-layer ErrorContext - committee_reader.go GetSettings: same committee_uid enrichment - committee_reader.go GetMember: append both committee_uid and member_uid to ctx - committee_reader.go ListMembers: append committee_uid to ctx - message_handler.go HandleCommitteeGetAttribute: append committee_uid and attribute to ctx after UUID validation so NATS boundary log includes these fields - message_handler.go HandleCommitteeListMembers: append committee_uid to ctx after UUID validation - message_handler.go HandleCommitteeTotalMembersSync: append committee_uid to ctx so JetStream boundary log (stream_consumer) includes committee_uid Resolves 6 review threads. Generated with [Claude Code](https://claude.ai/code) Signed-off-by: Andres Tobon <andrest2455@gmail.com>
Now that committee_uid, member_uid, and attribute are appended to ctx via log.AppendCtx, they no longer need to be passed as explicit fields to individual slog calls within the same function. Also moves AppendCtx before the initial debug log in message handlers so all logs in the function benefit from the enriched context. Generated with [Claude Code](https://claude.ai/code) Signed-off-by: Andres Tobon <andrest2455@gmail.com>
Comment on lines
317
to
321
| ctx = context.WithValue(ctx, constants.AuthorizationContextID, "Bearer lfx-v2-committee-service") | ||
| ctx = log.AppendCtx(ctx, slog.String("committee_uid", committeeUID)) | ||
|
|
||
| slog.DebugContext(ctx, "starting total_members sync", | ||
| "committee_uid", committeeUID, | ||
| "subject", subject, | ||
| ) | ||
| slog.DebugContext(ctx, "starting total_members sync", "subject", subject) | ||
|
|
| ) | ||
| ctx = log.AppendCtx(ctx, slog.String("committee_uid", uid)) | ||
| ctx = log.AppendCtx(ctx, slog.String("attribute", attribute)) | ||
| slog.DebugContext(ctx, "committee get name request") |
| var event model.CommitteeMailingListChangedEvent | ||
| if err := json.Unmarshal(msg.Data(), &event); err != nil { | ||
| slog.ErrorContext(ctx, "failed to unmarshal CommitteeMailingListChangedEvent", "error", err) | ||
| return nil, err |
| var event model.CommitteeEvent | ||
| if err := json.Unmarshal(msg.Data(), &event); err != nil { | ||
| slog.ErrorContext(ctx, "failed to unmarshal CommitteeEvent", "error", err) | ||
| return nil, err |
| var event model.CommitteeEvent | ||
| if err := json.Unmarshal(msg.Data(), &event); err != nil { | ||
| slog.ErrorContext(ctx, "failed to unmarshal CommitteeEvent for total_members sync", "error", err) | ||
| return err |
Comment on lines
+67
to
+69
| ctx = log.AppendCtx(ctx, slog.String("committee_uid", uid)) | ||
| ctx = log.AppendCtx(ctx, slog.String("attribute", attribute)) | ||
| slog.DebugContext(ctx, "committee get name request") |
Comment on lines
+62
to
+63
| ctx = log.AppendCtx(ctx, slog.String("committee_uid", uid)) | ||
| slog.DebugContext(ctx, "executing get committee base use case") |
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
wrapErrorfor HTTP,committee_handlerfor NATS,stream_consumerfor JetStream)slog.ErrorContextcalls fromcommittee_reader.goandmessage_handler.gofor all errors that are simply returned to a callerHandleCommitteeUpdatedsync loop are retained since they carry uniquemember_uidcontext that the outer caller cannot replicateTicket
LFXV2-1701
🤖 Generated with Claude Code