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

stacktrace: skip frames #525

Closed
wants to merge 1 commit into from
Closed

stacktrace: skip frames #525

wants to merge 1 commit into from

Conversation

boz
Copy link

@boz boz commented Nov 3, 2017

  • Honor StackSkip option when including stacktrace.
  • Replace package-based stack pruning - the same behavior is achieved by
    skipping frames appropriately.

fixes #512

@CLAassistant
Copy link

CLAassistant commented Nov 3, 2017

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Nov 3, 2017

Codecov Report

Merging #525 into master will decrease coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #525      +/-   ##
==========================================
- Coverage   97.06%   97.03%   -0.03%     
==========================================
  Files          39       39              
  Lines        2279     2262      -17     
==========================================
- Hits         2212     2195      -17     
  Misses         59       59              
  Partials        8        8
Impacted Files Coverage Δ
stacktrace.go 97.5% <100%> (-0.81%) ⬇️
field.go 100% <100%> (ø) ⬆️
logger.go 94.85% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f85c78b...99b0edf. Read the comment docs.

@boz
Copy link
Author

boz commented Nov 9, 2017

Hi @prashantv, @akshayjshah. Any thoughts on this?

Thanks!

field.go Outdated
// stack frames via the skip argument.
//
// StackSkip("foo",0) is equivalent to Stack("foo").
func StackSkip(key string, skip int) zapcore.Field {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we should expose this right now -- I'd prefer to keep just Stack for now and think about whether we really need the skip version separately.

stacktrace.go Outdated
buffer := bufferpool.Get()
defer buffer.Free()
programCounters := _stacktracePool.Get().(*programCounters)
defer _stacktracePool.Put(programCounters)

var numFrames int
skip += 2
for {
// Skip the call to runtime.Counters and takeStacktrace so that the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move this comment to where we do += 2


assert.True(t, len(frames) > 6)

// The logging function should be the first frame ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of testing partially, can we just test the entire result of frames?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, added. I was worried it'd be too brittle.

@@ -63,19 +56,12 @@ func takeStacktrace() string {
}

i := 0
skipZapFrames := true // skip all consecutive zap frames at the beginning.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behaviour was added on purpose, any reason why we're deleting this logic?

@prashantv
Copy link
Collaborator

Thanks for the contribution @boz

Can you provide more context about why we're removing the zap stacktrace pruning?

 * 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
Copy link
Author

boz commented Nov 10, 2017

Hi @prashantv

As far as I can tell, accounting for frames correctly with skip and zap.StackSkip() achieves the same thing that the name-based frame skipping did. I might be missing something, tho.

@akshayjshah
Copy link
Contributor

akshayjshah commented Apr 11, 2018

Today, the offset for determining callers is separate from the stack-pruning behavior. That means that it's entirely possible to use a logger that never includes the calling function, but does occasionally log stacktraces. In that case, the caller skip likely wouldn't be configured, but stacktraces would still prune zap's internals. Merging this change would begin including zap's internals in the stacktraces, which would be unfortunate. Strictly speaking, that means that this change isn't backward-compatible (even though it does make the implementation simpler) :/

@akshayjshah
Copy link
Contributor

This has been open for a long time, and I'd prefer not to introduce even small backward-incompatible changes if they're not absolutely necessary. For housekeeping, I'm going to close this PR - @boz, happy to discuss further if you want to re-open it.

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

Successfully merging this pull request may close these issues.

CallerSkip does not apply to stacktraces captured by zap
4 participants