Skip to content

Commit

Permalink
feat(gatsby): capture number of ssg,dsg,ssr pages in telemetry (#33337)
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Oct 20, 2021
1 parent 98a843c commit 7d66a23
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
5 changes: 4 additions & 1 deletion packages/gatsby-telemetry/src/index.ts
Expand Up @@ -89,7 +89,10 @@ export function aggregateStats(data: Array<number>): 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)
}

Expand Down
3 changes: 3 additions & 0 deletions packages/gatsby-telemetry/src/telemetry.ts
Expand Up @@ -108,6 +108,9 @@ export interface ITelemetryTagsPayload {
bundleStats?: unknown
pageDataStats?: unknown
queryStats?: unknown
SSRCount?: number
DSGCount?: number
SSGCount?: number
}
errorV2?: IStructuredErrorV2
valueString?: string
Expand Down
26 changes: 22 additions & 4 deletions packages/gatsby/src/commands/build.ts
Expand Up @@ -380,10 +380,28 @@ module.exports = async function build(program: IBuildArgs): Promise<void> {
await waitMaterializePageMode
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,
Expand Down
16 changes: 16 additions & 0 deletions packages/gatsby/src/commands/develop-process.ts
Expand Up @@ -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,
},
})
})
Expand Down

0 comments on commit 7d66a23

Please sign in to comment.