Issue
I want to integrate Sentry into my Firebase cloud functions. I couldn't understand the right approach here and then I saw your note in the Google Cloud Functions doc:
Is it still accurate? Do you have an answer for when it will be supported? Is there any workaround we can do for now?
Applies To
- All SaaS Customers and Self-Hosted Users
- Javascript Platform
Resolution
The note is still accurate. At this time, our JavaScript Serverless SDK doesn’t officially support Cloud Functions for Firebase. We don’t have a firm ETA on adding full support, but it’s on our radar.
As a workaround, you can use the standard Sentry Node SDK to manually capture errors in your Firebase Cloud Functions. For example, you can initialize Sentry with @sentry/node
and then wrap your function code to capture exceptions. Make sure to call Sentry.flush()
(with an appropriate timeout) before your function completes to ensure that events are sent.
Something like the following:
Sentry.init({
dsn: 'YOUR_SENTRY_DSN',
// Other configuration options
});
export const sendEmail = functions.firestore
.document('users/{userId}')
.onCreate(async (snap, context) => {
try {
doSomething(); // Your logic here
} catch (error) {
Sentry.captureException(error);
// Flush Sentry events before rethrowing
await Sentry.flush(2000);
throw error;
}
});
With this, you first throw the error so you can catch it and send it to Sentry, and then you re-throw it so that the Cloud Function is marked as failed.