Codebase list golang-go.uber-zap / 416e66a
Remove unused code to ignore runtime stack frames (#493) `runtime.CallerFrames` is currently ignoring the last frame, which is always `runtime.main` (for the main goroutine) and `runtime.goexit` (for additional goroutines). Since the main goroutine will include the user's main function, this is noise that doesn't add much value. We had special logic to ignore these runtime frames specifically, but it's not required since it's only ever the very last stack frame and we already ignore the last frame. Prashant Varanasi authored 6 years ago GitHub committed 6 years ago
1 changed file(s) with 4 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
3030 const _zapPackage = "go.uber.org/zap"
3131
3232 var (
33 _stacktraceIgnorePrefixes = []string{
34 "runtime.goexit",
35 "runtime.main",
36 }
3733 _stacktracePool = sync.Pool{
3834 New: func() interface{} {
3935 return newProgramCounters(64)
6864 i := 0
6965 skipZapFrames := true // skip all consecutive zap frames at the beginning.
7066 frames := runtime.CallersFrames(programCounters.pcs[:numFrames])
67
68 // Note: On the last iteration, frames.Next() returns false, with a valid
69 // frame, but we ignore this frame. The last frame is a a runtime frame which
70 // adds noise, since it's only either runtime.main or runtime.goexit.
7171 for frame, more := frames.Next(); more; frame, more = frames.Next() {
72 if shouldIgnoreStacktraceFunction(frame.Function) {
73 continue
74 }
7572 if skipZapFrames && isZapFrame(frame.Function) {
7673 continue
7774 } else {
111108 return false
112109 }
113110
114 func shouldIgnoreStacktraceFunction(function string) bool {
115 for _, prefix := range _stacktraceIgnorePrefixes {
116 if strings.HasPrefix(function, prefix) {
117 return true
118 }
119 }
120 return false
121 }
122
123111 type programCounters struct {
124112 pcs []uintptr
125113 }