Skip to content

Commit 8072980

Browse files
authored
Merge pull request #9417 from gitbutlerapp/kv-branch-33
Consolidate the CLI posthog events and use a command property
2 parents f512809 + 06c9fa2 commit 8072980

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

crates/but/src/metrics/mod.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,21 @@ pub struct Metrics {
1313
sender: Option<tokio::sync::mpsc::UnboundedSender<Event>>,
1414
}
1515

16-
#[derive(Debug, Clone, Serialize, Deserialize, strum::Display)]
16+
#[derive(Debug, Clone, Copy, Serialize, Deserialize, strum::Display)]
1717
#[serde(rename_all = "camelCase")]
1818
pub enum EventKind {
1919
Mcp,
2020
McpInternal,
21-
CliLog,
22-
CliStatus,
23-
CliRub,
21+
#[strum(serialize = "Cli")]
22+
Cli(Command),
23+
}
24+
25+
#[derive(Debug, Clone, Copy, Serialize, Deserialize, strum::Display)]
26+
#[serde(rename_all = "camelCase")]
27+
pub enum Command {
28+
Log,
29+
Status,
30+
Rub,
2431
ClaudePreTool,
2532
ClaudePostTool,
2633
ClaudeStop,
@@ -30,13 +37,13 @@ pub enum EventKind {
3037
impl From<CommandName> for EventKind {
3138
fn from(command_name: CommandName) -> Self {
3239
match command_name {
33-
CommandName::Log => EventKind::CliLog,
34-
CommandName::Status => EventKind::CliStatus,
35-
CommandName::Rub => EventKind::CliRub,
36-
CommandName::ClaudePreTool => EventKind::ClaudePreTool,
37-
CommandName::ClaudePostTool => EventKind::ClaudePostTool,
38-
CommandName::ClaudeStop => EventKind::ClaudeStop,
39-
_ => EventKind::Unknown,
40+
CommandName::Log => EventKind::Cli(Command::Log),
41+
CommandName::Status => EventKind::Cli(Command::Status),
42+
CommandName::Rub => EventKind::Cli(Command::Rub),
43+
CommandName::ClaudePreTool => EventKind::Cli(Command::ClaudePreTool),
44+
CommandName::ClaudePostTool => EventKind::Cli(Command::ClaudePostTool),
45+
CommandName::ClaudeStop => EventKind::Cli(Command::ClaudeStop),
46+
_ => EventKind::Cli(Command::Unknown),
4047
}
4148
}
4249
}
@@ -86,6 +93,9 @@ impl Event {
8693
event_name,
8794
props: HashMap::new(),
8895
};
96+
if let EventKind::Cli(command) = event_name {
97+
event.insert_prop("command", command);
98+
}
8999
event.insert_prop("appVersion", option_env!("VERSION").unwrap_or_default());
90100
event.insert_prop("releaseChannel", option_env!("CHANNEL").unwrap_or_default());
91101
event.insert_prop("appName", option_env!("CARGO_BIN_NAME").unwrap_or_default());

0 commit comments

Comments
 (0)