Skip to content

Commit

Permalink
feat(gatsby): capture number of ssg,dsg,ssr pages in telemetry (gatsb…
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh authored and wardpeet committed Oct 29, 2021
1 parent 2786979 commit 87d1cca
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 87d1cca

Please sign in to comment.