Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect caller when logs originate from modules with a major version suffix #1209

Open
deitrix opened this issue Dec 1, 2022 · 1 comment

Comments

@deitrix
Copy link

deitrix commented Dec 1, 2022

When using the logger in a Go module with a major version suffix, the package name is omitted, leaving only the version. In this case v2@v2.0.3. I would expect this to be go-pkg/v2@v2.0.3.
go.mod:

module github.com/me/go-pkg/v2

go 1.19

require go.uber.org/zap v1.24.0

log.go:

package pkg

import (
	"go.uber.org/zap"
)

func LogSomething() {
	logger, _ := zap.NewProduction(zap.AddCaller())
	logger.Info("logging from library")
}

Using the above library in another Go project:

package main

import "github.com/me/go-pkg/v2"

func main() {
	pkg.LogSomething()
}

Results in the following log:

{"level":"info","ts":1669917064.3370209,"caller":"v2@v2.0.3/pkg.go:9","msg":"logging from library"}
@deitrix deitrix changed the title Incorrect caller when used in a package with a major version greater than v1 Incorrect caller when used in a Go module with a version suffix Dec 1, 2022
@deitrix deitrix changed the title Incorrect caller when used in a Go module with a version suffix Incorrect caller when logs originate from modules with a major version suffix Dec 1, 2022
@prashantv
Copy link
Collaborator

This is caused by the logic in TrimmedPath which drops all but the final directory name. v2 is just another path of the package.

To solve this, we'd need a bit of a hack -- if we see v<N>@v<N>. at the beginning of the last directory path, we assume it's a version and use the previous / to get the directory instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants