Skip to content

Commit b72b5bc

Browse files
authored
chore(telemetry): ensure forked develop child processes have the same sessionId (#28799)
* chore(telemetry): ensure forked develop child processes have the same sessionId * Add patch from @pieh to ensure it works with old gatsby-cli
1 parent 2059ead commit b72b5bc

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

packages/gatsby-telemetry/src/telemetry.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,26 @@ export class AnalyticsTracker {
165165
}
166166

167167
// We might have two instances of this lib loaded, one from globally installed gatsby-cli and one from local gatsby.
168-
// Hence we need to use process level globals that are not scoped to this module
168+
// Hence we need to use process level globals that are not scoped to this module.
169+
// Due to the forking on develop process, we also need to pass this via process.env so that child processes have the same sessionId
169170
getSessionId(): string {
170171
const p = process as any
171172
if (!p.gatsbyTelemetrySessionId) {
172-
p.gatsbyTelemetrySessionId = uuidv4()
173+
const inherited = process.env.INTERNAL_GATSBY_TELEMETRY_SESSION_ID
174+
if (inherited) {
175+
p.gatsbyTelemetrySessionId = inherited
176+
} else {
177+
p.gatsbyTelemetrySessionId = uuidv4()
178+
process.env.INTERNAL_GATSBY_TELEMETRY_SESSION_ID =
179+
p.gatsbyTelemetrySessionId
180+
}
181+
} else if (!process.env.INTERNAL_GATSBY_TELEMETRY_SESSION_ID) {
182+
// in case older `gatsby-telemetry` already set `gatsbyTelemetrySessionId` property on process
183+
// but didn't set env var - let's make sure env var is set
184+
process.env.INTERNAL_GATSBY_TELEMETRY_SESSION_ID =
185+
p.gatsbyTelemetrySessionId
173186
}
187+
174188
return p.gatsbyTelemetrySessionId
175189
}
176190

0 commit comments

Comments
 (0)