Skip to content

Commit c920e3e

Browse files
authored
Add analytics about firebasePath and FIREBASE_BINARY.
1 parent 2690983 commit c920e3e

File tree

6 files changed

+54
-20
lines changed

6 files changed

+54
-20
lines changed

firebase-vscode/src/analytics.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { env as monospaceEnv } from "../src/core/env";
55

66
export const IDX_METRIC_NOTICE = `
77
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.
8-
We take steps to protect your privacy as part of this process. This includes disconnecting your telemetry data from your Google Account, fully anonymizing it, and storing that data for up to 14 months.
8+
We take steps to protect your privacy as part of this process. This includes disconnecting your telemetry data from your Google Account, fully anonymizing it, and storing that data for up to 14 months.
99
Read more in our [Privacy Policy](https://policies.google.com/privacy?hl=en-US).
1010
`;
1111

@@ -31,6 +31,7 @@ export enum DATA_CONNECT_EVENT_NAME {
3131
START_EMULATORS = "start_emulators",
3232
AUTO_COMPLETE = "auto_complete",
3333
SESSION_CHAR_COUNT = "session_char_count",
34+
SETUP_FIREBASE_BINARY = "setup_firebase_binary",
3435
}
3536

3637
export class AnalyticsLogger {

firebase-vscode/src/data-connect/deploy.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@ export function registerFdcDeploy(
4242
);
4343

4444
const deployAllCmd = vscode.commands.registerCommand("fdc.deploy-all", () => {
45-
telemetryLogger.logUsage(DATA_CONNECT_EVENT_NAME.DEPLOY_ALL);
45+
telemetryLogger.logUsage(DATA_CONNECT_EVENT_NAME.DEPLOY_ALL, {
46+
firebase_binary_kind: settings.firebaseBinaryKind,
47+
});
4648
deploySpy.call(`${settings.firebasePath} deploy --only dataconnect`);
4749
});
4850

4951
const deployCmd = vscode.commands.registerCommand("fdc.deploy", async () => {
50-
telemetryLogger.logUsage(DATA_CONNECT_EVENT_NAME.DEPLOY_INDIVIDUAL);
52+
telemetryLogger.logUsage(DATA_CONNECT_EVENT_NAME.DEPLOY_INDIVIDUAL, {
53+
firebase_binary_kind: settings.firebaseBinaryKind,
54+
});
5155
const configs = await firstWhereDefined(dataConnectConfigs).then(
5256
(c) => c.requireValue,
5357
);

firebase-vscode/src/data-connect/sdk-generation.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ export function registerFdcSdkGeneration(
3737
const initSdkCmd = vscode.commands.registerCommand(
3838
"fdc.init-sdk",
3939
(args: { appFolder: string }) => {
40-
telemetryLogger.logUsage(DATA_CONNECT_EVENT_NAME.INIT_SDK_CLI);
40+
telemetryLogger.logUsage(DATA_CONNECT_EVENT_NAME.INIT_SDK_CLI, {
41+
firebase_binary_kind: settings.firebaseBinaryKind,
42+
});
4143
// Lets do it from the right directory
4244
setTerminalEnvVars(FDC_APP_FOLDER, args.appFolder);
4345
runCommand(`${settings.firebasePath} init dataconnect:sdk`);

firebase-vscode/src/data-connect/terminal.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ export function registerTerminalTasks(
7474
const settings = getSettings();
7575

7676
const loginTaskBroker = broker.on("executeLogin", () => {
77-
telemetryLogger.logUsage(DATA_CONNECT_EVENT_NAME.IDX_LOGIN);
77+
telemetryLogger.logUsage(DATA_CONNECT_EVENT_NAME.IDX_LOGIN, {
78+
firebase_binary_kind: settings.firebaseBinaryKind,
79+
});
7880
runTerminalTask(
7981
"firebase login",
8082
`${settings.firebasePath} login --no-localhost`,
@@ -84,7 +86,9 @@ export function registerTerminalTasks(
8486
});
8587

8688
const startEmulatorsTaskBroker = broker.on("runStartEmulators", () => {
87-
telemetryLogger.logUsage(DATA_CONNECT_EVENT_NAME.START_EMULATORS);
89+
telemetryLogger.logUsage(DATA_CONNECT_EVENT_NAME.START_EMULATORS, {
90+
firebase_binary_kind: settings.firebaseBinaryKind,
91+
});
8892
// TODO: optional debug mode
8993
runTerminalTask(
9094
"firebase emulators",

firebase-vscode/src/extension.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import {
1111
import { logSetup, pluginLogger } from "./logger-wrapper";
1212
import { registerWebview } from "./webview";
1313
import { registerCore } from "./core";
14-
import { getSettings, updateIdxSetting } from "./utils/settings";
14+
import {
15+
getSettings,
16+
setupFirebasePath,
17+
updateIdxSetting,
18+
} from "./utils/settings";
1519
import { registerFdc } from "./data-connect";
1620
import { AuthService } from "./auth/service";
1721
import {
@@ -25,9 +29,12 @@ import { suggestGraphqlSyntaxExtension } from "./data-connect/graphql-syntax-hig
2529

2630
// This method is called when your extension is activated
2731
export async function activate(context: vscode.ExtensionContext) {
32+
const analyticsLogger = new AnalyticsLogger();
33+
2834
// Suggest installing the GraphQL syntax highlighter extension
2935
await suggestGraphqlSyntaxExtension();
3036

37+
await setupFirebasePath(analyticsLogger.logger);
3138
const settings = getSettings();
3239
logSetup();
3340
pluginLogger.debug("Activating Firebase extension.");
@@ -39,7 +46,6 @@ export async function activate(context: vscode.ExtensionContext) {
3946
>(new ExtensionBroker());
4047

4148
const authService = new AuthService(broker);
42-
const analyticsLogger = new AnalyticsLogger();
4349

4450
// show IDX data collection notice
4551
if (settings.shouldShowIdxMetricNotice && env.value.isMonospace) {

firebase-vscode/src/utils/settings.ts

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import * as vscode from "vscode";
12
import { ConfigurationTarget, window, workspace } from "vscode";
3+
import { DATA_CONNECT_EVENT_NAME } from "../analytics";
24

35
export interface Settings {
46
readonly firebasePath: string;
7+
readonly firebaseBinaryKind: string;
58
readonly npmPath: string;
69
readonly useFrameworks: boolean;
710
readonly shouldShowIdxMetricNotice: boolean;
@@ -12,22 +15,23 @@ const DEFAULT_FIREBASE_BINARY = "npx -y firebase-tools@latest";
1215

1316
export function getSettings(): Settings {
1417
const config = workspace.getConfiguration("firebase");
18+
const firebasePath =
19+
config.get<string>("firebasePath") || DEFAULT_FIREBASE_BINARY;
1520

16-
// TODO: Consider moving side effect out of getSettings
17-
// Persist env var as path setting when path setting doesn't exist
18-
if (process.env.FIREBASE_BINARY && !config.get<string>("firebasePath")) {
19-
config.update(
20-
"firebasePath",
21-
process.env.FIREBASE_BINARY,
22-
ConfigurationTarget.Global,
23-
);
24-
window.showInformationMessage(
25-
"Detected FIREBASE_BINARY env var. Saving to `Firebase Path` setting.",
26-
);
21+
let firebaseBinaryKind = "unknown"; // Used for analytics.
22+
if (firebasePath === DEFAULT_FIREBASE_BINARY) {
23+
firebaseBinaryKind = "npx";
24+
} else if (firebasePath.endsWith("/.local/bin/firebase")) {
25+
// https://firebase.tools/dataconnect defaults to $HOME/.local/bin
26+
firebaseBinaryKind = "firepit-local";
27+
} else if (firebasePath.endsWith("/local/bin/firebase")) {
28+
// https://firebase.tools/ defaults to /usr/local/bin
29+
firebaseBinaryKind = "firepit-global";
2730
}
2831

2932
return {
30-
firebasePath: config.get<string>("firebasePath") || DEFAULT_FIREBASE_BINARY,
33+
firebasePath,
34+
firebaseBinaryKind,
3135
npmPath: config.get<string>("npmPath", "npm"),
3236
useFrameworks: config.get<boolean>("hosting.useFrameworks", false),
3337
shouldShowIdxMetricNotice: config.get<boolean>(
@@ -41,3 +45,16 @@ export function updateIdxSetting(shouldShow: boolean) {
4145
const config = workspace.getConfiguration("firebase");
4246
config.update("idx.viewMetricNotice", shouldShow, ConfigurationTarget.Global);
4347
}
48+
49+
// Persist env var as path setting when path setting doesn't exist
50+
export function setupFirebasePath(telemetryLogger: vscode.TelemetryLogger) {
51+
const config = workspace.getConfiguration("firebase");
52+
if (process.env.FIREBASE_BINARY && !config.get<string>("firebasePath")) {
53+
config.update(
54+
"firebasePath",
55+
process.env.FIREBASE_BINARY,
56+
ConfigurationTarget.Global,
57+
);
58+
}
59+
telemetryLogger.logUsage(DATA_CONNECT_EVENT_NAME.SETUP_FIREBASE_BINARY);
60+
}

0 commit comments

Comments
 (0)