Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gatsby): capture number of ssg,dsg,ssr pages in telemetry #33337

Merged
merged 1 commit into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Comment on lines -92 to +95
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just add type for obj (instead of any)

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 @@ -297,10 +297,28 @@ module.exports = async function build(program: IBuildArgs): Promise<void> {

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