From 941f41bccb683b6982e1ce63943045098e20b959 Mon Sep 17 00:00:00 2001 From: JPeer264 Date: Fri, 30 Jan 2026 09:18:29 +0100 Subject: [PATCH 1/2] feat(firebase): Add an own Firebase section --- .../configuration/integrations/firebase.mdx | 1 + .../javascript/common/install/index.mdx | 1 + .../javascript/guides/firebase/index.mdx | 196 ++++++++++++++++++ .../javascript/guides/gcp-functions/index.mdx | 2 +- package.json | 2 +- src/components/platformIcon.tsx | 7 + src/data/platforms.yml | 3 + yarn.lock | 8 +- 8 files changed, 214 insertions(+), 6 deletions(-) create mode 100644 docs/platforms/javascript/guides/firebase/index.mdx diff --git a/docs/platforms/javascript/common/configuration/integrations/firebase.mdx b/docs/platforms/javascript/common/configuration/integrations/firebase.mdx index e8b04888747f6..baaff71bff370 100644 --- a/docs/platforms/javascript/common/configuration/integrations/firebase.mdx +++ b/docs/platforms/javascript/common/configuration/integrations/firebase.mdx @@ -3,6 +3,7 @@ title: Firebase description: "Adds instrumentation for Firebase. (default)" supported: - javascript.node + - javascript.firebase - javascript.gcp-functions - javascript.astro - javascript.bun diff --git a/docs/platforms/javascript/common/install/index.mdx b/docs/platforms/javascript/common/install/index.mdx index 442a5e1ef83d1..be74a26ac984f 100644 --- a/docs/platforms/javascript/common/install/index.mdx +++ b/docs/platforms/javascript/common/install/index.mdx @@ -11,6 +11,7 @@ notSupported: - javascript.cordova - javascript.electron - javascript.ember + - javascript.firebase - javascript.gatsby - javascript.nextjs - javascript.nuxt diff --git a/docs/platforms/javascript/guides/firebase/index.mdx b/docs/platforms/javascript/guides/firebase/index.mdx new file mode 100644 index 0000000000000..daa6772c3d544 --- /dev/null +++ b/docs/platforms/javascript/guides/firebase/index.mdx @@ -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 +--- + + + +[Cloud Functions for Firebase](https://firebase.google.com/docs/functions) lets 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 Firebase integration 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. + + + +## Step 1: Install + +Choose the features you want to configure, and this guide will show you how: + + + + + +### 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 requires and initializes Sentry. This file must be required at the very top of your functions entry point, before any other requires. + +```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 +}); +``` + +Require the initialization file at the very top of your functions entry point (for example, `index.js`), before any other requires: + +```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 + } +); +``` + + + The key is to require the initialization file **before** any other requires, + including Firebase requires. This ensures Sentry can properly instrument all + modules. + + +## Step 3: Add Readable Stack Traces With Source Maps (Optional) + + + +## 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"); // Require 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://-.cloudfunctions.net/testSentry +``` + + + +### 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!"); +}); +``` + + + +### 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). + + + +## 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 customize your configuration +- Learn how to manually capture errors +- Get familiar with [Sentry's product features](/product/) like tracing, insights, and alerts + + + +- Find various topics in Troubleshooting +- [Get support](https://sentry.zendesk.com/hc/en-us/) + + diff --git a/docs/platforms/javascript/guides/gcp-functions/index.mdx b/docs/platforms/javascript/guides/gcp-functions/index.mdx index 28933c1ba4544..ebf9f9f57e704 100644 --- a/docs/platforms/javascript/guides/gcp-functions/index.mdx +++ b/docs/platforms/javascript/guides/gcp-functions/index.mdx @@ -15,7 +15,7 @@ categories: - If you're using [Cloud Functions for Firebase](https://firebase.google.com/docs/functions), see the Firebase integration 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`. diff --git a/package.json b/package.json index 761f638d0834e..e9115480a6d72 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/components/platformIcon.tsx b/src/components/platformIcon.tsx index 2f11af739d8e2..f8b29c410a6dd 100644 --- a/src/components/platformIcon.tsx +++ b/src/components/platformIcon.tsx @@ -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'; @@ -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'; @@ -612,6 +614,10 @@ const formatToSVG = { sm: FastifySVG, lg: FastifySVGLarge, }, + firebase: { + sm: FirebaseSVG, + lg: FirebaseSVGLarge, + }, hapi: { sm: HapiSVG, lg: HapiSVGLarge, @@ -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', diff --git a/src/data/platforms.yml b/src/data/platforms.yml index 9f75f12e69d7e..009543db5f561 100644 --- a/src/data/platforms.yml +++ b/src/data/platforms.yml @@ -7,6 +7,9 @@ - slug: hono type: framework name: Hono +- slug: firebase + type: framework + name: Firebase - slug: fastify type: framework name: Fastify diff --git a/yarn.lock b/yarn.lock index c8fcb1716055b..08e5e281a576d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" "*" From dd32fdd341cf10a44609030abe175405cb5589a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Peer=20St=C3=B6cklmair?= Date: Wed, 4 Feb 2026 14:10:48 +0100 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Alex Krawiec Co-authored-by: Sigrid <32902192+s1gr1d@users.noreply.github.com> --- docs/platforms/javascript/guides/firebase/index.mdx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/platforms/javascript/guides/firebase/index.mdx b/docs/platforms/javascript/guides/firebase/index.mdx index daa6772c3d544..5e75dc28723f9 100644 --- a/docs/platforms/javascript/guides/firebase/index.mdx +++ b/docs/platforms/javascript/guides/firebase/index.mdx @@ -12,7 +12,7 @@ categories: -[Cloud Functions for Firebase](https://firebase.google.com/docs/functions) lets 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. +[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 @@ -53,7 +53,7 @@ pnpm add @sentry/node ## Step 2: Configure -Create an initialization file (for example, `instrument.js`) that requires and initializes Sentry. This file must be required at the very top of your functions entry point, before any other requires. +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"); @@ -86,7 +86,7 @@ Sentry.init({ }); ``` -Require the initialization file at the very top of your functions entry point (for example, `index.js`), before any other requires: +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 @@ -113,8 +113,8 @@ exports.onUserCreated = onDocumentCreated( ``` - The key is to require the initialization file **before** any other requires, - including Firebase requires. This ensures Sentry can properly instrument all + The key is to import the initialization file **before** any other `require` calls, + including Firebase imports. This ensures Sentry can properly instrument all modules. @@ -131,7 +131,7 @@ Let's test your setup and confirm that Sentry is working correctly and sending d Add a test function that throws an error to verify Sentry is capturing errors: ```javascript {filename:index.js} -require("./instrument"); // Require Sentry initialization first +require("./instrument"); // Import Sentry initialization first const { onRequest } = require("firebase-functions/https"); exports.testSentry = onRequest(async (request, response) => {