Files
oak-gpui/crates/telemetry_events/src/telemetry_events.rs
T
Joseph T. Lyons b6189b05f9 Add telemetry for supermaven (#11821)
Data migration plan:

- [X] Make a duplicate table of `copilot_events`
    - Name: `inline_completion_events`
    - Omit `suggestion_id` column
- [X-reverted-skipping] In collab, continue to match on copilot_events,
but simply stuff their data into inline_completion_events, to forward it
to the new table
- [skipping] Once collab is deployed, ensure no events are being sent to
copilot_events, migrate `copilot_events` to new table via a transaction
- [skipping] Delete `copilot_events` table

---

- [X] Locally test that copilot events sent from old clients get put
into inline_completions_table
- [X] Locally test that copilot events and supermaven events sent from
new clients get put into inline_completions_table

---

- [X] Why are discard events being spammed?
- A:
https://github.com/zed-industries/zed/blob/8d4315712bc706a9b04d9daf638b264e5789b1f9/crates/editor/src/editor.rs#L2147


![scr-20240514-pqmg](https://github.com/zed-industries/zed/assets/19867440/e51e7ae4-21b8-47a2-bfaa-f68fb355e409)

This will throw off the past results for accepted / dismissed that I was
wanting to use to evaluate Supermaven quality, by comparing its rate
with copilot's rate.

I'm not super thrilled with this fix, but I think it'll do. In the
`supermaven_completions_provider`, we check if there's a `completion_id`
before sending either an accepted or discard completion event. I don't
see a similar construct in the `copilot_completions_provider` to
piggyback off of, so I begrudgingly introduced
`should_allow_event_to_send` and had it follow the same pattern that
`completion_id` does. Maybe there's a better way?

---

Adds events to supermaven suggestions. Makes "CopilotEvents" generic ->
"InlineCompletionEvents".

Release Notes:

- N/A
2024-05-16 17:18:32 -04:00

196 lines
5.0 KiB
Rust

use semantic_version::SemanticVersion;
use serde::{Deserialize, Serialize};
use std::{fmt::Display, sync::Arc, time::Duration};
#[derive(Serialize, Deserialize, Debug)]
pub struct EventRequestBody {
pub installation_id: Option<String>,
pub session_id: Option<String>,
pub is_staff: Option<bool>,
pub app_version: String,
pub os_name: String,
pub os_version: Option<String>,
pub architecture: String,
pub release_channel: Option<String>,
pub events: Vec<EventWrapper>,
}
impl EventRequestBody {
pub fn semver(&self) -> Option<SemanticVersion> {
self.app_version.parse().ok()
}
}
#[derive(Serialize, Deserialize, Debug)]
pub struct EventWrapper {
pub signed_in: bool,
pub milliseconds_since_first_event: i64,
#[serde(flatten)]
pub event: Event,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum AssistantKind {
Panel,
Inline,
}
impl Display for AssistantKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
Self::Panel => "panel",
Self::Inline => "inline",
}
)
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum Event {
Editor(EditorEvent),
Copilot(CopilotEvent), // Needed for clients sending old copilot_event types
InlineCompletion(InlineCompletionEvent),
Call(CallEvent),
Assistant(AssistantEvent),
Cpu(CpuEvent),
Memory(MemoryEvent),
App(AppEvent),
Setting(SettingEvent),
Extension(ExtensionEvent),
Edit(EditEvent),
Action(ActionEvent),
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct EditorEvent {
pub operation: String,
pub file_extension: Option<String>,
pub vim_mode: bool,
pub copilot_enabled: bool,
pub copilot_enabled_for_language: bool,
}
// Needed for clients sending old copilot_event types
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct CopilotEvent {
pub suggestion_id: Option<String>,
pub suggestion_accepted: bool,
pub file_extension: Option<String>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct InlineCompletionEvent {
pub provider: String,
pub suggestion_accepted: bool,
pub file_extension: Option<String>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct CallEvent {
pub operation: String,
pub room_id: Option<u64>,
pub channel_id: Option<u64>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct AssistantEvent {
pub conversation_id: Option<String>,
pub kind: AssistantKind,
pub model: String,
pub response_latency: Option<Duration>,
pub error_message: Option<String>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct CpuEvent {
pub usage_as_percentage: f32,
pub core_count: u32,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MemoryEvent {
pub memory_in_bytes: u64,
pub virtual_memory_in_bytes: u64,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ActionEvent {
pub source: String,
pub action: String,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct EditEvent {
pub duration: i64,
pub environment: String,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct SettingEvent {
pub setting: String,
pub value: String,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ExtensionEvent {
pub extension_id: Arc<str>,
pub version: Arc<str>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct AppEvent {
pub operation: String,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct BacktraceFrame {
pub ip: usize,
pub symbol_addr: usize,
pub base: Option<usize>,
pub symbols: Vec<String>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct HangReport {
pub backtrace: Vec<BacktraceFrame>,
pub app_version: Option<SemanticVersion>,
pub os_name: String,
pub os_version: Option<SemanticVersion>,
pub architecture: String,
pub installation_id: Option<String>,
}
#[derive(Serialize, Deserialize)]
pub struct LocationData {
pub file: String,
pub line: u32,
}
#[derive(Serialize, Deserialize)]
pub struct Panic {
pub thread: String,
pub payload: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub location_data: Option<LocationData>,
pub backtrace: Vec<String>,
pub app_version: String,
pub release_channel: String,
pub os_name: String,
pub os_version: Option<String>,
pub architecture: String,
pub panicked_on: i64,
#[serde(skip_serializing_if = "Option::is_none")]
pub installation_id: Option<String>,
pub session_id: String,
}
#[derive(Serialize, Deserialize)]
pub struct PanicRequest {
pub panic: Panic,
}