mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-07 07:55:13 +02:00
feat(telemetry): show first-run notice before command output
This commit is contained in:
parent
1953466c78
commit
91772e5bce
3 changed files with 14 additions and 0 deletions
|
|
@ -80,6 +80,11 @@ describe('runCommanderKtxCli telemetry', () => {
|
|||
expect(statusIo.stderr()).toContain('"event":"project_stack_snapshot"');
|
||||
expect(statusIo.stderr()).toContain('"connectionCount"');
|
||||
expect(statusIo.stderr()).not.toContain(tempDir);
|
||||
|
||||
const noticeIndex = statusIo.stderr().indexOf('ktx collects anonymous usage data');
|
||||
const firstTelemetryIndex = statusIo.stderr().indexOf('[telemetry]');
|
||||
expect(noticeIndex).toBeGreaterThanOrEqual(0);
|
||||
expect(firstTelemetryIndex).toBeGreaterThan(noticeIndex);
|
||||
});
|
||||
|
||||
it('emits aborted telemetry when project validation aborts after preAction starts', async () => {
|
||||
|
|
|
|||
|
|
@ -417,6 +417,7 @@ export function buildKtxProgram(options: BuildKtxProgramOptions): Command {
|
|||
program.hook('preAction', async (_thisCommand, actionCommand) => {
|
||||
const telemetry = await import('./telemetry/index.js');
|
||||
options.setTelemetryModule?.(telemetry);
|
||||
await telemetry.showTelemetryNoticeIfNeeded(options.io);
|
||||
const commandNode = actionCommand as CommandPathNode;
|
||||
const path = commandPath(commandNode);
|
||||
const projectDir = resolveCommandProjectDir(commandNode);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,14 @@ import { buildProjectStackSnapshotFields } from './project-snapshot.js';
|
|||
export { beginCommandSpan, completeCommandSpan, shutdownTelemetryEmitter };
|
||||
export type { CommandOutcome, CompletedCommandSpan };
|
||||
|
||||
export async function showTelemetryNoticeIfNeeded(io: KtxCliIo): Promise<void> {
|
||||
await loadTelemetryIdentity({
|
||||
stdoutIsTTY: io.stdout.isTTY === true,
|
||||
stderr: io.stderr,
|
||||
env: process.env,
|
||||
});
|
||||
}
|
||||
|
||||
type TelemetryEventFields<Name extends TelemetryEventName> = Omit<
|
||||
TelemetryEventProperties<Name>,
|
||||
keyof TelemetryCommonEnvelope
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue