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

CallerSkip does not apply to stacktraces captured by zap #512

Closed
prashantv opened this issue Oct 11, 2017 · 4 comments · Fixed by #843
Closed

CallerSkip does not apply to stacktraces captured by zap #512

prashantv opened this issue Oct 11, 2017 · 4 comments · Fixed by #843

Comments

@prashantv
Copy link
Collaborator

Currently, logging wrappers use CallerSkip to avoid the logging wrapper showing up as the caller. However, this is not used by stacktraces, so we end up with the logging wrappers showing up in stacktraces.

@akshayjshah: I'm thinking we should respect caller skip in stacktraces as well, any thoughts?

boz added a commit to boz/zap that referenced this issue Nov 3, 2017
 * Skip frames as configured in stacktraces
 * Add `StackSkip()` to manually retrieved a pruned stacktrace
 * Remove "zip" package pruning in `takeStacktrace()`

 fixes uber-go#512
boz added a commit to boz/zap that referenced this issue Nov 3, 2017
 * Skip frames as configured in stacktraces
 * Add `StackSkip()` to manually retrieved a pruned stacktrace
 * Remove "zip" package pruning in `takeStacktrace()`

 fixes uber-go#512
boz added a commit to boz/zap that referenced this issue Nov 9, 2017
 * Skip frames as configured in stacktraces
 * Add `StackSkip()` to manually retrieved a pruned stacktrace
 * Remove "zip" package pruning in `takeStacktrace()`

 fixes uber-go#512
boz added a commit to boz/zap that referenced this issue Nov 10, 2017
 * Honor StackSkip option when including stacktrace.
 * Replace package-based stack pruning - the same behavior is achieved by
   skipping frames appropriately.

 fixes uber-go#512
boz added a commit to boz/zap that referenced this issue Nov 10, 2017
 * Honor StackSkip option when including stacktrace.
 * Replace package-based stack pruning - the same behavior is achieved by
   skipping frames appropriately.

 fixes uber-go#512
@akshayjshah
Copy link
Contributor

On balance, I'd prefer to leave the stacktraces as complete as possible. Managing caller skips is really finicky - we've made mistakes ourselves when wrapping and unwrapping loggers internally. It's not the end of the world when the caller reported in the logs is incorrect, but it'd be a real pain if we mistakenly trimmed off too many stack frames.

Even the trimming functionality we have today is a bit unusual - most other libraries I've seen (including ones in other languages) seem to bias toward more-complete stack traces. Sentry and similar tools highlight stack frames from the application code, so I don't think including extra information is too harmful.

I'll leave this open for a bit longer so we can ruminate.

@liu-xuewen
Copy link

I think it's very nice. This is very important. because the invalid log is too much. @akshayjshah It is not very convenient to find bug.

@dan-j
Copy link

dan-j commented Dec 19, 2019

I know this is an old issue, but I've just been reading through this and reviewed what #525 was trying to achieve.

I understand why the PR was closed, but how about an alternative solution of allowing users to add custom prefixes to omit from stacktraces? This would mean there wouldn't be any breaking changes to existing users as it would be opt-in by providing said prefixes.

For context, I'm using https://github.com/go-logr/zapr and would like to omit the stacks from this wrapper, similar to the OP

@prashantv
Copy link
Collaborator Author

While we can add the ability to omit specific prefixes, I think it may be better to align the caller skip with the stack trace collection, so users don't have to opt-in to prefix stripping, as well as increasing the caller skip.

segevfiner added a commit to segevfiner/zap that referenced this issue Jun 23, 2020
* UseCallerSkipForStacktrace configures the Logger to honor CallerSkip
when taking stacktraces.
* StackSkip is similar to Stack but allows
skipping frames from the top of the stack

Fixes uber-go#512, fixes uber-go#727
prashantv pushed a commit that referenced this issue Aug 18, 2020
…843)

* Honor `CallerSkip` when taking a stack trace. Both the caller and stack trace will now point to the same frame.
* Add `StackSkip` which is similar to `Stack` but allows skipping frames from the top of the stack.

This removes the internal behavior of skipping zap specific stack frames when taking a stack trace, and instead relies on the same behavior used to calculate the number of frames to skip for getting the caller to also skip frames in the stack trace.

Fixes #512, fixes #727
cgxxv pushed a commit to cgxxv/zap that referenced this issue Mar 25, 2022
…ber-go#843)

* Honor `CallerSkip` when taking a stack trace. Both the caller and stack trace will now point to the same frame.
* Add `StackSkip` which is similar to `Stack` but allows skipping frames from the top of the stack.

This removes the internal behavior of skipping zap specific stack frames when taking a stack trace, and instead relies on the same behavior used to calculate the number of frames to skip for getting the caller to also skip frames in the stack trace.

Fixes uber-go#512, fixes uber-go#727
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants