You can send application exceptions and error events to Error Reporting
so that Error Reporting can analyze error data in your
Google Cloud project. Depending on your compute environment, programming language,
and authentication requirements, you can collect error data in the following
ways:

- **Automatic log collection** : Supported compute environments automatically send error data to Cloud Logging for Error Reporting to analyze. For example, Cloud Run automatically sends exceptions written to `stderr` to Logging.
- **Client libraries**: You can instrument your application code with language-specific client libraries to send error reports directly from your app.
- **REST APIs**: You can call the Error Reporting API or the Cloud Logging API to write formatted error events and stack traces, including when you require API key authentication.

## When Error Reporting analyzes log entries

Error Reporting is a global service built on
Cloud Logging and can analyze log entries when all of the following are true:

- Assured workloads are disabled. For more information, see [Overview of Assured Workloads](https://docs.cloud.google.com/assured-workloads/docs/overview.md.txt).
- [Customer-managed encryption keys (CMEK)](https://docs.cloud.google.com/logging/docs/routing/managed-encryption-storage.md.txt) are disabled on all log buckets that store the log entry. Error Reporting can't store log entries in log buckets that have CMEK enabled. For information about how to determine the CMEK configuration for a log bucket, see [Verify key enablement](https://docs.cloud.google.com/logging/docs/routing/managed-encryption-storage.md.txt#verify-key).
- The log bucket satisfies one of the following:
  - The log bucket is stored in the same project where the log entries originated.
  - The log entries were routed to a project, and then that project stored those log entries in a log bucket that it owns.

<br />

## VPC Service Controls support

VPC Service Controls support Error Reporting.

To reduce the risk of data exfiltration, use VPC Service Controls to create
a service perimeter around your Google-managed services.
For information about VPC Service Controls and how to create a service
perimeter, see the
[VPC Service Controls documentation](https://docs.cloud.google.com/vpc-service-controls/docs.md.txt).

## Configure environments to automatically report error data

For information about environment-specific configuration requirements, see
the following guides:

- [App Engine flexible environment](https://docs.cloud.google.com/error-reporting/docs/setup/app-engine-flexible-environment.md.txt)
- [App Engine standard environment](https://docs.cloud.google.com/error-reporting/docs/setup/app-engine-standard-environment.md.txt)
- [Apps Script](https://docs.cloud.google.com/error-reporting/docs/setup/apps-script.md.txt)
- [Cloud Run functions](https://docs.cloud.google.com/error-reporting/docs/setup/cloud-functions.md.txt)
- [Cloud Run](https://docs.cloud.google.com/error-reporting/docs/setup/cloud-run.md.txt)
- [Compute Engine](https://docs.cloud.google.com/error-reporting/docs/setup/compute-engine.md.txt)
- [Google Kubernetes Engine](https://docs.cloud.google.com/error-reporting/docs/setup/kubernetes-engine.md.txt)
- [Amazon EC2](https://docs.cloud.google.com/error-reporting/docs/setup/ec2.md.txt)

## Instrument apps by using client libraries

For information about how to configure your application to send error reports,
see the language-specific configuration guides:

- [Go apps](https://docs.cloud.google.com/error-reporting/docs/setup/go.md.txt)
- [Java apps](https://docs.cloud.google.com/error-reporting/docs/setup/java.md.txt)
- [.NET apps](https://docs.cloud.google.com/error-reporting/docs/setup/dotnet.md.txt)
- [Node.js apps](https://docs.cloud.google.com/error-reporting/docs/setup/nodejs.md.txt)
- [Python apps](https://docs.cloud.google.com/error-reporting/docs/setup/python.md.txt)
- [PHP apps](https://docs.cloud.google.com/error-reporting/docs/setup/php.md.txt)
- [Ruby apps](https://docs.cloud.google.com/error-reporting/docs/setup/ruby.md.txt)

## Write error data by using an API

You can report error events to your Google Cloud project by
executing the Error Reporting API method
[`report`](https://docs.cloud.google.com/error-reporting/reference/rest/v1beta1/projects.events/report.md.txt) or the Logging API method
[`write`](https://docs.cloud.google.com/logging/docs/reference/v2/rest/v2/entries/write.md.txt).

- 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`](https://docs.cloud.google.com/error-reporting/reference/rest/v1beta1/projects.events/report.md.txt)
  and format the request body of the method as a
  [`ReportedErrorEvent`](https://docs.cloud.google.com/error-reporting/reference/rest/v1beta1/projects.events/report.md.txt#ReportedErrorEvent) object.

  When you use the Error Reporting API, log entries with properly
  formatted error messages are automatically generated and written to
  [Logging](https://docs.cloud.google.com/logging/docs.md.txt). 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
  Logging ingestion costs. To control which log entries are
  ingested, see [Exclusion filters](https://docs.cloud.google.com/logging/docs/routing/overview.md.txt#exclusions).
- If you want to use the Logging API, then you must format the
  [`LogEntry`](https://docs.cloud.google.com/logging/docs/api/reference/rest/v2/LogEntry) object so that it includes a stack trace
  or a [`ReportedErrorEvent`](https://docs.cloud.google.com/error-reporting/reference/rest/v1beta1/projects.events/report.md.txt#ReportedErrorEvent) object. For more information
  about the formatting requirements, see
  [Format errors in logs](https://docs.cloud.google.com/error-reporting/docs/formatting-error-messages.md.txt).