160
const errorNameOf = (error: unknown): string =>
161
error instanceof Error && error.name ? error.name : 'UnknownError';
162
163
-const errorMessageOf = (error: unknown): string => {
164
- if (error instanceof Error && error.message) return error.message.slice(0, 500);
165
- if (typeof error === 'string') return error.slice(0, 500);
166
- return 'Unknown error';
167
-};
168
-
163
const isFlagPresent = (argv: ReadonlyArray<string>, ...flags: string[]): boolean =>
164
argv.slice(2).some(token => {
165
if (flags.includes(token)) return true;
246
};
247
};
248
255
-const getSearchCommandProperties = (context: CliCommandTelemetryContext) => ({
256
- source: 'cli',
257
- invocation_origin: getInvocationOrigin(),
258
- parent_run_id: getParentRunId(),
259
- parent_command: getParentRunId() ? 'run' : undefined,
260
- cli_version: context.cliVersion,
261
- command_path: context.commandPath,
262
- duration_ms: Date.now() - context.startedAt,
263
- query: getTrailingPositionals(context)[0],
264
- search_query: getTrailingPositionals(context)[0],
265
- toolkits: getFlagValue(context.argv, '--toolkits'),
266
- limit: getFlagValue(context.argv, '--limit'),
267
-});
249
+// Search queries are user-authored free text, so only their shape is recorded.
250
+const getSearchCommandProperties = (context: CliCommandTelemetryContext) => {
251
+ const query = getTrailingPositionals(context)[0] ?? '';
252
+ return {
253
+ source: 'cli',
254
+ invocation_origin: getInvocationOrigin(),
255
+ parent_run_id: getParentRunId(),
256
+ parent_command: getParentRunId() ? 'run' : undefined,
257
+ cli_version: context.cliVersion,
258
+ command_path: context.commandPath,
259
+ duration_ms: Date.now() - context.startedAt,
260
+ query_length: query.length,
261
+ query_term_count: query.split(/\s+/u).filter(Boolean).length,
262
+ toolkits: getFlagValue(context.argv, '--toolkits'),
263
+ limit: getFlagValue(context.argv, '--limit'),
264
+ };
265
+};
266
267
const getLinkCommandProperties = (context: CliCommandTelemetryContext) => {
268
const firstPositional = getTrailingPositionals(context)[0];
346
cli_version: context.cliVersion,
347
command_path: context.commandPath,
348
duration_ms: Date.now() - context.startedAt,
351
- endpoint: getTrailingPositionals(context)[0],
349
+ has_endpoint: typeof getTrailingPositionals(context)[0] === 'string',
350
toolkit: getFlagValue(context.argv, '--toolkit', '-t'),
351
method: getFlagValue(context.argv, '--method', '-X') ?? 'GET',
352
has_data: isFlagPresent(context.argv, '--data', '-d'),
437
duration_ms: Date.now() - context.startedAt,
438
flag_names: context.flagNames,
439
error_name: errorNameOf(error),
442
- error_message: errorMessageOf(error),
440
},
441
});
442
556
properties: {
557
...family.getProperties(context),
558
error_name: errorNameOf(error),
562
- error_message: errorMessageOf(error),
559
},
560
};
561
};
598
agent_host: params.target,
599
phase: params.phase,
600
error_name: errorNameOf(params.error),
605
- error_message: errorMessageOf(params.error),
601
},
602
});
603
741
error_slug: params.errorSlug,
742
http_status: params.status,
743
api_error_code: params.apiCode,
749
- error_message: params.message?.slice(0, 500),
744
...argumentShape(params.args),
745
},
746
});
775
http_status: params.status,
776
api_error_code: params.apiCode,
777
error_name: params.errorName,
784
- error_message: params.message?.slice(0, 500),
778
is_no_connection_error: Boolean(params.isNoConnectionError),
779
...argumentShape(params.args),
780
},