Skip to content

Commit fc66250

Browse files
authored
fix(gatsby): Assign parentSpan to activities that were missing them (#33122)
* Pass parentSpan to page onCreateNode * Add parentSpan to writing page-data.json files activity * more fixes * Make typescript happy
1 parent 91187da commit fc66250

File tree

11 files changed

+37
-16
lines changed

11 files changed

+37
-16
lines changed

packages/gatsby/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Renderer } from "react-dom"
33
import { EventEmitter } from "events"
44
import { WindowLocation, NavigateFn, NavigateOptions } from "@reach/router"
55
import { Reporter } from "gatsby-cli/lib/reporter/reporter"
6+
import { Span } from "opentracing"
67
export { Reporter }
78
import {
89
EnumTypeComposerAsObjectDefinition as ComposeEnumTypeConfig,
@@ -916,7 +917,7 @@ export interface WrapRootElementNodeArgs extends NodePluginArgs {
916917
}
917918

918919
export interface ParentSpanPluginArgs extends NodePluginArgs {
919-
parentSpan: object
920+
parentSpan: Span
920921
}
921922

922923
export interface NodePluginArgs {

packages/gatsby/src/bootstrap/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export async function bootstrap(
6868

6969
await createPages(context)
7070

71-
await handleStalePageData()
71+
await handleStalePageData(parentSpan)
7272

7373
await rebuildSchemaWithSitePage(context)
7474

packages/gatsby/src/commands/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ module.exports = async function build(program: IBuildArgs): Promise<void> {
205205
rewriteActivityTimer.end()
206206
}
207207

208-
await flushPendingPageDataWrites()
208+
await flushPendingPageDataWrites(buildSpan)
209209
markWebpackStatusAsDone()
210210

211211
if (telemetry.isTrackingEnabled()) {

packages/gatsby/src/internal-plugins/functions/gatsby-node.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,11 @@ let isFirstBuild = true
327327
export async function onPreBootstrap({
328328
reporter,
329329
store,
330+
parentSpan,
330331
}: ParentSpanPluginArgs): Promise<void> {
331-
const activity = reporter.activityTimer(`Compiling Gatsby Functions`)
332+
const activity = reporter.activityTimer(`Compiling Gatsby Functions`, {
333+
parentSpan,
334+
})
332335
activity.start()
333336

334337
const {

packages/gatsby/src/redux/plugin-runner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export const startPluginRunner = (): void => {
6868
if (node.internal.type === `SitePage`) {
6969
apiRunnerNode(`onCreateNode`, {
7070
node,
71+
parentSpan: action.parentSpan,
7172
traceTags: { nodeId: node.id, nodeType: node.internal.type },
7273
})
7374
}

packages/gatsby/src/redux/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { IGatsbyCLIState } from "gatsby-cli/src/reporter/redux/types"
66
import { ThunkAction } from "redux-thunk"
77
import { InternalJob, JobResultInterface } from "../utils/jobs/manager"
88
import { ITypeMetadata } from "../schema/infer/inference-metadata"
9+
import { Span } from "opentracing"
910

1011
type SystemPath = string
1112
type Identifier = string
@@ -790,6 +791,9 @@ export interface ICreateNodeAction {
790791
type: `CREATE_NODE`
791792
payload: IGatsbyNode
792793
oldNode?: IGatsbyNode
794+
traceId: string
795+
parentSpan: Span
796+
followsSpan: Span
793797
}
794798

795799
export interface IAddFieldToNodeAction {

packages/gatsby/src/services/create-pages.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ export async function createPages({
107107
`Deleted ${deletedPages.length} page${deletedPages.length === 1 ? `` : `s`}`
108108
)
109109

110-
const tim = reporter.activityTimer(`Checking for changed pages`)
110+
const tim = reporter.activityTimer(`Checking for changed pages`, {
111+
parentSpan,
112+
})
111113
tim.start()
112114

113115
const { changedPages } = findChangedPages(

packages/gatsby/src/services/initialize.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,13 @@ export async function initialize({
427427

428428
// Init plugins once cache is initialized
429429
if (_CFLAGS_.GATSBY_MAJOR === `4`) {
430-
await apiRunnerNode(`onPluginInit`)
430+
await apiRunnerNode(`onPluginInit`, {
431+
parentSpan: activity.span,
432+
})
431433
} else {
432-
await apiRunnerNode(`unstable_onPluginInit`)
434+
await apiRunnerNode(`unstable_onPluginInit`, {
435+
parentSpan: activity.span,
436+
})
433437
}
434438

435439
activity.end()

packages/gatsby/src/services/source-nodes.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ export async function sourceNodes({
3131

3232
reporter.verbose(`Checking for deleted pages`)
3333

34-
const tim = reporter.activityTimer(`Checking for changed pages`)
34+
const tim = reporter.activityTimer(`Checking for changed pages`, {
35+
parentSpan,
36+
})
3537
tim.start()
3638

3739
const { changedPages, deletedPages } = findChangedPages(

packages/gatsby/src/state-machines/query-running/actions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {
77
} from "xstate"
88
import { enqueueFlush } from "../../utils/page-data"
99

10-
export const flushPageData = (): void => {
11-
enqueueFlush()
10+
export const flushPageData = (context: IQueryRunningContext): void => {
11+
enqueueFlush(context.parentSpan)
1212
}
1313

1414
export const assignDirtyQueries = assign<

packages/gatsby/src/utils/page-data.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
reverseFixedPagePath,
1616
IPageData,
1717
} from "./page-data-helpers"
18+
import { Span } from "opentracing"
1819

1920
export { reverseFixedPagePath }
2021

@@ -146,7 +147,7 @@ export function isFlushEnqueued(): boolean {
146147
return isFlushPending
147148
}
148149

149-
export async function flush(): Promise<void> {
150+
export async function flush(parentSpan?: Span): Promise<void> {
150151
if (isFlushing) {
151152
// We're already in the middle of a flush
152153
return
@@ -167,7 +168,8 @@ export async function flush(): Promise<void> {
167168
const writePageDataActivity = reporter.createProgress(
168169
`Writing page-data.json files to public directory`,
169170
pagePaths.size,
170-
0
171+
0,
172+
{ id: `write-page-data-public-directory`, parentSpan }
171173
)
172174
writePageDataActivity.start()
173175

@@ -260,15 +262,15 @@ export async function flush(): Promise<void> {
260262
return
261263
}
262264

263-
export function enqueueFlush(): void {
265+
export function enqueueFlush(parentSpan?: Span): void {
264266
if (isWebpackStatusPending()) {
265267
isFlushPending = true
266268
} else {
267-
flush()
269+
flush(parentSpan)
268270
}
269271
}
270272

271-
export async function handleStalePageData(): Promise<void> {
273+
export async function handleStalePageData(parentSpan: Span): Promise<void> {
272274
if (!(await fs.pathExists(`public/page-data`))) {
273275
return
274276
}
@@ -277,7 +279,9 @@ export async function handleStalePageData(): Promise<void> {
277279
// we get the list of those and compare against expected page-data files
278280
// and remove ones that shouldn't be there anymore
279281

280-
const activity = reporter.activityTimer(`Cleaning up stale page-data`)
282+
const activity = reporter.activityTimer(`Cleaning up stale page-data`, {
283+
parentSpan,
284+
})
281285
activity.start()
282286

283287
const pageDataFilesFromPreviousBuilds = await new Promise<Set<string>>(

0 commit comments

Comments
 (0)