google-cloud-go: errorreporting: Stack incompatible with pkg/errors
Client
Error Reporting
Describe Your Environment
Go 1.10.1 on Ubuntu 18.04 (local development machine)
Use Case
type StackTracer interface {
StackTrace() errors.StackTrace
}
var (
projectID = flag.String("projectID", "", "")
credentialsFile = flag.String("credentialsFile", "", "")
)
func main() {
flag.Parse()
client, err := errorreporting.NewClient(ctx, *projectID, errorreporting.Config{
ServiceName: "test",
OnError: func(err error) {
log.Printf("Failed to report error: %+v", err)
},
}, option.WithCredentialsFile(*credentialsFile))
if err != nil {
panic(errors.Wrap(err, "failed to initialize error reporting client"))
}
// given a pkg/errors error
testErr := errors.New("hello there")
// report error without stack trace
err = errorReportingClient.ReportSync(ctx, errorreporting.Entry{
Error: testErr,
})
if err != nil {
panic(errors.Wrap(err, "failed to log error"))
}
// report error with stack trace
err = client.ReportSync(ctx, errorreporting.Entry{
Error: testErr,
Stack: []byte(fmt.Sprintf("%v", testErr.(StackTracer).StackTrace())),
})
if err != nil {
panic(errors.Wrap(err, "failed to log error with stack trace"))
}
}
Expected Behavior
Error gets reported successfully.
Actual Behavior
panic: failed to log error with stack trace: rpc error: code = InvalidArgument desc = ReportedErrorEvent.context must contain a location unless `message` contain an exception or stacktrace.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 19 (8 by maintainers)
We hacked together a formatter that Stackdriver seems happy with. Some frame parts (routine id, routine status, func args) are either hard-coded or omitted, but the important parts work. Note that
var ErrorReportingClient *errorreporting.Client
is initialized in another file in this package.