Skip to content
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

Add X-Firebase-AppId header to VertexAI requests #8809

Merged
merged 7 commits into from
Mar 25, 2025
Merged

Conversation

dlarocque
Copy link
Contributor

@dlarocque dlarocque commented Feb 25, 2025

These headers are only sent when automaticDataCollection is true. This is false by default, so users must explicitly set it to true for these headers to be sent.

  • Add a X-Firebase-Appid header containing the App ID to VertexAI requests.
  • Add a X-Firebase-Appversion header containing the Firebase JS SDK version (e.g. 11.4.0) to VertexAI requests.
  • Add appId to ApiSettings, and throw an error if it's not defined when initializing the VertexAI instance.

In my testing, the browser converted X-Firebase-AppId to X-Firebase-Appid (lowercases i) in the request. Would this cause any issues?

Sample headers from a request:

'x-firebase-appid: 1:857220473716:web:8c802ada681de9b2b56e21'
'x-firebase-appversion: 11.4.0'

Copy link

changeset-bot bot commented Feb 25, 2025

🦋 Changeset detected

Latest commit: e8c97ad

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@firebase/vertexai Patch
firebase Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Feb 25, 2025

Size Report 1

Affected Products

  • @firebase/data-connect

    TypeBase (e8865f2)Merge (d9579f1)Diff
    browser21.1 kB21.4 kB+305 B (+1.4%)
    main23.1 kB23.6 kB+529 B (+2.3%)
    module21.1 kB21.4 kB+305 B (+1.4%)
  • @firebase/firestore

    TypeBase (e8865f2)Merge (d9579f1)Diff
    browser381 kB381 kB+1 B (+0.0%)
    main590 kB590 kB+1 B (+0.0%)
    module381 kB381 kB+1 B (+0.0%)
    react-native381 kB381 kB+1 B (+0.0%)
  • @firebase/firestore-lite

    TypeBase (e8865f2)Merge (d9579f1)Diff
    browser113 kB113 kB+1 B (+0.0%)
    main155 kB155 kB+1 B (+0.0%)
    module113 kB113 kB+1 B (+0.0%)
    react-native113 kB113 kB+1 B (+0.0%)
  • @firebase/vertexai

    TypeBase (e8865f2)Merge (d9579f1)Diff
    browser34.2 kB34.7 kB+492 B (+1.4%)
    main35.2 kB35.7 kB+492 B (+1.4%)
    module34.2 kB34.7 kB+492 B (+1.4%)
  • bundle

    15 size changes

    TypeBase (e8865f2)Merge (d9579f1)Diff
    firestore (CSI Auto Indexing Disable and Delete)272 kB272 kB+1 B (+0.0%)
    firestore (CSI Auto Indexing Enable)272 kB272 kB+1 B (+0.0%)
    firestore (Persistence)303 kB303 kB+1 B (+0.0%)
    firestore (Query Cursors)250 kB250 kB+1 B (+0.0%)
    firestore (Query)248 kB248 kB+1 B (+0.0%)
    firestore (Read data once)236 kB236 kB+1 B (+0.0%)
    firestore (Read Write w Persistence)328 kB328 kB+1 B (+0.0%)
    firestore (Realtime updates)238 kB238 kB+1 B (+0.0%)
    firestore (Transaction)215 kB215 kB+1 B (+0.0%)
    firestore (Write data)214 kB214 kB+1 B (+0.0%)
    firestore-lite (Query Cursors)104 kB104 kB+1 B (+0.0%)
    firestore-lite (Query)99.9 kB99.9 kB+1 B (+0.0%)
    firestore-lite (Read data once)75.4 kB75.4 kB+1 B (+0.0%)
    firestore-lite (Transaction)101 kB101 kB+1 B (+0.0%)
    firestore-lite (Write data)85.0 kB85.0 kB+1 B (+0.0%)

  • firebase

    TypeBase (e8865f2)Merge (d9579f1)Diff
    firebase-compat.js793 kB793 kB+2 B (+0.0%)
    firebase-data-connect.js17.3 kB17.6 kB+284 B (+1.6%)
    firebase-firestore-compat.js339 kB339 kB+1 B (+0.0%)
    firebase-firestore-lite.js131 kB131 kB+1 B (+0.0%)
    firebase-firestore.js440 kB440 kB+1 B (+0.0%)
    firebase-vertexai.js27.8 kB28.3 kB+444 B (+1.6%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/VpRNKvrMyf.html

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Feb 25, 2025

Size Analysis Report 1

This report is too large (97,096 characters) to be displayed here in a GitHub comment. Please use the below link to see the full report on Google Cloud Storage.

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/kFrCp6DULS.html

@hsubox76
Copy link
Contributor

In my testing, the browser converted X-Firebase-AppId to X-Firebase-Appid (lowercases i) in the request. Would this cause any issues?

It's fine, according to HTTP standard, headers are case insensitive, I guess we just capitalize for better readability in code.

@@ -68,10 +68,16 @@ export abstract class VertexAIModel {
VertexAIErrorCode.NO_PROJECT_ID,
`The "projectId" field is empty in the local Firebase config. Firebase VertexAI requires this field to contain a valid project ID.`
);
} else if (!vertexAI.app?.options?.appId) {
throw new VertexAIError(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In light of Paul's comment about automaticDataCollectionEnabled, not sure if we throw this error if that's false, since we don't actually need appId in that case? Kind of weird edge case though.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The firebaseAppConfig obtained from Firebase Console and Terraform always contains an appId, so unless the developer deliberately removes the appId (not sure why since it's not sensitive), it should always be present. AppId is not just for telemetry purposes. Thus, stronger validation is better here.

@@ -68,10 +68,16 @@ export abstract class VertexAIModel {
VertexAIErrorCode.NO_PROJECT_ID,
`The "projectId" field is empty in the local Firebase config. Firebase VertexAI requires this field to contain a valid project ID.`
);
} else if (!vertexAI.app?.options?.appId) {
throw new VertexAIError(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The firebaseAppConfig obtained from Firebase Console and Terraform always contains an appId, so unless the developer deliberately removes the appId (not sure why since it's not sensitive), it should always be present. AppId is not just for telemetry purposes. Thus, stronger validation is better here.

@dlarocque dlarocque requested a review from paulb777 February 25, 2025 19:17
Copy link
Member

@paulb777 paulb777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, please wait for privacy review process before releasing the header change.

Thanks!

@dlarocque dlarocque force-pushed the dl/firebase-app-id branch from d09a548 to 76f635a Compare March 19, 2025 16:02
@dlarocque dlarocque requested a review from rainshen49 March 19, 2025 16:04
@dlarocque dlarocque merged commit 648de84 into main Mar 25, 2025
36 of 37 checks passed
@dlarocque dlarocque deleted the dl/firebase-app-id branch March 25, 2025 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants