Repository navigation
fix(logger): pass the caller pc to handler wrappers - #53
Merged
Merged
Conversation
A wrapper set with WithHandlerWrapper or SetHandlerWrapper saw record.PC point at logger.(*Logger).log. Build the record with the caller's PC, the same call site as the source attribute. Co-Authored-By: Claude Opus 5.5 <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.
What
A handler wrapper set with
WithHandlerWrapper/SetHandlerWrapperreceived aslog.RecordwhosePCpointed atlogger.(*Logger).log(logger/logger.go), because the logger calledslog.Logger.Log. A wrapper usingAddSourceor a bridge that readsrecord.PC(otelslog-style) reported the wrong call site. The JSONsourceattribute was already right (LOG-06); the wrapper path (LOG-07) never met it.Found by the epic-assessment retrospective (finding 6).
How
(*Logger).logbuilds theslog.Recorditself with the caller's PC, taken from the same program counters as thesourceattribute (calldepth honored,SetCalldepthincluded), and callsHandler().Handle. This is the pattern thelog/slogdocs give for wrapper functions.callerPC, which does not allocate (the same workslog.Logger.Logdid before).context.Background(), asslog.Logger.Logdid.record.PCholds since v1.7.5.Constitution VIII deviation (justified here per Governance): the handler's error is discarded with
_ =. A logging call has no error result and no other channel to report a failed write;slog.Logger.Logdropped the same error before this change, so behavior is unchanged. The comment at the call states this.Tests
TestHandlerWrapperSeesCallerPC(instance API, instance with source off, package-level helpers): failed on master withrecord.PC = {function:log file:logger.go line:216}, passes now.TestHandlerWrapperNeverSeesNilContext: fails when the nil-context guard is removed.Local verification
gofmt -l .empty (root, otel)go vet ./...clean (root, otel)go test -race ./...pass (root, otel)govulncheck ./...no vulnerabilities (root, otel)go test -bench .: identical B/op and allocs/op; ns/op equal or lowerPATCH: release as log v1.7.5.
🤖 Generated with Claude Code