File tree 1 file changed +16
-2
lines changed
packages/gatsby-telemetry/src
1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -165,12 +165,26 @@ export class AnalyticsTracker {
165
165
}
166
166
167
167
// 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
169
170
getSessionId ( ) : string {
170
171
const p = process as any
171
172
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
173
186
}
187
+
174
188
return p . gatsbyTelemetrySessionId
175
189
}
176
190
You can’t perform that action at this time.
0 commit comments