Search code examples
google-cloud-platformgcloudstackdrivergoogle-cloud-stackdrivergoogle-cloud-error-reporting

Stackdriver error reporting with gcloud


I'm retying to use the gcloud cli to send events to StackDriver Error Reporting.
The (very limited) documentation is here: https://cloud.google.com/sdk/gcloud/reference/beta/error-reporting/events/report

Regardless of what I send as a message I seem to get this error:

ERROR: (gcloud.beta.error-reporting.events.report) INVALID_ARGUMENT: ReportedErrorEvent.context must contain a location unless message contain an exception or stacktrace.

I have tried formatting the message as a JSON representation of an error report: https://cloud.google.com/error-reporting/docs/formatting-error-messages but the message seems to be the same. Here's an example command and JSON:

gcloud beta error-reporting events report --service foo --message-file err.json

{
    "serviceContext": {
        "service": "foo"
    },
    "message": "Whoops!",
    "context": {
        "reportLocation": {
            "filePath": "/usr/local/bin/test",
            "lineNumber": 123,
            "functionName": "main"
        }
    }
}

Solution

  • The gcloud --message or --message-field argument is just the message field of the reported error, not the entire JSON. Since you can't provide the reportLocation via gcloud, message has to be a stack trace or exception.

    Using the API explorer with the original request works. Logging the error also makes its way into Error Reporting via:

    gcloud beta logging write --payload-type=json test-errors-log '
    {
        "serviceContext": {
            "service": "foo"
        },                        
        "message": "Whoops!",
        "context": {
            "reportLocation": {
                "filePath": "/usr/local/bin/test",
                "lineNumber": 123,
                "functionName": "main"
            }
        }
    }'