Skip to content

Commit f90e12b

Browse files
piehwardpeet
authored andcommitted
fix(gatsby): assign correct parentSpans to PQR activities (gatsbyjs#33568)
1 parent 29d49a1 commit f90e12b

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

packages/gatsby/src/commands/build.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ module.exports = async function build(program: IBuildArgs): Promise<void> {
221221
}
222222

223223
const cacheActivity = report.activityTimer(`Caching Webpack compilations`, {
224-
parentSpan: buildActivityTimer.span,
224+
parentSpan: buildSpan,
225225
})
226226
try {
227227
cacheActivity.start()
@@ -249,12 +249,14 @@ module.exports = async function build(program: IBuildArgs): Promise<void> {
249249

250250
let waitForWorkerPoolRestart = Promise.resolve()
251251
if (process.env.GATSBY_EXPERIMENTAL_PARALLEL_QUERY_RUNNING) {
252-
await runQueriesInWorkersQueue(workerPool, queryIds)
252+
await runQueriesInWorkersQueue(workerPool, queryIds, {
253+
parentSpan: buildSpan,
254+
})
253255
// Jobs still might be running even though query running finished
254256
await waitUntilAllJobsComplete()
255257
// Restart worker pool before merging state to lower memory pressure while merging state
256258
waitForWorkerPoolRestart = workerPool.restart()
257-
await mergeWorkerState(workerPool)
259+
await mergeWorkerState(workerPool, buildSpan)
258260
} else {
259261
await runStaticQueries({
260262
queryIds,

packages/gatsby/src/utils/worker/__tests__/queries.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ describeWhenLMDB(`worker (queries)`, () => {
298298
const spy = jest.spyOn(worker.single, `runQueries`)
299299

300300
// @ts-ignore - worker is defined
301-
await runQueriesInWorkersQueue(worker, queryIdsBig, 10)
301+
await runQueriesInWorkersQueue(worker, queryIdsBig, { chunkSize: 10 })
302302
const stateFromWorker = await worker.single.getState()
303303

304304
// Called the complete ABC so we can test _a

packages/gatsby/src/utils/worker/pool.ts

+21-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { WorkerPool } from "gatsby-worker"
22
import { chunk } from "lodash"
33
import reporter from "gatsby-cli/lib/reporter"
44
import { cpuCoreCount } from "gatsby-core-utils"
5+
import { Span } from "opentracing"
56

67
import { IGroupedQueryIds } from "../../services"
78
import { initJobsMessagingInMainProcess } from "../jobs/worker-messaging"
@@ -46,16 +47,27 @@ function handleRunQueriesInWorkersQueueError(e: Error): never {
4647
export async function runQueriesInWorkersQueue(
4748
pool: GatsbyWorkerPool,
4849
queryIds: IGroupedQueryIds,
49-
chunkSize = queriesChunkSize
50+
opts?: {
51+
chunkSize?: number
52+
parentSpan?: Span
53+
}
5054
): Promise<void> {
5155
const activity = reporter.createProgress(
5256
`run queries in workers`,
53-
queryIds.staticQueryIds.length + queryIds.pageQueryIds.length
57+
queryIds.staticQueryIds.length + queryIds.pageQueryIds.length,
58+
0,
59+
{ parentSpan: opts?.parentSpan }
5460
)
5561
activity.start()
5662
try {
57-
const staticQuerySegments = chunk(queryIds.staticQueryIds, chunkSize)
58-
const pageQuerySegments = chunk(queryIds.pageQueryIds, chunkSize)
63+
const staticQuerySegments = chunk(
64+
queryIds.staticQueryIds,
65+
opts?.chunkSize ?? queriesChunkSize
66+
)
67+
const pageQuerySegments = chunk(
68+
queryIds.pageQueryIds,
69+
opts?.chunkSize ?? queriesChunkSize
70+
)
5971

6072
pool.all.setComponents()
6173

@@ -90,8 +102,11 @@ export async function runQueriesInWorkersQueue(
90102
}
91103
}
92104

93-
export async function mergeWorkerState(pool: GatsbyWorkerPool): Promise<void> {
94-
const activity = reporter.activityTimer(`Merge worker state`)
105+
export async function mergeWorkerState(
106+
pool: GatsbyWorkerPool,
107+
parentSpan?: Span
108+
): Promise<void> {
109+
const activity = reporter.activityTimer(`Merge worker state`, { parentSpan })
95110
activity.start()
96111

97112
for (const { workerId } of pool.getWorkerInfo()) {

0 commit comments

Comments
 (0)