@@ -16,10 +16,34 @@ const TELEMETRY_REASON_LABELS = {
1616 "update-disabled" : "update checks are disabled" ,
1717} satisfies Record < ReturnType < typeof resolveTelemetryStatus > [ "reason" ] , string > ;
1818
19- async function showTelemetry ( ) : Promise < void > {
19+ async function showTelemetry ( options : { json ?: boolean } ) : Promise < void > {
2020 const config = getRuntimeConfig ( { skipPluginValidation : true } ) ;
2121 const telemetry = resolveTelemetryStatus ( config ) ;
2222 const userAgent = buildTelemetryUserAgent ( "gateway" ) ;
23+ const requestSent = telemetry . reason !== "update-disabled" ;
24+ const payload = telemetry . enabled
25+ ? buildTelemetryPayload ( config , { surface : "gateway" } )
26+ : undefined ;
27+
28+ if ( options . json ) {
29+ defaultRuntime . log (
30+ JSON . stringify ( {
31+ featureStatsEnabled : telemetry . enabled ,
32+ reason : telemetry . reason ,
33+ endpoint : telemetry . endpoint ,
34+ lastPingAt : telemetry . lastPingAt ? new Date ( telemetry . lastPingAt ) . toISOString ( ) : null ,
35+ request : requestSent
36+ ? {
37+ method : telemetry . enabled ? "POST" : "GET" ,
38+ userAgent,
39+ ...( payload ? { payload } : { } ) ,
40+ }
41+ : null ,
42+ } ) ,
43+ ) ;
44+ return ;
45+ }
46+
2347 defaultRuntime . log ( `Feature stats: ${ telemetry . enabled ? "enabled" : "disabled" } ` ) ;
2448 defaultRuntime . log ( `Reason: ${ TELEMETRY_REASON_LABELS [ telemetry . reason ] } ` ) ;
2549 defaultRuntime . log ( `Endpoint: ${ telemetry . endpoint } ` ) ;
@@ -32,9 +56,9 @@ async function showTelemetry(): Promise<void> {
3256 }
3357 defaultRuntime . log ( `Request: ${ telemetry . enabled ? "POST" : "GET" } ${ telemetry . endpoint } ` ) ;
3458 defaultRuntime . log ( `User-Agent: ${ userAgent } ` ) ;
35- if ( telemetry . enabled ) {
59+ if ( payload ) {
3660 defaultRuntime . log ( "Payload:" ) ;
37- defaultRuntime . log ( JSON . stringify ( buildTelemetryPayload ( config , { surface : "gateway" } ) ) ) ;
61+ defaultRuntime . log ( JSON . stringify ( payload ) ) ;
3862 }
3963}
4064
@@ -62,7 +86,10 @@ export function registerTelemetryCli(program: Command): void {
6286 telemetry
6387 . command ( "show" )
6488 . description ( "Show exactly what the daily update request sends" )
65- . action ( async ( ) => runCommandWithRuntime ( defaultRuntime , showTelemetry ) ) ;
89+ . option ( "--json" , "Print the request and payload as JSON" )
90+ . action ( async ( options : { json ?: boolean } ) =>
91+ runCommandWithRuntime ( defaultRuntime , ( ) => showTelemetry ( options ) ) ,
92+ ) ;
6693
6794 telemetry
6895 . command ( "on" )
0 commit comments