Skip to content

feat(node): Add firebase integration #16719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Jul 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
31381d5
feat(node): Add firebase integration
onurtemizkan Jun 24, 2025
07c9e9b
Add missing dependency
onurtemizkan Jun 24, 2025
5a9cc23
Add missing node re-exports
onurtemizkan Jun 24, 2025
d83a5bd
Add JSDoc
onurtemizkan Jun 26, 2025
0d72991
Apply suggestions from code review
onurtemizkan Jul 16, 2025
5adfbda
Fix import paths
onurtemizkan Jul 16, 2025
6398ce7
Rename internal `startSpan` to `startDBSpan`
onurtemizkan Jul 16, 2025
0d761cd
Lint
onurtemizkan Jul 16, 2025
a2bf706
Reimplement e2e test
onurtemizkan Jul 18, 2025
f3c5ca3
Simplify patch logic
onurtemizkan Jul 19, 2025
767a417
Merge branch 'develop' into onur/firebase-instrumentation
onurtemizkan Jul 21, 2025
eddeb8e
Add `deleteDoc` unwrapper
onurtemizkan Jul 21, 2025
cab996e
Simplify unwrappers
onurtemizkan Jul 21, 2025
d30be51
Correct `setDoc` span name
onurtemizkan Jul 21, 2025
1786676
Merge branch 'develop' into onur/firebase-instrumentation
onurtemizkan Jul 21, 2025
d27149e
Increase size limit
onurtemizkan Jul 21, 2025
3636b82
Handle IPv6 hosts
onurtemizkan Jul 21, 2025
ed24b87
Handle IPv6 hosts better
onurtemizkan Jul 21, 2025
1416017
Handle IPv6 hosts even better
onurtemizkan Jul 22, 2025
3a2a443
Try to make it more robust
onurtemizkan Jul 22, 2025
948db0c
Brackets
onurtemizkan Jul 22, 2025
89774ab
Add tests
onurtemizkan Jul 22, 2025
8d07b8d
Merge branch 'develop' into onur/firebase-instrumentation
onurtemizkan Jul 22, 2025
4395b36
Remove README
onurtemizkan Jul 24, 2025
5eff48e
Merge branch 'develop' into onur/firebase-instrumentation
onurtemizkan Jul 24, 2025
0de410e
Merge branch 'develop' into onur/firebase-instrumentation
onurtemizkan Jul 25, 2025
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
@@ -0,0 +1,5 @@
{
"projects": {
"default": "sentry-firebase-e2e-test-f4ed3"
}
}
58 changes: 58 additions & 0 deletions dev-packages/e2e-tests/test-applications/node-firebase/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# compiled output
/dist
/node_modules
/build

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# temp directory
.temp
.tmp

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

test-results
2 changes: 2 additions & 0 deletions dev-packages/e2e-tests/test-applications/node-firebase/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@sentry:registry=http://127.0.0.1:4873
@sentry-internal:registry=http://127.0.0.1:4873
64 changes: 64 additions & 0 deletions dev-packages/e2e-tests/test-applications/node-firebase/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
## Assuming you already have installed docker desktop or orbstack etc. or any other docker software

### Enabling / authorising firebase emulator through docker

1. Run the docker

```bash
pnpm docker
```

2. In new tab, enter the docker container by simply running

```bash
docker exec -it sentry-firebase bash
```

3. Now inside docker container run

```bash
firebase login
```

4. You should now see a long link to authenticate with google account, copy the link and open it using your browser
5. Choose the account you want to authenticate with
6. Once you do this you should be able to see something like "Firebase CLI Login Successful"
7. And inside docker container you should see something like "Success! Logged in as <here is the email you have chosen>"
8. Now you can exit docker container

```bash
exit
```

9. Switch back to previous tab, stop the docker container (ctrl+c).
10. You should now be able to run the test, as you have correctly authenticated the firebase emulator

### Preparing data for CLI

1. Please authorize the docker first - see the previous section
2. Once you do that you can generate .env file locally, to do that just run

```bash
npm run createEnvFromConfig
```

3. It will create a new file called ".env" inside folder "docker"
4. View the file. There will be 2 params CONFIG_FIREBASE_TOOLS and CONFIG_UPDATE_NOTIFIER_FIREBASE_TOOLS.
5. Now inside the CLI create a new variable under the name CONFIG_FIREBASE_TOOLS and
CONFIG_UPDATE_NOTIFIER_FIREBASE_TOOLS - take values from mentioned .env file
6. File .env is ignored to avoid situation when developer after authorizing firebase with private account will
accidently push the tokens to github.
7. But if we want the users to still have some default to be used for authorisation (on their local development) it will
be enough to commit this file, we just have to authorize it with some "special" account.

**Some explanation towards environment settings, the environment variable defined directly in "environments" takes
precedence over .env file, that means it will be safe to define it in CLI and still keeps the .env file.**

### Scripts - helpers

- createEnvFromConfig - it will use the firebase docker authentication and create .env file which will be used then by
docker whenever you run emulator
- createConfigFromEnv - it will use '.env' file in docker folder to create .config for the firebase to be used to
authenticate whenever you run docker, Docker by default loads .env file itself

Use these scripts when testing and updating the environment settings on CLI
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"firestore": {
"database": "(default)",
"location": "nam5",
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"emulators": {
"firestore": {
"port": 8080
},
"database": {
"port": 9000
},
"ui": {
"enabled": true
},
"singleProjectMode": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"indexes": [],
"fieldOverrides": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
rules_version='2'

service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
// This rule allows anyone with your database reference to view, edit,
// and delete all data in your database. It is useful for getting
// started, but it is configured to expire after 30 days because it
// leaves your app open to attackers. At that time, all client
// requests to your database will be denied.
//
// Make sure to write security rules for your app before that time, or
// else all client requests to your database will be denied until you
// update your rules.
allow read, write: if request.time < timestamp.date(2025, 8, 17);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "node-firebase-e2e-test-app",
"version": "0.0.1",
"private": true,
"scripts": {
"build": "tsc",
"dev": "tsc --build --watch",
"proxy": "node start-event-proxy.mjs",
"emulate": "firebase emulators:start &",
"start": "node ./dist/app.js",
"test": "playwright test",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"test:build": "pnpm install && pnpm build",
"test:assert": "pnpm firebase emulators:exec 'pnpm test'"
},
"dependencies": {
"@firebase/app": "^0.13.1",
"@sentry/node": "latest || *",
"@sentry/core": "latest || *",
"@sentry/opentelemetry": "latest || *",
"@types/node": "^18.19.1",
"dotenv": "^16.4.5",
"express": "^4.18.2",
"firebase": "^12.0.0",
"firebase-admin": "^12.0.0",
"tsconfig-paths": "^4.2.0",
"typescript": "4.9.5"
},
"devDependencies": {
"@playwright/test": "~1.53.2",
"@sentry-internal/test-utils": "link:../../../test-utils",
"@types/express": "^4.17.13",
"firebase-tools": "^12.0.0"
},
"volta": {
"extends": "../../package.json"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { getPlaywrightConfig } from '@sentry-internal/test-utils';

const config = getPlaywrightConfig({
startCommand: `pnpm start`,
});

export default config;
71 changes: 71 additions & 0 deletions dev-packages/e2e-tests/test-applications/node-firebase/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import * as Sentry from '@sentry/node';
import './init';
import express from 'express';
import type { FirebaseOptions } from '@firebase/app';
import { initializeApp } from 'firebase/app';
import {
addDoc,
collection,
connectFirestoreEmulator,
deleteDoc,
doc,
getDocs,
getFirestore,
setDoc,
} from 'firebase/firestore/lite';

const options: FirebaseOptions = {
projectId: 'sentry-15d85',
apiKey: 'sentry-fake-api-key',
};

const app = initializeApp(options);

const db = getFirestore(app);
connectFirestoreEmulator(db, '127.0.0.1', 8080);
const citiesRef = collection(db, 'cities');

async function addCity(): Promise<void> {
await addDoc(citiesRef, {
name: 'San Francisco',
});
}

async function getCities(): Promise<unknown> {
const citySnapshot = await getDocs(citiesRef);
const cityList = citySnapshot.docs.map(doc => doc.data());
return cityList;
}

async function deleteCity(): Promise<void> {
await deleteDoc(doc(citiesRef, 'SF'));
}

async function setCity(): Promise<void> {
await setDoc(doc(citiesRef, 'SF'), {
name: 'San Francisco',
state: 'CA',
country: 'USA',
capital: false,
population: 860000,
regions: ['west_coast', 'norcal'],
});
}

const expressApp = express();
const port = 3030;

expressApp.get('/test', async function (req, res) {
await Sentry.startSpan({ name: 'Test Transaction' }, async () => {
await addCity();
await setCity();
await getCities();
await deleteCity();
});
await Sentry.flush();
res.send({ version: 'v1' });
});

expressApp.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});
11 changes: 11 additions & 0 deletions dev-packages/e2e-tests/test-applications/node-firebase/src/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as Sentry from '@sentry/node';


Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
integrations: [Sentry.firebaseIntegration()],
defaultIntegrations: false,
tunnel: `http://localhost:3031/`, // proxy server
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { startEventProxyServer } from '@sentry-internal/test-utils';

startEventProxyServer({
port: 3031,
proxyServerName: 'node-firebase',
});
Loading
Loading