-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(firebase): Instrument cloud functions for firebase v2 #17952
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
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7b72760
feat(firebase): instrument cloud functions for firebase v2
JPeer264 ea06541
feat(firebase): update e2e tests to use functions
JPeer264 f201221
fixup! feat(firebase): update e2e tests to use functions
JPeer264 4b8472e
feat(firebase): add error handling and rename hooks to align with ote…
JPeer264 bc71a98
feat(firebase): remove firebase-functions as dependency
JPeer264 c2cb176
fixup! feat(firebase): update e2e tests to use functions
JPeer264 a431a54
fixup! feat(firebase): add error handling and rename hooks to align w…
JPeer264 1f83c01
Merge branch 'develop' into jp/firebase-integration
JPeer264 e532f44
feat: Update sdk size
JPeer264 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: 0 additions & 5 deletions
5
dev-packages/e2e-tests/test-applications/node-firebase/.firebaserc
This file was deleted.
Oops, something went wrong.
80 changes: 33 additions & 47 deletions
80
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 |
|---|---|---|
| @@ -1,64 +1,50 @@ | ||
| ## Assuming you already have installed docker desktop or orbstack etc. or any other docker software | ||
| <center> | ||
| <a href="https://firebase.google.com/" target="_blank"> | ||
| <img src="https://firebase.google.com/static/downloads/brand-guidelines/SVG/logo-standard.svg" alt="Firebase" width="200"> | ||
| </a> | ||
| </center> | ||
|
|
||
| ### Enabling / authorising firebase emulator through docker | ||
| ## Description | ||
|
|
||
| 1. Run the docker | ||
| [Firebase](https://firebase.google.com/) starter repository with Cloud Functions for Firebase and Firestore. | ||
|
|
||
| ```bash | ||
| pnpm docker | ||
| ``` | ||
|
|
||
| 2. In new tab, enter the docker container by simply running | ||
| ## Project setup | ||
|
|
||
| ```bash | ||
| docker exec -it sentry-firebase bash | ||
| ```sh | ||
| $ pnpm install | ||
| ``` | ||
|
|
||
| 3. Now inside docker container run | ||
| ## Compile and run the project | ||
|
|
||
| ```bash | ||
| firebase login | ||
| ```sh | ||
| $ pnpm dev # builds the functions and firestore app | ||
| $ pnpm emulate | ||
| $ pnpm start # run the firestore app | ||
| ``` | ||
|
|
||
| 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 | ||
| ``` | ||
| ## Run tests | ||
|
|
||
| 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 | ||
| Either run the tests directly: | ||
|
|
||
| ### 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 | ||
| ```sh | ||
| $ pnpm test:build | ||
| $ pnpm test:assert | ||
| ``` | ||
|
|
||
| 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. | ||
| Or run develop while running the tests directly against the emulator. Start each script in a separate terminal: | ||
|
|
||
| **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.** | ||
| ```sh | ||
| $ pnpm dev | ||
| $ pnpm emulate | ||
| $ pnpm test --ui | ||
| ``` | ||
|
|
||
| ### Scripts - helpers | ||
| The tests will run against the Firebase Emulator Suite. | ||
|
|
||
| - 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 | ||
| ## Resources | ||
|
|
||
| Use these scripts when testing and updating the environment settings on CLI | ||
| - [Firebase](https://firebase.google.com/) | ||
| - [Firebase Emulator Suite](https://firebase.google.com/docs/emulator-suite) | ||
| - [Firebase SDK](https://firebase.google.com/docs/sdk) | ||
| - [Firebase Functions](https://firebase.google.com/docs/functions) | ||
| - [Firestore](https://firebase.google.com/docs/firestore) |
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
25 changes: 25 additions & 0 deletions
25
dev-packages/e2e-tests/test-applications/node-firebase/firestore-app/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,25 @@ | ||
| { | ||
| "name": "firestore-app", | ||
| "private": true, | ||
| "scripts": { | ||
| "build": "tsc", | ||
| "dev": "tsc --build --watch", | ||
| "start": "node ./dist/app.js" | ||
| }, | ||
| "dependencies": { | ||
| "@firebase/app": "^0.13.1", | ||
| "@sentry/node": "latest || *", | ||
| "@sentry/core": "latest || *", | ||
| "@sentry/opentelemetry": "latest || *", | ||
JPeer264 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "@types/node": "^22.13.14", | ||
| "dotenv": "^16.4.5", | ||
| "express": "^4.18.2", | ||
| "firebase": "^12.0.0", | ||
| "firebase-admin": "^13.5.0", | ||
| "tsconfig-paths": "^4.2.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/express": "^4.17.13", | ||
| "typescript": "5.9.3" | ||
| } | ||
| } | ||
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions
8
dev-packages/e2e-tests/test-applications/node-firebase/firestore-app/tsconfig.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,8 @@ | ||
| { | ||
| "extends": "../tsconfig.json", | ||
| "compilerOptions": { | ||
| "outDir": "dist", | ||
| "skipLibCheck": true | ||
| }, | ||
| "include": ["src"] | ||
| } |
21 changes: 21 additions & 0 deletions
21
dev-packages/e2e-tests/test-applications/node-firebase/functions/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,21 @@ | ||
| { | ||
| "name": "functions", | ||
| "scripts": { | ||
| "build": "tsc", | ||
| "dev": "tsc --build --watch" | ||
| }, | ||
| "engines": { | ||
| "node": "20" | ||
| }, | ||
| "main": "dist/index.js", | ||
| "dependencies": { | ||
| "firebase-admin": "^12.6.0", | ||
| "firebase-functions": "^6.0.1", | ||
| "@sentry/node": "latest || *", | ||
| "@sentry/core": "latest || *", | ||
| "@sentry/opentelemetry": "latest || *" | ||
JPeer264 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
JPeer264 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
| "devDependencies": { | ||
| "typescript": "5.9.3" | ||
| } | ||
| } | ||
46 changes: 46 additions & 0 deletions
46
dev-packages/e2e-tests/test-applications/node-firebase/functions/src/index.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,46 @@ | ||
| import './init'; | ||
|
|
||
| import { onDocumentCreated, onDocumentCreatedWithAuthContext } from 'firebase-functions/firestore'; | ||
| import { onCall, onRequest } from 'firebase-functions/https'; | ||
| import * as logger from 'firebase-functions/logger'; | ||
| import { setGlobalOptions } from 'firebase-functions/options'; | ||
| import * as admin from 'firebase-admin'; | ||
|
|
||
| setGlobalOptions({ region: 'default' }); | ||
|
|
||
| admin.initializeApp(); | ||
|
|
||
| const db = admin.firestore(); | ||
|
|
||
| export const helloWorld = onRequest(async (request, response) => { | ||
| logger.info('Hello logs!', { structuredData: true }); | ||
|
|
||
| response.send('Hello from Firebase!'); | ||
| }); | ||
|
|
||
| export const onCallSomething = onRequest(async (request, response) => { | ||
| const data = { | ||
| name: request.body?.name || 'Sample Document', | ||
| timestamp: performance.now(), | ||
| description: request.body?.description || 'Created via Cloud Function', | ||
| }; | ||
|
|
||
| await db.collection('documents').add(data); | ||
|
|
||
| logger.info('Create document!', { structuredData: true }); | ||
|
|
||
| response.send({ message: 'Document created!' }); | ||
| }); | ||
|
|
||
| export const onDocumentCreate = onDocumentCreated('documents/{documentId}', async event => { | ||
| const documentId = event.params.documentId; | ||
|
|
||
| await db.collection('documents').doc(documentId).update({ | ||
| processed: true, | ||
| processedAt: new Date(), | ||
| }); | ||
| }); | ||
|
|
||
| export const onDocumentCreateWithAuthContext = onDocumentCreatedWithAuthContext('documents/{documentId}', async () => { | ||
| // noop | ||
| }); |
10 changes: 10 additions & 0 deletions
10
dev-packages/e2e-tests/test-applications/node-firebase/functions/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,10 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://[email protected]/1337', | ||
| release: '1.0', | ||
| tracesSampleRate: 1.0, | ||
| integrations: [Sentry.firebaseIntegration()], | ||
| defaultIntegrations: false, | ||
| tunnel: `http://localhost:3031/`, // proxy server | ||
| }); |
8 changes: 8 additions & 0 deletions
8
dev-packages/e2e-tests/test-applications/node-firebase/functions/tsconfig.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,8 @@ | ||
| { | ||
| "extends": "../tsconfig.json", | ||
| "compilerOptions": { | ||
| "outDir": "dist", | ||
| "skipLibCheck": true | ||
| }, | ||
| "include": ["src"] | ||
| } |
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
3 changes: 3 additions & 0 deletions
3
dev-packages/e2e-tests/test-applications/node-firebase/pnpm-workspace.yaml
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,3 @@ | ||
| packages: | ||
| - 'functions' | ||
| - 'firestore-app' |
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.