From 2da22caaa5a7bc4ab2ced2361fb192843a61e81e Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Thu, 30 Sep 2021 12:36:33 +0200 Subject: [PATCH] feat(gatsby): capture number of ssg,dsg,ssr pages in telemetry --- packages/gatsby-telemetry/src/index.ts | 5 +++- packages/gatsby-telemetry/src/telemetry.ts | 3 +++ packages/gatsby/src/commands/build.ts | 26 ++++++++++++++++--- .../gatsby/src/commands/develop-process.ts | 16 ++++++++++++ 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/packages/gatsby-telemetry/src/index.ts b/packages/gatsby-telemetry/src/index.ts index aba3e61a3f3bc..4152eb7203519 100644 --- a/packages/gatsby-telemetry/src/index.ts +++ b/packages/gatsby-telemetry/src/index.ts @@ -89,7 +89,10 @@ export function aggregateStats(data: Array): IAggregateStats { return instance.aggregateStats(data) } -export function addSiteMeasurement(event: string, obj): void { +export function addSiteMeasurement( + event: string, + obj: ITelemetryTagsPayload["siteMeasurements"] +): void { instance.addSiteMeasurement(event, obj) } diff --git a/packages/gatsby-telemetry/src/telemetry.ts b/packages/gatsby-telemetry/src/telemetry.ts index 0ccbc85fc0885..345687cb545c1 100644 --- a/packages/gatsby-telemetry/src/telemetry.ts +++ b/packages/gatsby-telemetry/src/telemetry.ts @@ -108,6 +108,9 @@ export interface ITelemetryTagsPayload { bundleStats?: unknown pageDataStats?: unknown queryStats?: unknown + SSRCount?: number + DSGCount?: number + SSGCount?: number } errorV2?: IStructuredErrorV2 valueString?: string diff --git a/packages/gatsby/src/commands/build.ts b/packages/gatsby/src/commands/build.ts index 72b21cd5489b3..41570fb57adcc 100644 --- a/packages/gatsby/src/commands/build.ts +++ b/packages/gatsby/src/commands/build.ts @@ -297,10 +297,28 @@ module.exports = async function build(program: IBuildArgs): Promise { const waitWorkerPoolEnd = Promise.all(workerPool.end()) - telemetry.addSiteMeasurement(`BUILD_END`, { - pagesCount: toRegenerate.length, // number of html files that will be written - totalPagesCount: store.getState().pages.size, // total number of pages - }) + { + let SSGCount = 0 + let DSGCount = 0 + let SSRCount = 0 + for (const page of store.getState().pages.values()) { + if (page.mode === `SSR`) { + SSRCount++ + } else if (page.mode === `DSG`) { + DSGCount++ + } else { + SSGCount++ + } + } + + telemetry.addSiteMeasurement(`BUILD_END`, { + pagesCount: toRegenerate.length, // number of html files that will be written + totalPagesCount: store.getState().pages.size, // total number of pages + SSRCount, + DSGCount, + SSGCount, + }) + } const postBuildActivityTimer = report.activityTimer(`onPostBuild`, { parentSpan: buildSpan, diff --git a/packages/gatsby/src/commands/develop-process.ts b/packages/gatsby/src/commands/develop-process.ts index a8002da36d34e..ac14777f446d4 100644 --- a/packages/gatsby/src/commands/develop-process.ts +++ b/packages/gatsby/src/commands/develop-process.ts @@ -48,9 +48,25 @@ if (process.send) { } onExit(() => { + let SSGCount = 0 + let DSGCount = 0 + let SSRCount = 0 + for (const page of store.getState().pages.values()) { + if (page.mode === `SSR`) { + SSRCount++ + } else if (page.mode === `DSG`) { + DSGCount++ + } else { + SSGCount++ + } + } + telemetry.trackCli(`DEVELOP_STOP`, { siteMeasurements: { totalPagesCount: store.getState().pages.size, + SSRCount, + DSGCount, + SSGCount, }, }) })