Skip to content

Commit e96b069

Browse files
authored
Imporved extensions metrics (#6037)
* Switched most uses of track to GA4 * Move duration out of params, and improve debug logging slightly * Improved metrics for extensions * formats
1 parent 31c2d22 commit e96b069

File tree

7 files changed

+25
-9
lines changed

7 files changed

+25
-9
lines changed

src/deploy/extensions/args.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ export interface Payload {
1010
export interface Context {
1111
have?: planner.DeploymentInstanceSpec[];
1212
want?: planner.DeploymentInstanceSpec[];
13+
extensionsStartTime?: number;
1314
}

src/deploy/extensions/deploy.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ export async function deploy(context: Context, options: Options, payload: Payloa
5959

6060
validationQueue.process();
6161
validationQueue.close();
62-
6362
await validationPromise;
6463

6564
if (errorHandler.hasErrors()) {

src/deploy/extensions/prepare.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { checkSpecForV2Functions, ensureNecessaryV2ApisAndRoles } from "./v2Func
1717
import { acceptLatestAppDeveloperTOS } from "../../extensions/tos";
1818

1919
export async function prepare(context: Context, options: Options, payload: Payload) {
20+
context.extensionsStartTime = Date.now();
2021
const projectId = needProjectId(options);
2122
const projectNumber = await needProjectNumber(options);
2223
const aliases = getAliases(options, projectId);

src/deploy/extensions/release.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ErrorHandler } from "./errors";
77
import { Options } from "../../options";
88
import { needProjectId } from "../../projectUtils";
99
import { saveEtags } from "../../extensions/etags";
10+
import { trackGA4 } from "../../track";
1011

1112
export async function release(context: Context, options: Options, payload: Payload) {
1213
const projectId = needProjectId(options);
@@ -45,6 +46,20 @@ export async function release(context: Context, options: Options, payload: Paylo
4546
deploymentQueue.close();
4647

4748
await deploymentPromise;
49+
// extensionsStartTime should always be populated, but if not, fall back to something that won't break us.
50+
const duration = context.extensionsStartTime ? Date.now() - context.extensionsStartTime : 1;
51+
await trackGA4(
52+
"extensions_deploy",
53+
{
54+
extension_instance_created: payload.instancesToCreate?.length ?? 0,
55+
extension_instance_updated: payload.instancesToUpdate?.length ?? 0,
56+
extension_instance_configured: payload.instancesToConfigure?.length ?? 0,
57+
extension_instance_deleted: payload.instancesToDelete?.length ?? 0,
58+
errors: errorHandler.errors.length ?? 0,
59+
interactive: options.nonInteractive ? "false" : "true",
60+
},
61+
duration
62+
);
4863

4964
// After deployment, write the latest etags to RC so we can detect out of band changes in the next deploy.
5065
const newHave = await planner.have(projectId);

src/deploy/hosting/deploy.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Uploader } from "./uploader";
22
import { detectProjectRoot } from "../../detectProjectRoot";
33
import { listFiles } from "../../listFiles";
44
import { logger } from "../../logger";
5-
import { track } from "../../track";
65
import { envOverride, logLabeledBullet, logLabeledSuccess } from "../../utils";
76
import { bold, cyan } from "colorette";
87
import * as ora from "ora";
@@ -88,9 +87,6 @@ export async function deploy(context: Context, options: Options): Promise<void>
8887

8988
try {
9089
await uploader.start();
91-
} catch (err: any) {
92-
void track("Hosting Deploy", "failure");
93-
throw err;
9490
} finally {
9591
clearInterval(progressInterval);
9692
updateSpinner(uploader.statusMessage(), debugging);
@@ -103,8 +99,6 @@ export async function deploy(context: Context, options: Options): Promise<void>
10399
logLabeledSuccess(`hosting[${deploy.config.site}]`, "file upload complete");
104100
const dt = Date.now() - t0;
105101
logger.debug(`[hosting] deploy completed after ${dt}ms`);
106-
107-
void track("Hosting Deploy", "success", dt);
108102
return runDeploys(deploys, debugging);
109103
}
110104

src/emulator/controller.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as path from "path";
44
import * as fsConfig from "../firestore/fsConfig";
55

66
import { logger } from "../logger";
7-
import { trackEmulator } from "../track";
7+
import { trackEmulator, trackGA4 } from "../track";
88
import * as utils from "../utils";
99
import { EmulatorRegistry } from "./registry";
1010
import {
@@ -351,6 +351,10 @@ export async function startAll(
351351
extensionsBackends
352352
);
353353
emulatableBackends.push(...filteredExtensionsBackends);
354+
trackGA4("extensions_emulated", {
355+
number_of_extensions_emulated: filteredExtensionsBackends.length,
356+
number_of_extensions_ignored: extensionsBackends.length - filteredExtensionsBackends.length,
357+
});
354358
}
355359

356360
const listenConfig = {} as Record<PortName, EmulatorListenConfig>;

src/track.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ type cliEventNames =
1414
| "login"
1515
| "api_enabled"
1616
| "hosting_version"
17-
| "extension_added_to_manifest";
17+
| "extension_added_to_manifest"
18+
| "extensions_deploy"
19+
| "extensions_emulated";
1820
type GA4Property = "cli" | "emulator";
1921
interface GA4Info {
2022
measurementId: string;

0 commit comments

Comments
 (0)