Format a log entry to report error events

This document explains how to format the log entry when you want to use Cloud Logging to report error events.

You can report error events to your Google Cloud project by executing the Cloud Logging API method write or the Error Reporting API method report. When you report error events by using the Cloud Logging API, then request body contains a LogEntry object that must include a stack trace, or a ReportedErrorEvent object.

Before you begin

  • Follow the setup instructions for your language and platform.

  • If you require API key-based authentication, then you must use the Error Reporting API. To report an error event by using the Error Reporting API, execute the method report and format the request body of the method as a ReportedErrorEvent object.

    When you use the Error Reporting API, log entries with properly formatted error messages are automatically generated and written to Cloud Logging. These log entries are written to a log whose logName is formatted as follows:

    projects/PROJECT_ID/clouderrorreporting.googleapis.com%2Freported_errors
    

    Because log entries are generated by calls to report, you might incur Cloud Logging ingestion costs. To control which log entries are ingested, see Exclusion filters.

    If you report error events by using the Error Reporting API, the remainder of this document doesn't apply.

LogEntry format requirements

This section describes how to format a LogEntry so that Error Reporting captures the error event that is contained in the log entry.

Log a stack trace

To log an error event that is a stack trace, write the error event as one of these types:

  • A multi-line textPayload.
  • A jsonPayload that includes a message, stack_trace, or exception field.

    You can specify more than one of those fields. If more than one of those fields is specified, then the order of evaluation is: stack_trace, then exception, and then message.

    If the message field is evaluated and if it isn't empty, then the stack trace is captured only when the field contains a stack trace in