|
1 | 1 | import chalk from "chalk"; |
2 | 2 | import { fetch } from "undici"; |
3 | | -import _isInteractive from "../is-interactive"; |
| 3 | +import isInteractive from "../is-interactive"; |
4 | 4 | import { logger } from "../logger"; |
5 | 5 | import { CI } from "./../is-ci"; |
6 | 6 | import { |
@@ -28,16 +28,9 @@ export function getMetricsDispatcher(options: MetricsConfigOptions) { |
28 | 28 | const SPARROW_SOURCE_KEY = process.env.SPARROW_SOURCE_KEY ?? ""; |
29 | 29 | const requests: Array<Promise<void>> = []; |
30 | 30 | const wranglerVersion = getWranglerVersion(); |
31 | | - const osPlatform = getPlatform(); |
32 | | - const osVersion = getOSVersion(); |
33 | | - const nodeVersion = getNodeVersion(); |
34 | | - const packageManager = getPackageManager(); |
35 | | - const isFirstUsage = readMetricsConfig().permission === undefined; |
36 | | - const isCI = CI.isCI(); |
37 | | - const isInteractive = _isInteractive(); |
38 | 31 | const amplitude_session_id = Date.now(); |
39 | | - const configFileType = getConfigFileType(options.configPath); |
40 | 32 | let amplitude_event_id = 0; |
| 33 | + |
41 | 34 | /** We redact strings in arg values, unless they are named here */ |
42 | 35 | const allowList = { |
43 | 36 | // applies to all commands |
@@ -95,20 +88,20 @@ export function getMetricsDispatcher(options: MetricsConfigOptions) { |
95 | 88 | amplitude_session_id, |
96 | 89 | amplitude_event_id: amplitude_event_id++, |
97 | 90 | wranglerVersion, |
98 | | - osPlatform, |
99 | | - osVersion, |
100 | | - nodeVersion, |
101 | | - packageManager, |
102 | | - isFirstUsage, |
103 | | - configFileType, |
104 | | - isCI, |
105 | | - isInteractive, |
| 91 | + osPlatform: getPlatform(), |
| 92 | + osVersion: getOSVersion(), |
| 93 | + nodeVersion: getNodeVersion(), |
| 94 | + packageManager: await getPackageManager(), |
| 95 | + isFirstUsage: readMetricsConfig().permission === undefined, |
| 96 | + configFileType: getConfigFileType(options.configPath), |
| 97 | + isCI: CI.isCI(), |
| 98 | + isInteractive: isInteractive(), |
106 | 99 | argsUsed, |
107 | 100 | argsCombination, |
108 | 101 | }; |
109 | | - // we redact all args unless they are in the allowList |
110 | | - const allowedKeys = getAllowedKeys(allowList, properties.command ?? ""); |
111 | | - properties.args = redactArgValues(properties.args ?? {}, allowedKeys); |
| 102 | + // get the args where we don't want to redact their values |
| 103 | + const allowedArgs = getAllowedArgs(allowList, properties.command ?? ""); |
| 104 | + properties.args = redactArgValues(properties.args ?? {}, allowedArgs); |
112 | 105 | await dispatch({ |
113 | 106 | name, |
114 | 107 | properties: { |
@@ -154,8 +147,8 @@ export function getMetricsDispatcher(options: MetricsConfigOptions) { |
154 | 147 |
|
155 | 148 | logger.debug(`Metrics dispatcher: Posting data ${JSON.stringify(body)}`); |
156 | 149 |
|
157 | | - // Do not await this fetch call. |
158 | | - // Just fire-and-forget, otherwise we might slow down the rest of Wrangler. |
| 150 | + // Don't await fetch but make sure requests are resolved (with a timeout) |
| 151 | + // before exiting Wrangler |
159 | 152 | const request = fetch(`${SPARROW_URL}/api/v1/event`, { |
160 | 153 | method: "POST", |
161 | 154 | headers: { |
@@ -235,7 +228,7 @@ const sanitiseUserInput = (argsWithValues: Record<string, unknown>) => { |
235 | 228 | return result; |
236 | 229 | }; |
237 | 230 |
|
238 | | -const getAllowedKeys = ( |
| 231 | +const getAllowedArgs = ( |
239 | 232 | allowList: Record<string, string[]> & { "*": string[] }, |
240 | 233 | key: string |
241 | 234 | ) => { |
|
0 commit comments