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

Remove first four calls of stacktrace #308

Closed
bufdev opened this issue Feb 17, 2017 · 3 comments
Closed

Remove first four calls of stacktrace #308

bufdev opened this issue Feb 17, 2017 · 3 comments

Comments

@bufdev
Copy link
Contributor

bufdev commented Feb 17, 2017

When you get a stacktrace, it will always return:

go.uber.org/zap.takeStacktrace(0xc42005d000, 0x400, 0x400, 0x0, 0x0, 0xc4200f9901)
	/Users/peteredge/gocode/src/go.uber.org/zap/stacktrace.go:33 +0x64
go.uber.org/zap.Stack(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/Users/peteredge/gocode/src/go.uber.org/zap/field.go:197 +0x7a
go.uber.org/zap.(*Logger).check(0xc420072300, 0x1, 0x12969d2, 0x4, 0xc4200784c0)
	/Users/peteredge/gocode/src/go.uber.org/zap/logger.go:254 +0x212
go.uber.org/zap.(*Logger).Warn(0xc420072300, 0x12969d2, 0x4, 0xc4200784c0, 0x1, 0x1)
	/Users/peteredge/gocode/src/go.uber.org/zap/logger.go:154 +0x44

This doesn't have much use to the user, so we should try to remove these. This might be a little tricky, I'll look into it at some point.

akshayjshah pushed a commit that referenced this issue Mar 7, 2017
Remove `runtime.goexit`, `runtime.main`, and some zap frames from our stacktraces. Since we're now formatting our own traces, we also get a *big* performance win: nearly 5x faster and half the number of bytes allocated!

Current master:

```
BenchmarkStackField-4             200000              9587 ns/op             960 B/op          2 allocs/op
```

After this PR:

```
BenchmarkStackField-4             500000              2149 ns/op             448 B/op          2 allocs/op
```

Fixes #308.
@enjoylife
Copy link

enjoylife commented May 3, 2017

@akshayjshah I'm not sure if this is a regression or the intended behavior, but I'm still seeing a large number of frames being returned.

Heres an example call to zap.S().Error from some application code of mine.

2017-05-02T22:03:11.186-0700	ERROR	config/postgres.go:32	Unable to connect to postgres database{error 25 0  dial tcp [::1]:5432: getsockopt: connection refused} {config 2 0  postgresql://gecko_admin:devpass@localhost:%!d(string=5433)}	{"app_name": "ProjectGecko", "version": "0.1.0"}
go.uber.org/zap.Stack
	/Users/matt/Programming/GoDevel/src/go.uber.org/zap/field.go:209
go.uber.org/zap.(*Logger).check
	/Users/matt/Programming/GoDevel/src/go.uber.org/zap/logger.go:273
go.uber.org/zap.(*Logger).Check
	/Users/matt/Programming/GoDevel/src/go.uber.org/zap/logger.go:146
go.uber.org/zap.(*SugaredLogger).log
	/Users/matt/Programming/GoDevel/src/go.uber.org/zap/sugar.go:223
go.uber.org/zap.(*SugaredLogger).Error
	/Users/matt/Programming/GoDevel/src/go.uber.org/zap/sugar.go:102
gecko/config.SetupPostgres
	/Users/matt/Programming/ProjectGecko/src/api/src/gecko/config/postgres.go:32
main.main
	/Users/matt/Programming/ProjectGecko/src/api/server.go:40

My assumption is that those zap specific lines are supposed filtered out. Is that your assumption too, @peter-edge ?

Taking a quick peek at the zap code, I see in stacktrace.go the array called _stacktraceIgnorePrefixes which holds the list of prefixes that get filtered.

My current quick fix is just to add "go.uber.org/zap" to this list which removes the noise from my logs.

I took a look at #311 and the test cases but I can't tell what the intended behavior exactly is.
I have a feeling my quick fix probably filters out too much for other applications and for uber, but it works for my small use case.

@Till--H
Copy link

Till--H commented Jun 29, 2017

Any update on this one? My logs are also full of stack frames from within zap. It would be great if they're filtered out.

@prashantv
Copy link
Collaborator

The original issue was to filter out runtime stacks, and the very last zap stacktraces. I've filed a separate issue #488 to discuss whether all zap stack frames should be removed.

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

No branches or pull requests

5 participants