What is the minimum required JSON fields for a logged ERROR to end up in Google Cloud Error Reporting

82 Views Asked by At

The minimum JSON for a structured error message to be parsed in by google (i.e. be marked as debug/info/error/... in the GCP logs) is {"severity":"ERROR","message":"hello world"}. But this error will never pop up in GCP Error Reporting.

What is the minimum required fields for an error to actually show up in GCP Error Reporting?

2

There are 2 best solutions below

0
On BEST ANSWER

Take a look at Log an error event that is a text message. Of notable important is the @type field. If you aren't providing a stack_trace then Error Reporting is looking for more information in order to group the error.

0
On

This will result in a instance in Error Reporting:

{
  "severity": "ERROR",
  "message": "hello error",
  "@type": "type.googleapis.com/google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent"
}

(severity is not taken into consideration, I managed to get a INFO severity "error" into Error Reporting)

This will also result in a message in Error Reporting:

{
  "severity": "ERROR",
  "message": "hello error",
  "stack_trace": "goroutine 8 [running]:\nmain.main.func2({0x6f0948, 0xc0000d6000}, 0xc0000b6700)\n\t/app/main.go:42 +0x6c\nnet/http.HandlerFunc.ServeHTTP(0xc000045af0?, {0x6f0948?, 0xc0000d6000?}, 0x0?)\n\t/usr/local/go/src/net/http/server.go:2109 +0x2f\nnet/http.(*ServeMux).ServeHTTP(0x0?, {0x6f0948, 0xc0000d6000}, 0xc0000b6700)\n\t/usr/local/go/src/net/http/server.go:2487 +0x149\nnet/http.serverHandler.ServeHTTP({0xc00006d0e0?}, {0x6f0948, 0xc0000d6000}, 0xc0000b6700)\n\t/usr/local/go/src/net/http/server.go:2947 +0x30c\nnet/http.(*con"
}

BUT; this will not end up as a ERROR in Error Reporting:

{
  "severity": "ERROR",
  "message": "hello error",
  "stack_trace": "fake stack trace"
}

NB: All the JSON messages here are pretty printed, it is important that the JSON you print in your app is on a single line to work with structured logging.

NB2: If you want your errors to be grouped by the service that made them you need to add serviceContext. E.g.

"serviceContext":{"service":"service-name"}