Firebase offers two options for configuring alerts and sending them to custom notification channels.
(Recommended) Set up and send custom alerts to custom notification channels
You can use Cloud Monitoring to send fully customized alerts to custom notification channels based on Crashlytics data and (optionally) Firebase sessions data that you've exported to Cloud Logging.
Send default Crashlytics alerts to custom notification channels
You can use Cloud Functions to send the default Crashlytics alerts to custom notification channels.
(Recommended) Set up and send custom alerts to custom notification channels
Firebase offers default Crashlytics alerts (see the alerting overview page). However, these default alerts and their notification channels may not be sufficient for your needs.
In these cases, you can use Cloud Monitoring to send custom alerts to custom notification channels based on Crashlytics data in Cloud Logging, which is automatically sent for web apps or exported for mobile apps (along with optional Firebase sessions data).
To use Cloud Monitoring for custom alerts, you set up an alerting policy, which describes the circumstances under which you want to be alerted and how you want to be notified.
For example, if your crash-free rate goes below a specific threshold or your web app error rate spikes, Cloud Monitoring can send a customized alert message to a specific email address or post it to a third-party service, like Discord, Slack, PagerDuty, or Jira. You can also fully customize the information sent in the alert, like including helpful deep-links into the Firebase console or company-specific troubleshooting information.
In the Google Cloud documentation, learn more about Cloud Monitoring and alerts, including pricing.
Prerequisites
Make sure your Firebase project is on the pay-as-you-go Blaze pricing plan.
Ensure your Crashlytics logs are available in Cloud Logging:
- For mobile apps: Set up export to Cloud Logging of Crashlytics data and (optionally) Firebase sessions data.
- For web apps: Logs (
firebasetelemetry.googleapis.com/events) are automatically sent to Cloud Logging when you set up Crashlytics in your web app.
Set up an alerting policy
The following are high-level instructions; for detailed instructions, see the Google Cloud documentation (for example: Create metric-threshold alerting policies or Use PromQL to create alerting policies).
As part of running queries, you can set up either a log-based alert or a SQL-based alert:
Set up a log-based alert:
Run a query in Logs Explorer.
Click the Add alert button that appears.
Follow the on-screen instructions to add a log-based alert.
Set up a SQL-based alert:
Run a query in Logs Analytics.
Click the Add alert button that appears.
Follow the on-screen instructions to add a SQL-based alert.
Alternatively, you can set up alerts for your log-based metrics by using the policy configuration tool in the Google Cloud console, where you can choose one of the following options:
Builder: The console UI provides a guided workflow to build the alerting policy.
For web apps, you can create a log-based counter metric on your Crashlytics web logs in Cloud Logging and configure a threshold alert using the Builder:
- In the Google Cloud console, go to Logging > Log-based Metrics, and then click Create Metric.
- Select Counter as the metric type and name your metric (for example,
web_crashlytics_errors). In the Build filter box, enter the following LQL query to count incoming web error records:
logName="projects/PROJECT_ID/logs/firebasetelemetry.googleapis.com%2Fevents" severity=ERRORClick Create Metric.
From the newly created metric's Actions menu (three vertical dots), select Create alert from metric.
Set the Rolling window (for example,
5 min) and Rolling window function (rateorcount), choose Above threshold as the condition type, and select your notification channels (such as email, Slack, PagerDuty, or webhooks).
PromQL: You provide a PromQL query for your alerting policy
For example, say that you've created two log-based metrics for your exported Crashlytics and Firebase sessions data:
One metric named
firebase/crashlytics_eventswith a label oferrorType, and it's defined as:logName="projects/PROJECT_ID/logs/firebasecrashlytics.googleapis.com%2Fevents"Another metric named
firebase/session_eventswith a label ofeventType, and it's defined as:logName="projects/PROJECT_ID/logs/firebasecrashlytics.googleapis.com%2Fsession_events"
Here's an example PromQL query using these log-based metrics to alert when your crash-free drops below 70%:
1 - (sum by (project_id) (rate({__name__="logging.googleapis.com/user/firebase/crashlytics_events", errorType="FATAL"}[5m])) / sum by (project_id) (rate({__name__="logging.googleapis.com/user/firebase/session_events", eventType="SESSION_START"}[5m])) ) < 0.7
Send default Crashlytics alerts to custom notification channels
Firebase offers default Crashlytics alerts (see the list on the alerting options overview page). However, the information in these default alerts and their notification channels may not be sufficient for your needs.
In these cases, you can use Cloud Functions for Firebase to send these default Crashlytics alerts to custom notification channels. For example, you can write a function that captures an alert event for velocity alerts and posts the alert information to a third-party service, like Discord, Slack, or Jira.
With this advanced alerting mechanism, you can also customize the information sent to the third-party service. For example, in addition to the default information provided by Firebase, you can also include helpful deep-links into the Firebase console or company-specific troubleshooting information.
To set up advanced alerting capabilities using Cloud Functions for Firebase, follow these steps:
Set up Cloud Functions for Firebase, which includes the following tasks:
- Set up a development environment for Node.js or Python.
- Install and sign into the Firebase CLI.
- Initialize Cloud Functions for Firebase using the Firebase CLI.
Write and deploy a function that captures an alert event from Crashlytics and handles the event payload (for example, posts the alert information in a message on Discord).
To learn about all the Crashlytics alert events that you can capture, go to the reference documentation for Crashlytics alerts.
Learn more about handling Crashlytics alerts using Cloud Functions for Firebase