Search code examples
stackdrivergoogle-apis-explorergoogle-cloud-error-reporting

INVALID_ARGUMENT (400 error) when calling Stackdriver Error Reporting API


When trying to invoke the Stackdriver Error Reporting API (via the API explorer or via the Client-Side JavaScript library), I receive the following error:

Request:

{ "message" : "test" }

Response:

{
  "error": {
    "code": 400,
    "message": "Request contains an invalid argument.",
    "status": "INVALID_ARGUMENT"
  }
}

The Stackdriver Error Reporting API is enabled and I have Owner rights to the App Engine project.

Is the API simply not functional? If I'm doing something wrong, can someone try to help?


Solution

  • The documentation for reporting events says that a ServiceContext is required.

    If you're only sending a message (not a stacktrace / exception) you'll need to include a context with a reportLocation as well. This is noted in the documentation of the message field, but it's not obvious.

    The following works from the API explorer:

    {
     "context": {
      "reportLocation": {
       "functionName": "My Function"
      }
     },
     "message": "error message",
     "serviceContext": {
      "service": "My Microservice",
     }
    }
    

    You might be interested in the docs on How Error are Grouped too.

    FWIW, I work on this product and I think the error message is too generic. The problem is (?) that the serving stack scrubs the message unless they're annotated as being for public consumption. I'll chase that down.