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

svc1log caller pkg functions are not module aware #116

Open
tabboud opened this issue Jan 14, 2021 · 0 comments · May be fixed by #117
Open

svc1log caller pkg functions are not module aware #116

tabboud opened this issue Jan 14, 2021 · 0 comments · May be fixed by #117

Comments

@tabboud
Copy link
Contributor

tabboud commented Jan 14, 2021

What happened?

All svc1log functions that determine the origin based off of the call stack are not module aware.
The internal function initLineCaller gets the filename and line number of the calling function via the runtime.Caller method and then uses a simple heuristic to remove the GOPATH specific prefix of /src/. Removing the GOPATH prefix does not work for projects that use go modules, since they no longer need to be rooted in the GOPATH, which then results in an incorrect pkg based origin.
For example, if GOPATH=/home/tabboud/go/src, the following will be returned for the svc1log.CallerPkg(0, 1) function call from the test-repo/server/server.go file:

// Inside GOPATH: /home/tabboud/go/src/github.com/tabboud/test-repo/server/server.go
// returns "github.com/tabboud/test-repo"

// Outside GOPATH: /home/tabboud/test-repo/server/server.go
// returns "/home/tabboud/test-repo"

What did you want to happen?

The return value should be "github.com/tabboud/test-repo", no matter if the repo was in or out of the GOPATH.

@tabboud tabboud changed the title svc1log origin functions are not module aware svc1log caller pkg functions are not module aware Jan 14, 2021
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 a pull request may close this issue.

1 participant