fix(slog): disable automatic logging of stacktraces for errors#464
fix(slog): disable automatic logging of stacktraces for errors#464
Conversation
There was a problem hiding this comment.
I was curious because you mentioned the panic-check handler, seems like there's a bug in there:
gorouter/handlers/paniccheck.go
Line 44 in a34e690
From runtime.StartTrace:
StartTrace enables tracing for the current process.
that doesn't sound right. It should probably call runtime/debug.Stack. Without your change this is not noticed because the stack-trace is emitted either way, but by merging this there will be no stack-trace anymore. And if you don't mind, a test to ensure the panic-check handler emits the stack trace would probably be a good idea as well 😅
Edit: An alternative approach could be to log at ErrorLevel+1 to trigger the stack-trace again and use it as a replacement for the previous PanicLevel.
|
+100. Will add the check for the panic check handler outputting a proper stack trace, not just the field named |
The slog handler for Zap is configured to automatically emit stack traces at "Error" level. In pure Zap, stack traces are added via option AddStacktrace, which was not used before the move to slog. The Zap slog handler has a mapping from Zap levels to slog levels, and does not emit values above slog.LevelError. By setting the limit for automatically added stack traces via slog to ErrorLevel + 1, this effectively disables automatic stack traces. The `panic-check` handler that catches and logs panics in handlers remains unaffected, as it explicitly logs a field called "stacktrace", as it did with pure Zap. Related: #435
5a11bb0 to
e3aa65d
Compare
|
@maxmoehl, I've applied the change you mention and ensure in the |
The slog handler for Zap is configured to automatically emit stack traces at "Error" level.
In pure Zap, stack traces are added via option AddStacktrace, which was not used before the move to slog.
The Zap slog handler has a mapping from Zap levels to slog levels, and does not emit values above slog.LevelError. By setting the limit for automatically added stack traces via slog to ErrorLevel + 1, this effectively disables automatic stack traces.
The
panic-checkhandler that catches and logs panics in handlers remains unaffected, as it explicitly logs a field called "stacktrace", as it did with pure Zap.Related: #435
Breaking change: No. This is restoring the behavior we had with the pure zap logger / logger wrappers.