@@ -16,6 +16,18 @@ let tasks: Promise<any>[] = [];
16
16
// send telemetry
17
17
const sessionId = nanoid ( ) ;
18
18
19
+ export const addToGlobalContext = ( key : string , value : any ) => {
20
+ globalContext [ key ] = value ;
21
+ } ;
22
+
23
+ // context info sent with all events, provided
24
+ // by the app. currently:
25
+ // - cliVersion
26
+ const globalContext = {
27
+ inCI : Boolean ( process . env . CI ) ,
28
+ isTTY : process . stdout . isTTY ,
29
+ } as Record < string , any > ;
30
+
19
31
export async function sendTelemetry (
20
32
data : TelemetryData ,
21
33
options : Partial < Options > = { retryDelay : 1000 , immediate : false }
@@ -27,11 +39,10 @@ export async function sendTelemetry(
27
39
// flatten the data before we send it
28
40
const { eventType, payload, metadata, ...rest } = data ;
29
41
const context = options . stripMetadata
30
- ? { }
42
+ ? globalContext
31
43
: {
44
+ ...globalContext ,
32
45
anonymousId : getAnonymousProjectId ( ) ,
33
- inCI : Boolean ( process . env . CI ) ,
34
- isTTY : process . stdout . isTTY ,
35
46
} ;
36
47
const eventId = nanoid ( ) ;
37
48
const body = { ...rest , eventType, eventId, sessionId, metadata, payload, context } ;
0 commit comments