Skip to content

Commit

Permalink
Merge branch 'master' into rosalyntan.evo
Browse files Browse the repository at this point in the history
  • Loading branch information
rosalyntan committed Dec 27, 2024
2 parents 0051335 + 774d3f0 commit b053edb
Show file tree
Hide file tree
Showing 60 changed files with 630 additions and 213 deletions.
16 changes: 14 additions & 2 deletions .github/workflows/node-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ jobs:
distribution: temurin

- uses: actions/checkout@v4
- name: Setup Chrome
uses: browser-actions/[email protected]
with:
install-dependencies: true
install-chromedriver: true
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
Expand Down Expand Up @@ -146,7 +151,7 @@ jobs:
integration:
needs: unit
if: contains(fromJSON('["push", "merge_group"]'), github.event_name)
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

env:
FIREBASE_EMULATORS_PATH: ${{ github.workspace }}/emulator-cache
Expand Down Expand Up @@ -176,13 +181,19 @@ jobs:
- npm run test:triggers-end-to-end
- npm run test:triggers-end-to-end:inspect
- npm run test:dataconnect-deploy
- npm run test:dataconnect-emulator
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: npm
cache-dependency-path: npm-shrinkwrap.json
- name: Setup Chrome
uses: browser-actions/[email protected]
with:
install-dependencies: true
install-chromedriver: true
- name: Cache firebase emulators
uses: actions/cache@v3
with:
Expand Down Expand Up @@ -231,6 +242,7 @@ jobs:
- npm run test:storage-deploy
# - npm run test:storage-emulator-integration
# - npm run test:dataconnect-deploy # TODO (joehanley): Reenable this - it should be safe to run in parallel
# - npm run test:dataconnect-emulator # TODO (joehanley): Figure out why this is failing
- npm run test:frameworks
steps:
- name: Setup Java JDK
Expand Down Expand Up @@ -260,7 +272,7 @@ jobs:
- run: ${{ matrix.script }}
- name: Print debug logs
if: failure()
run: type *debug.log
run: dir "*.log" /s/b | type

check-package-lock:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ src/test/emulators/extensions/firebase/[email protected]/functions/pa
src/test/emulators/extensions/firebase/[email protected]/functions/package-lock.json
scripts/functions-deploy-tests/**/package-lock.json
scripts/functions-discover-tests/**/**/package-lock.json
.dataconnect
*-debug.log

/.vscode
node_modules
Expand Down
10 changes: 0 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
- Enable apphosting:rollouts:create command. (#8031)
- Added default value for `emulators.dataconnect.dataDir` to `init dataconnect`.
- Fixed issue where expired auth tokens would not refresh when running on IDX.
- Fixed an issue where `firebase` would error out instead of displaying help text.
- Fixed an issue where `firebase init genkit` would error on Windows machines.
- Fixed an issue where emulator returned error when emulating alerts functions written in python (#8019)
- Better error message for emulator binary architecture incompatibility on MacOS (#7995).
- Deprecated `emulators.apphosting.startCommandOverride`. Please use `emulators.apphosting.startCommand` instead.
- Updated `superstatic` to `9.1.0` in package.json.
- Updated the Firebase Data Connect local toolkit to v1.7.4, which includes a fix for an issue that caused duplicate installations of the Firebase JS SDK. (#8028)
12 changes: 12 additions & 0 deletions firebase-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
## NEXT

## 0.12.0

- Updated internal firebase-tools dependency to 13.29.1
- [Fixed] Fixed firebase binary detection for analytics

## 0.11.1

- [Fixed] Fixed IDX analytics issue

## 0.11.0

- Updated internal firebase-tools dependency to 13.28.0
- [Fixed] Fixed an issue where generating an ad-hoc file would break codelenses

## 0.10.8
Expand Down
4 changes: 2 additions & 2 deletions firebase-vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion firebase-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"publisher": "GoogleCloudTools",
"icon": "./resources/firebase_dataconnect_logo.png",
"description": "Firebase Data Connect for VSCode",
"version": "0.10.8",
"version": "0.12.0",
"engines": {
"vscode": "^1.69.0"
},
Expand Down
37 changes: 25 additions & 12 deletions firebase-vscode/src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import vscode, { env, TelemetryLogger, TelemetrySender } from "vscode";
import { pluginLogger } from "./logger-wrapper";
import { AnalyticsParams, trackVSCode } from "../../src/track";
import { env as monospaceEnv } from "../src/core/env";
import { getSettings } from "./utils/settings";

export const IDX_METRIC_NOTICE = `
When you use the Firebase Data Connect Extension, Google collects telemetry data such as usage statistics, error metrics, and crash reports. Telemetry helps us better understand how the Firebase Extension is performing, where improvements need to be made, and how features are being used. Firebase uses this data, consistent with our [Google Privacy Policy](https://policies.google.com/privacy?hl=en-US), to provide, improve, and develop Firebase products and services.
Expand Down Expand Up @@ -35,12 +36,12 @@ export enum DATA_CONNECT_EVENT_NAME {
}

export class AnalyticsLogger {
readonly logger: TelemetryLogger;
readonly logger: TelemetryLogger | IDXLogger;
private disposable: vscode.Disposable;
private sessionCharCount = 0; // Track total chars for the session

constructor() {
this.logger = env.createTelemetryLogger(
constructor(context: vscode.ExtensionContext) {
this.logger = monospaceEnv.value.isMonospace ? new IDXLogger(new GA4TelemetrySender(pluginLogger), context) : env.createTelemetryLogger(
new GA4TelemetrySender(pluginLogger),
);

Expand Down Expand Up @@ -146,6 +147,19 @@ export class AnalyticsLogger {
}
}

export class IDXLogger {
constructor(private sender: GA4TelemetrySender, private context: vscode.ExtensionContext) {}
public logUsage(eventName: string, data?: any) {
const packageJson = this.context.extension.packageJSON;
data = { ...data, extversion: packageJson.version, extname: this.context.extension.id, isidx: true };
this.sender.sendEventData(eventName, data);
}

public logError() {
// TODO
}
}

class GA4TelemetrySender implements TelemetrySender {
private hasSentData = false;
constructor(readonly pluginLogger: { warn: (s: string) => void }) {}
Expand All @@ -154,12 +168,6 @@ class GA4TelemetrySender implements TelemetrySender {
eventName: string,
data?: Record<string, any> | undefined,
): void {
// telemtry flag does not exist in monospace
if (!env.isTelemetryEnabled && !monospaceEnv.value.isMonospace) {
this.pluginLogger.warn("Telemetry is not enabled.");
return;
}

// telemetry logger adds prefixes to eventName and params that are disallowed in GA4
eventName = eventName.replace(
"GoogleCloudTools.firebase-dataconnect-vscode/",
Expand All @@ -176,19 +184,24 @@ class GA4TelemetrySender implements TelemetrySender {
}
}
data = { ...data };
const idxPrepend = monospaceEnv.value.isMonospace ? "idx_" : "";
data = addFirebaseBinaryMetadata(data);
if (!this.hasSentData) {
trackVSCode(
`${idxPrepend}${DATA_CONNECT_EVENT_NAME.EXTENSION_USED}`,
DATA_CONNECT_EVENT_NAME.EXTENSION_USED,
data as AnalyticsParams,
);
this.hasSentData = true;
}
trackVSCode(`${idxPrepend}${eventName}`, data as AnalyticsParams);
trackVSCode(eventName, data as AnalyticsParams);
}

sendErrorData(error: Error, data?: Record<string, any> | undefined): void {
// n/a
// TODO: Sanatize error messages for user data
}
}

function addFirebaseBinaryMetadata(data?: Record<string, any> | undefined) {
const settings = getSettings();
return { ...data, binary_kind: settings.firebaseBinaryKind };
}
11 changes: 6 additions & 5 deletions firebase-vscode/src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import vscode, { Disposable, ExtensionContext, TelemetryLogger } from "vscode";
import vscode, { Disposable, ExtensionContext } from "vscode";
import { ExtensionBrokerImpl } from "../extension-broker";
import { getRootFolders, registerConfig } from "./config";
import { EmulatorsController } from "./emulators";
Expand All @@ -14,11 +14,12 @@ import { upsertFile } from "../data-connect/file-utils";
import { registerWebhooks } from "./webhook";
import { createE2eMockable } from "../utils/test_hooks";
import { runTerminalTask } from "../data-connect/terminal";
import { AnalyticsLogger } from "../analytics";

export async function registerCore(
broker: ExtensionBrokerImpl,
context: ExtensionContext,
telemetryLogger: TelemetryLogger,
analyticsLogger: AnalyticsLogger,
): Promise<[EmulatorsController, vscode.Disposable]> {
const settings = getSettings();

Expand Down Expand Up @@ -69,7 +70,7 @@ export async function registerCore(
? `${settings.firebasePath} init dataconnect --project ${currentProjectId.value}`
: `${settings.firebasePath} init dataconnect`;

initSpy.call("firebase init", initCommand, {focus: true});
initSpy.call("firebase init", initCommand, { focus: true });
});

const emulatorsController = new EmulatorsController(broker);
Expand Down Expand Up @@ -103,8 +104,8 @@ export async function registerCore(
initSpy,
registerOptions(context),
registerEnv(broker),
registerUser(broker, telemetryLogger),
registerProject(broker, telemetryLogger),
registerUser(broker, analyticsLogger),
registerProject(broker, analyticsLogger),
registerQuickstart(broker),
await registerWebhooks(),
{ dispose: sub1 },
Expand Down
12 changes: 7 additions & 5 deletions firebase-vscode/src/core/project.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import vscode, { Disposable, TelemetryLogger } from "vscode";
import vscode, { Disposable } from "vscode";
import { ExtensionBrokerImpl } from "../extension-broker";
import { computed, effect, Signal } from "@preact/signals-react";
import { firebaseRC, updateFirebaseRCProject } from "./config";
Expand All @@ -9,7 +9,7 @@ import { pluginLogger } from "../logger-wrapper";
import { globalSignal } from "../utils/globals";
import { firstWhereDefined } from "../utils/signal";
import { User } from "../types/auth";
import { DATA_CONNECT_EVENT_NAME } from "../analytics";
import { DATA_CONNECT_EVENT_NAME, AnalyticsLogger } from "../analytics";
/** Available projects */
export const projects = globalSignal<Record<string, FirebaseProjectMetadata[]>>(
{},
Expand All @@ -30,7 +30,7 @@ const userScopedProjects = computed<FirebaseProjectMetadata[] | undefined>(

export function registerProject(
broker: ExtensionBrokerImpl,
telemetryLogger: TelemetryLogger,
analyticsLogger: AnalyticsLogger,
): Disposable {
// For testing purposes.
const demoProjectCommand = vscode.commands.registerCommand(
Expand Down Expand Up @@ -103,7 +103,7 @@ export function registerProject(
return;
} else {
try {
telemetryLogger.logUsage(
analyticsLogger.logger.logUsage(
DATA_CONNECT_EVENT_NAME.PROJECT_SELECT_CLICKED,
);

Expand All @@ -120,7 +120,9 @@ export function registerProject(
}
: undefined,
});
telemetryLogger.logUsage(DATA_CONNECT_EVENT_NAME.PROJECT_SELECTED);
analyticsLogger.logger.logUsage(
DATA_CONNECT_EVENT_NAME.PROJECT_SELECTED,
);
} catch (e: any) {
vscode.window.showErrorMessage(e.message);
}
Expand Down
8 changes: 4 additions & 4 deletions firebase-vscode/src/core/user.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Signal, computed, effect } from "@preact/signals-react";
import { Disposable, TelemetryLogger } from "vscode";
import { Disposable } from "vscode";
import { ServiceAccountUser } from "../types";
import { User as AuthUser } from "../../../src/types/auth";
import { ExtensionBrokerImpl } from "../extension-broker";
import { login, logoutUser, requireAuthWrapper } from "../cli";
import { globalSignal } from "../utils/globals";
import { DATA_CONNECT_EVENT_NAME } from "../analytics";
import { DATA_CONNECT_EVENT_NAME, AnalyticsLogger } from "../analytics";
import * as vscode from "vscode";

type User = ServiceAccountUser | AuthUser;
Expand All @@ -24,7 +24,7 @@ export async function checkLogin() {

export function registerUser(
broker: ExtensionBrokerImpl,
telemetryLogger: TelemetryLogger,
analyticsLogger: AnalyticsLogger,
): Disposable {
// For testing purposes.
const userMockCommand = vscode.commands.registerCommand(
Expand Down Expand Up @@ -58,7 +58,7 @@ export function registerUser(
});

const addUserSub = broker.on("addUser", async () => {
telemetryLogger.logUsage(DATA_CONNECT_EVENT_NAME.LOGIN);
analyticsLogger.logger.logUsage(DATA_CONNECT_EVENT_NAME.LOGIN);
const { user } = await login();
currentUser.value = user;
});
Expand Down
9 changes: 5 additions & 4 deletions firebase-vscode/src/data-connect/ad-hoc-mutations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import vscode, { Disposable, TelemetryLogger } from "vscode";
import vscode, { Disposable } from "vscode";
import {
DocumentNode,
GraphQLInputField,
Expand All @@ -18,10 +18,11 @@ import { DataConnectService } from "./service";
import { DATA_CONNECT_EVENT_NAME } from "../analytics";
import { dataConnectConfigs } from "./config";
import { firstWhereDefined } from "../utils/signal";
import {AnalyticsLogger} from "../analytics";

export function registerAdHoc(
dataConnectService: DataConnectService,
telemetryLogger: TelemetryLogger,
analyticsLogger: AnalyticsLogger,
): Disposable {
const defaultScalarValues = {
Any: "{}",
Expand Down Expand Up @@ -262,14 +263,14 @@ query {
vscode.commands.registerCommand(
"firebase.dataConnect.schemaAddData",
(ast, uri) => {
telemetryLogger.logUsage(DATA_CONNECT_EVENT_NAME.ADD_DATA);
analyticsLogger.logger.logUsage(DATA_CONNECT_EVENT_NAME.ADD_DATA);
schemaAddData(ast, uri);
},
),
vscode.commands.registerCommand(
"firebase.dataConnect.schemaReadData",
(document, ast, uri) => {
telemetryLogger.logUsage(DATA_CONNECT_EVENT_NAME.READ_DATA);
analyticsLogger.logger.logUsage(DATA_CONNECT_EVENT_NAME.READ_DATA);
schemaReadData(document, ast, uri);
},
),
Expand Down
9 changes: 5 additions & 4 deletions firebase-vscode/src/data-connect/connectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import vscode, {
ExtensionContext,
InputBoxValidationMessage,
InputBoxValidationSeverity,
TelemetryLogger,
} from "vscode";
import { ExtensionBrokerImpl } from "../extension-broker";
import {
Expand Down Expand Up @@ -39,13 +38,13 @@ import { DataConnectService } from "./service";
import { OperationLocation } from "./types";
import { checkIfFileExists } from "./file-utils";
import * as path from "path";
import { DATA_CONNECT_EVENT_NAME } from "../analytics";
import { DATA_CONNECT_EVENT_NAME, AnalyticsLogger } from "../analytics";

export function registerConnectors(
context: ExtensionContext,
broker: ExtensionBrokerImpl,
dataConnectService: DataConnectService,
telemetryLogger: TelemetryLogger,
analyticsLogger: AnalyticsLogger,
): Disposable {
async function moveOperationToConnector(
defIndex: number, // The index of the definition to move.
Expand Down Expand Up @@ -477,7 +476,9 @@ export function registerConnectors(
vscode.commands.registerCommand(
"firebase.dataConnect.moveOperationToConnector",
(number, location, connectorPath) => {
telemetryLogger.logUsage(DATA_CONNECT_EVENT_NAME.MOVE_TO_CONNECTOR);
analyticsLogger.logger.logUsage(
DATA_CONNECT_EVENT_NAME.MOVE_TO_CONNECTOR,
);
moveOperationToConnector(number, location, connectorPath);
},
),
Expand Down
Loading

0 comments on commit b053edb

Please sign in to comment.