Skip to content

Commit

Permalink
Merge branch 'master' into jh-better-core-app-proj-logs
Browse files Browse the repository at this point in the history
  • Loading branch information
joehan authored Dec 9, 2024
2 parents 3d4c65a + 89f1c8a commit 52cc437
Show file tree
Hide file tree
Showing 31 changed files with 184 additions and 80 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/node-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ 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
Expand Down Expand Up @@ -231,6 +232,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 +262,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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- Improved error messaging when using a project that does not have Firebase enabled.
- Changes default CF3 runtime to nodejs22 (#8037)
- Fixed an issue where `--import` would error for the Data Connect emulator if `dataDir` was also set.
6 changes: 6 additions & 0 deletions firebase-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## NEXT

## 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

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.11.0",
"version": "0.11.1",
"engines": {
"vscode": "^1.69.0"
},
Expand Down
30 changes: 18 additions & 12 deletions firebase-vscode/src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,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 +146,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 +167,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,15 +183,14 @@ class GA4TelemetrySender implements TelemetrySender {
}
}
data = { ...data };
const idxPrepend = monospaceEnv.value.isMonospace ? "idx_" : "";
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 {
Expand Down
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
8 changes: 4 additions & 4 deletions firebase-vscode/src/data-connect/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { dataConnectConfigs } from "./config";
import { createE2eMockable } from "../utils/test_hooks";
import { runCommand } from "./terminal";
import { ExtensionBrokerImpl } from "../extension-broker";
import { DATA_CONNECT_EVENT_NAME } from "../analytics";
import { DATA_CONNECT_EVENT_NAME, AnalyticsLogger } from "../analytics";
import { getSettings } from "../utils/settings";

function createDeployOnlyCommand(serviceConnectorMap: {
Expand All @@ -28,7 +28,7 @@ function createDeployOnlyCommand(serviceConnectorMap: {

export function registerFdcDeploy(
broker: ExtensionBrokerImpl,
telemetryLogger: vscode.TelemetryLogger,
analyticsLogger: AnalyticsLogger,
): vscode.Disposable {
const settings = getSettings();

Expand All @@ -42,14 +42,14 @@ export function registerFdcDeploy(
);

const deployAllCmd = vscode.commands.registerCommand("fdc.deploy-all", () => {
telemetryLogger.logUsage(DATA_CONNECT_EVENT_NAME.DEPLOY_ALL, {
analyticsLogger.logger.logUsage(DATA_CONNECT_EVENT_NAME.DEPLOY_ALL, {
firebase_binary_kind: settings.firebaseBinaryKind,
});
deploySpy.call(`${settings.firebasePath} deploy --only dataconnect`);
});

const deployCmd = vscode.commands.registerCommand("fdc.deploy", async () => {
telemetryLogger.logUsage(DATA_CONNECT_EVENT_NAME.DEPLOY_INDIVIDUAL, {
analyticsLogger.logger.logUsage(DATA_CONNECT_EVENT_NAME.DEPLOY_INDIVIDUAL, {
firebase_binary_kind: settings.firebaseBinaryKind,
});
const configs = await firstWhereDefined(dataConnectConfigs).then(
Expand Down
7 changes: 3 additions & 4 deletions firebase-vscode/src/data-connect/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import vscode, {
ConfigurationTarget,
Disposable,
ExtensionContext,
TelemetryLogger,
} from "vscode";
import { ExtensionBrokerImpl } from "../extension-broker";
import { registerWebview } from "../webview";
Expand All @@ -23,13 +22,13 @@ import { DataConnectService } from "./service";
import { DataConnectError, toSerializedError } from "../../common/error";
import { OperationLocation } from "./types";
import { InstanceType } from "./code-lens-provider";
import { DATA_CONNECT_EVENT_NAME } from "../analytics";
import { DATA_CONNECT_EVENT_NAME, AnalyticsLogger } from "../analytics";

export function registerExecution(
context: ExtensionContext,
broker: ExtensionBrokerImpl,
dataConnectService: DataConnectService,
telemetryLogger: TelemetryLogger,
analyticsLogger: AnalyticsLogger,
): Disposable {
const treeDataProvider = new ExecutionHistoryTreeDataProvider();
const executionHistoryTreeView = vscode.window.createTreeView(
Expand Down Expand Up @@ -190,7 +189,7 @@ export function registerExecution(
vscode.commands.registerCommand(
"firebase.dataConnect.executeOperation",
(ast, location, instanceType: InstanceType) => {
telemetryLogger.logUsage(
analyticsLogger.logger.logUsage(
instanceType === InstanceType.LOCAL
? DATA_CONNECT_EVENT_NAME.RUN_LOCAL
: DATA_CONNECT_EVENT_NAME.RUN_PROD,
Expand Down
Loading

0 comments on commit 52cc437

Please sign in to comment.