Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Firebase
description: "Adds instrumentation for Firebase. (default)"
supported:
- javascript.node
- javascript.firebase
- javascript.gcp-functions
- javascript.astro
- javascript.bun
Expand Down
1 change: 1 addition & 0 deletions docs/platforms/javascript/common/install/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ notSupported:
- javascript.cordova
- javascript.electron
- javascript.ember
- javascript.firebase
- javascript.gatsby
- javascript.nextjs
- javascript.nuxt
Expand Down
196 changes: 196 additions & 0 deletions docs/platforms/javascript/guides/firebase/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
---
title: Cloud Functions for Firebase
description: Learn how to set up Sentry in your Cloud Functions for Firebase project and capture your first errors.
sdk: sentry.javascript.node
fallbackGuide: javascript.node
categories:
- javascript
- server
- server-node
- serverless
---

<PlatformContent includePath="getting-started-primer" />

[Cloud Functions for Firebase](https://firebase.google.com/docs/functions) let you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. Sentry's Node SDK works out of the box with Cloud Functions for Firebase.

## What's Instrumented

The Sentry SDK includes a built-in <PlatformLink to="/configuration/integrations/firebase">Firebase integration</PlatformLink> that automatically instruments:

- **Cloud Functions** - HTTP functions, background functions, and event triggers
- **[Firestore](https://firebase.google.com/docs/firestore)** - Database operations like reads, writes, and queries are instrumented out of the box

This integration is enabled by default, so you get automatic performance monitoring and error tracking without any additional configuration.

<PlatformContent includePath="getting-started-prerequisites" />

## Step 1: Install

Choose the features you want to configure, and this guide will show you how:

<OnboardingOptionButtons
options={["error-monitoring", "performance", "profiling", "logs"]}
/>

<PlatformContent includePath="getting-started-features-expandable" />

### Install the Sentry SDK

Run the command for your preferred package manager to add the Sentry SDK to your Firebase Functions project:

```bash {tabTitle:npm}
npm install @sentry/node --save
```

```bash {tabTitle:yarn}
yarn add @sentry/node
```

```bash {tabTitle:pnpm}
pnpm add @sentry/node
```

## Step 2: Configure

Create an initialization file (for example, `instrument.js`) that imports and initializes Sentry. This file must be imported at the very top of your functions entry point, before any other imports.

```javascript {filename:instrument.js}
const Sentry = require("@sentry/node");

Sentry.init({
dsn: "___PUBLIC_DSN___",

// Adds request headers and IP for users, for more info visit:
// https://docs.sentry.io/platforms/javascript/guides/firebase/configuration/options/#sendDefaultPii
sendDefaultPii: true,
// ___PRODUCT_OPTION_START___ performance

// Add Tracing by setting tracesSampleRate
// Set tracesSampleRate to 1.0 to capture 100% of transactions
// We recommend adjusting this value in production
// Learn more at
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
tracesSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ performance
// ___PRODUCT_OPTION_START___ profiling

// Set profilesSampleRate to 1.0 to profile 100% of sampled transactions.
// This is relative to tracesSampleRate
profilesSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ profiling
// ___PRODUCT_OPTION_START___ logs
// Enable logs to be sent to Sentry
enableLogs: true,
// ___PRODUCT_OPTION_END___ logs
});
```

Import the initialization file at the very top of your functions entry point (for example, `index.js`), before any other imports:

```javascript {filename:index.js}
require("./instrument"); // Require Sentry initialization first

const { onRequest } = require("firebase-functions/https");
const { onDocumentCreated } = require("firebase-functions/firestore");
const admin = require("firebase-admin");

admin.initializeApp();

// HTTP function - automatically instrumented
exports.helloWorld = onRequest(async (request, response) => {
response.send("Hello from Firebase!");
});

// Firestore trigger - automatically instrumented
exports.onUserCreated = onDocumentCreated(
"users/{userId}",
async (event) => {
const userId = event.params.userId;
// Your logic here
}
);
```

<Alert>
The key is to import the initialization file **before** any other `require` calls,
including Firebase imports. This ensures Sentry can properly instrument all
modules.
</Alert>

## Step 3: Add Readable Stack Traces With Source Maps (Optional)

<PlatformContent includePath="getting-started-sourcemaps-short-version" />

## Step 4: Verify Your Setup

Let's test your setup and confirm that Sentry is working correctly and sending data to your Sentry project.

### Issues

Add a test function that throws an error to verify Sentry is capturing errors:

```javascript {filename:index.js}
require("./instrument"); // Import Sentry initialization first
const { onRequest } = require("firebase-functions/https");

exports.testSentry = onRequest(async (request, response) => {
throw new Error("Sentry Test Error - This is intentional!");
});
```

Deploy your functions and trigger the test endpoint:

```bash
firebase deploy --only functions
curl https://<region>-<project-id>.cloudfunctions.net/testSentry
```

<OnboardingOption optionId="performance">

### Tracing

Firebase Functions are automatically instrumented for tracing. You can also create custom spans:

```javascript {filename:index.js}
require("./instrument");
const Sentry = require("@sentry/node");
const { onRequest } = require("firebase-functions/https");

exports.tracedFunction = onRequest(async (request, response) => {
await Sentry.startSpan(
{ op: "task", name: "My Custom Task" },
async () => {
// Simulate some work
await new Promise((resolve) => setTimeout(resolve, 100));
}
);

response.send("Done!");
});
```

</OnboardingOption>

### View Captured Data in Sentry

Now, head over to your project on [Sentry.io](https://sentry.io/) to view the collected data (it takes a couple of moments for the data to appear).

<PlatformContent includePath="getting-started-verify-locate-data" />

## Next Steps

At this point, you should have integrated Sentry into your Cloud Functions for Firebase project.

Now's a good time to customize your setup and look into more advanced topics:

- Continue to <PlatformLink to="/configuration">customize your configuration</PlatformLink>
- Learn how to <PlatformLink to="/usage">manually capture errors</PlatformLink>
- Get familiar with [Sentry's product features](/product/) like tracing, insights, and alerts

<Expandable permalink={false} title="Are you having problems setting up the SDK?">

- Find various topics in <PlatformLink to="/troubleshooting">Troubleshooting</PlatformLink>
- [Get support](https://sentry.zendesk.com/hc/en-us/)

</Expandable>
2 changes: 1 addition & 1 deletion docs/platforms/javascript/guides/gcp-functions/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ categories:
</Alert>

<Alert level="info" title="Using Cloud Functions for Firebase?">
If you're using [Cloud Functions for Firebase](https://firebase.google.com/docs/functions), see the <PlatformLink to="/configuration/integrations/firebase">Firebase integration</PlatformLink> documentation for automatic instrumentation of Firebase-specific features
If you're using [Cloud Functions for Firebase](https://firebase.google.com/docs/functions), see our dedicated [Firebase guide](/platforms/javascript/guides/firebase/) for a simpler setup using `@sentry/node`.
</Alert>

<PlatformContent includePath="getting-started-prerequisites" />
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"next-themes": "^0.3.0",
"nextjs-toploader": "^1.6.6",
"p-limit": "^6.2.0",
"platformicons": "^9.0.5",
"platformicons": "^9.0.6",
"prism-sentry": "^1.0.2",
"react": "^19.2.4",
"react-dom": "^19.2.4",
Expand Down
7 changes: 7 additions & 0 deletions src/components/platformIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import FastapiSVG from 'platformicons/svg/fastapi.svg';
import FasthttpSVG from 'platformicons/svg/fasthttp.svg';
import FastifySVG from 'platformicons/svg/fastify.svg';
import FiberSVG from 'platformicons/svg/fiber.svg';
import FirebaseSVG from 'platformicons/svg/firebase.svg';
import FlaskSVG from 'platformicons/svg/flask.svg';
import FlutterSVG from 'platformicons/svg/flutter.svg';
import FontSVG from 'platformicons/svg/font.svg';
Expand Down Expand Up @@ -198,6 +199,7 @@ import FastapiSVGLarge from 'platformicons/svg_80x80/fastapi.svg';
import FasthttpSVGLarge from 'platformicons/svg_80x80/fasthttp.svg';
import FastifySVGLarge from 'platformicons/svg_80x80/fastify.svg';
import FiberSVGLarge from 'platformicons/svg_80x80/fiber.svg';
import FirebaseSVGLarge from 'platformicons/svg_80x80/firebase.svg';
import FlaskSVGLarge from 'platformicons/svg_80x80/flask.svg';
import FlutterSVGLarge from 'platformicons/svg_80x80/flutter.svg';
import FontSVGLarge from 'platformicons/svg_80x80/font.svg';
Expand Down Expand Up @@ -612,6 +614,10 @@ const formatToSVG = {
sm: FastifySVG,
lg: FastifySVGLarge,
},
firebase: {
sm: FirebaseSVG,
lg: FirebaseSVGLarge,
},
hapi: {
sm: HapiSVG,
lg: HapiSVGLarge,
Expand Down Expand Up @@ -986,6 +992,7 @@ export const PLATFORM_TO_ICON = {
'javascript-ionic': 'ionic',
'javascript-hapi': 'hapi',
'javascript-hono': 'hono',
'javascript-firebase': 'firebase',
'javascript-koa': 'koa',
'javascript-fastify': 'fastify',
'javascript-nestjs': 'nestjs',
Expand Down
3 changes: 3 additions & 0 deletions src/data/platforms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
- slug: hono
type: framework
name: Hono
- slug: firebase
type: framework
name: Firebase
- slug: fastify
type: framework
name: Fastify
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11517,10 +11517,10 @@ pkg-types@^2.3.0:
exsolve "^1.0.7"
pathe "^2.0.3"

platformicons@^9.0.5:
version "9.0.5"
resolved "https://registry.yarnpkg.com/platformicons/-/platformicons-9.0.5.tgz#e17bded0aba76a3a09515bfb02461c0e1434b090"
integrity sha512-w7MVLlJZ9vjAbhXmOFl/rhMrSCsw0c9aIZjFGsjCbrvvzPiv3b7FE9BC46YDJSiLnmGoMpotrqxhTzEMiY8H+A==
platformicons@^9.0.6:
version "9.0.6"
resolved "https://registry.yarnpkg.com/platformicons/-/platformicons-9.0.6.tgz#579bd3c4519f31972b652a35b1e6974ba1d44b27"
integrity sha512-FjDMRWz9QbyVxMXfNz2YyZ2QZIBUuwflTWj0uBij+oy58eLf98y6xTrD2+Wo9dwpLtHK/0HzUa5zsed1cCH6+w==
dependencies:
"@types/node" "*"
"@types/react" "*"
Expand Down
Loading