Skip to content

Commit 40a0daa

Browse files
committed
feat: added telemetry collection via posthog
1 parent 3efaf3d commit 40a0daa

File tree

5 files changed

+59
-4
lines changed

5 files changed

+59
-4
lines changed

.changeset/salty-cases-change.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@calycode/cli": minor
3+
---
4+
5+
feat: Posthog integration and basic telemetry collection

packages/cli/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@
4444
"homepage": "https://github.com/calycode/xano-tools/tree/main/packages/cli#readme",
4545
"devDependencies": {
4646
"@calycode/core": "workspace:*",
47+
"@clack/prompts": "^0.11.0",
4748
"@repo/types": "workspace:*",
4849
"@repo/utils": "workspace:*",
49-
"shx": "^0.4.0",
50-
"@clack/prompts": "^0.11.0",
5150
"commander": "^14.0.0",
5251
"js-yaml": "^4.1.0",
52+
"shx": "^0.4.0",
5353
"tar": "^7.4.3"
5454
},
5555
"scripts": {
@@ -58,5 +58,8 @@
5858
"build:chmod": "shx chmod +x dist/index.cjs",
5959
"build": "pnpm build:js && pnpm build:chmod && pnpm link -g",
6060
"xano": "node dist/index.cjs"
61+
},
62+
"dependencies": {
63+
"posthog-node": "^5.9.2"
6164
}
6265
}

packages/cli/src/commands/setup-instance.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { intro, text, password, confirm } from '@clack/prompts';
1+
import { intro, text, password, confirm, log } from '@clack/prompts';
22
import { sanitizeInstanceName } from '@repo/utils';
33
import { ensureGitignore, withErrorHandler } from '../utils/index';
44

@@ -41,6 +41,24 @@ async function setupInstanceWizard(core) {
4141
})) as boolean;
4242
}
4343

44+
log.info(
45+
`
46+
Thank you for using @calycode/cli! 🚀
47+
48+
To help us improve, we collect anonymous telemetry data via our PostHog instance.
49+
Here’s exactly what we track:
50+
• Command names (e.g., generate-oas)
51+
• Command duration
52+
• Technical data:
53+
– IP address (IPv6)
54+
– Timestamp
55+
– PostHog library version
56+
57+
By continuing to use @calycode/cli, you consent to this data collection.
58+
We appreciate your support and commitment to making @calycode/cli better!
59+
`
60+
);
61+
4462
// Run the core setup logic
4563
await core.setupInstance({
4664
name: instanceName,

packages/cli/src/program.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { registerRegistryAddCommand, registerRegistryScaffoldCommand } from './c
1414
import { registerOasServeCommand, registerRegistryServeCommand } from './commands/serve';
1515
import { registerBuildXanoscriptRepoCommand } from './commands/generate-xanoscript-repo';
1616
import { Caly } from '@calycode/core';
17+
import { InitializedPostHog } from './utils/posthog/init';
1718
import { nodeConfigStorage } from './node-config-storage';
1819

1920
const commandStartTimes = new WeakMap<Command, number>();
@@ -23,11 +24,22 @@ const program = new Command();
2324
const core = new Caly(nodeConfigStorage);
2425

2526
// Store start time on the command object
26-
program.hook('preAction', (thisCommand) => {
27+
program.hook('preAction', (thisCommand, actionCommand) => {
28+
console.log(actionCommand.name());
2729
commandStartTimes.set(thisCommand, Date.now());
30+
// [ ] Add some system information to the capture
31+
InitializedPostHog.capture({
32+
distinctId: 'anonymous',
33+
event: 'command_started',
34+
properties: {
35+
"command": actionCommand.name()
36+
}
37+
});
38+
InitializedPostHog.shutdown();
2839
});
2940

3041
program.hook('postAction', (thisCommand, actionCommand) => {
42+
console.log(actionCommand.name());
3143
const start = commandStartTimes.get(thisCommand);
3244
if (!start) {
3345
// Could happen if preAction failed, or if there's a bug
@@ -42,6 +54,16 @@ program.hook('postAction', (thisCommand, actionCommand) => {
4254
: actionCommand.name();
4355

4456
console.log(`\n⏱️ Command "${commandPath}" completed in ${duration}s`);
57+
// [ ] Add some outcome capture in a very anonymous manner
58+
InitializedPostHog.capture({
59+
distinctId: 'anonymous',
60+
event: 'command_finished',
61+
properties: {
62+
"command": actionCommand.name(),
63+
duration: duration
64+
}
65+
});
66+
InitializedPostHog.shutdown();
4567
});
4668

4769
program
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { PostHog } from 'posthog-node';
2+
3+
const InitializedPostHog = new PostHog('phc_MrSAUUthn4y0PWjbxVt9a9ys7TrQKMQhdYvErJFPvE3', {
4+
host: 'https://eu.i.posthog.com',
5+
});
6+
7+
export { InitializedPostHog };

0 commit comments

Comments
 (0)