This may be a long shot, but I wonder if it would be worth while to add json.Marshaler support for stack traces, to make it easier to pass stack traces to, for instance, logrus.
I'm thinking that implementing the json.Marshaler interface on the errors.Frame type might be the best approach. This would make it possible to log a stack trace as simply as:
if stackErr, ok := err.(stackTracer); ok {
log.WithField("stacktrace", stackErr.StackTrace())
}
and the JSON output ought to be a nice array of stack trace frames.
This would of course raise the question of precisely how to format these frames. I'm using my own implementation now which is essentially the %+v format verb's output, without newlines and tabs. Whatever format is chosen, consumers would be free to write their own marshaler and wrap the type, if necessary for special use cases.
Are there any drawbacks to this? Other thoughts or considerations?
This may be a long shot, but I wonder if it would be worth while to add
json.Marshaler
support for stack traces, to make it easier to pass stack traces to, for instance, logrus.I'm thinking that implementing the
json.Marshaler
interface on theerrors.Frame
type might be the best approach. This would make it possible to log a stack trace as simply as:and the JSON output ought to be a nice array of stack trace frames.
This would of course raise the question of precisely how to format these frames. I'm using my own implementation now which is essentially the
%+v
format verb's output, without newlines and tabs. Whatever format is chosen, consumers would be free to write their own marshaler and wrap the type, if necessary for special use cases.Are there any drawbacks to this? Other thoughts or considerations?