-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Open
onurtemizkan
wants to merge
9
commits into
develop
Choose a base branch
from
onur/firebase-instrumentation
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
37a5842
feat(node): Add firebase integration
onurtemizkan 11bcb38
Add missing dependency
onurtemizkan 65ff3ef
Add missing node re-exports
onurtemizkan 9dfe783
Add JSDoc
onurtemizkan d609d66
Apply suggestions from code review
onurtemizkan 70c2311
Fix import paths
onurtemizkan c92eaab
Rename internal `startSpan` to `startDBSpan`
onurtemizkan 2b3b28c
Lint
onurtemizkan 4b4b08d
Reimplement e2e test
onurtemizkan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
dev-packages/e2e-tests/test-applications/node-firebase/.firebaserc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
58
dev-packages/e2e-tests/test-applications/node-firebase/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
2
dev-packages/e2e-tests/test-applications/node-firebase/.npmrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
64
dev-packages/e2e-tests/test-applications/node-firebase/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
20 changes: 20 additions & 0 deletions
20
dev-packages/e2e-tests/test-applications/node-firebase/firebase.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
dev-packages/e2e-tests/test-applications/node-firebase/firestore.indexes.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"indexes": [], | ||
"fieldOverrides": [] | ||
} |
18 changes: 18 additions & 0 deletions
18
dev-packages/e2e-tests/test-applications/node-firebase/firestore.rules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
dev-packages/e2e-tests/test-applications/node-firebase/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
dev-packages/e2e-tests/test-applications/node-firebase/playwright.config.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
71
dev-packages/e2e-tests/test-applications/node-firebase/src/app.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
dev-packages/e2e-tests/test-applications/node-firebase/src/init.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
AbhiPrasad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
integrations: [Sentry.firebaseIntegration()], | ||
defaultIntegrations: false, | ||
tunnel: `http://localhost:3031/`, // proxy server | ||
}); |
6 changes: 6 additions & 0 deletions
6
dev-packages/e2e-tests/test-applications/node-firebase/start-event-proxy.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.