user5156141
user5156141

Reputation: 684

Google Stackdriver Error Reporting API - Include Custom Data

I need to include a custom data object/JSON string with an error report, without losing the stacktrace that Stackdriver seems to capture. Setting a JSON string as the message doesn't seem like an ideal solution.

I have seen references to a jsonPayload key online, but haven't had success setting it in the report.

In the Node.js systems I am integrating Stackdriver into (via logging client), I have a logger function that accepts additional data about the environment, the error stack and any supporting data that led to the error, and I wish to include this with the report so that they can be quickly investigated.

I have instead had to use the Google Stackdriver Logging API to handle this in the interim, but I find the metrics viewer a little convoluted and it's also hard to keep track of which logs have been dealt with.

I saw a stale question on this previously, but didn't want to hijack it. Nor did it have any solution.

Hoping there's a solution!

Upvotes: 2

Views: 474

Answers (1)

Nakilon
Nakilon

Reputation: 35074

What I do is storing custom payload to Datastore and put the link to Datastore viewer to the error exception message. Here is for example how it looks in Ruby (the method stores url and html strings that I need for debug as attributes of the Datastore entity of kind exception_details):

def report_error url, html
  begin
    raise "https://console.cloud.google.com/datastore/entities/query/gql?gql=#{
            CGI.escape "SELECT * FROM exception_details WHERE __key__=Key(exception_details, #{
              Datastore.save( Datastore.entity("exception_details") do |error|
                error["url"] = url
                error["html"] = html
                error.exclude_from_indexes! "html", true
              end ).first.key.id
            })"
          }"
  rescue => e
    Google::Cloud::ErrorReporting.report e
  end
end

Here is an email I get:

enter image description here

Instead of clicking the blue button I visit the hyperlink where I can now inspect the html variable that I stored:

enter image description here

Upvotes: 2

Related Questions