Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Capture telemetry when requesting completions in agent2 (#36600)

Antonio Scandurra699f58aeba56
diff --git a/Cargo.lock b/Cargo.lock
index fdc858ef50f..342bb1058fb 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -239,6 +239,7 @@ dependencies = [
"smol",
"sqlez",
"task",
+ "telemetry",
"tempfile",
"terminal",
"text",
diff --git a/crates/agent2/Cargo.toml b/crates/agent2/Cargo.toml
index bc32a796222..2a5d879e9ec 100644
--- a/crates/agent2/Cargo.toml
+++ b/crates/agent2/Cargo.toml
@@ -58,6 +58,7 @@ settings.workspace = true
smol.workspace = true
sqlez.workspace = true
task.workspace = true
+telemetry.workspace = true
terminal.workspace = true
text.workspace = true
ui.workspace = true
diff --git a/crates/agent2/src/thread.rs b/crates/agent2/src/thread.rs
index c7b1a08b92b..f407ee7de54 100644
--- a/crates/agent2/src/thread.rs
+++ b/crates/agent2/src/thread.rs
@@ -1195,6 +1195,15 @@ impl Thread {
let mut attempt = None;
'retry: loop {
+ telemetry::event!(
+ "Agent Thread Completion",
+ thread_id = this.read_with(cx, |this, _| this.id.to_string())?,
+ prompt_id = this.read_with(cx, |this, _| this.prompt_id.to_string())?,
+ model = model.telemetry_id(),
+ model_provider = model.provider_id().to_string(),
+ attempt
+ );
+
let mut events = model.stream_completion(request.clone(), cx).await?;
let mut tool_uses = FuturesUnordered::new();
while let Some(event) = events.next().await {
@@ -1211,8 +1220,21 @@ impl Thread {
this.update_model_request_usage(amount, limit, cx)
})?;
}
- Ok(LanguageModelCompletionEvent::UsageUpdate(token_usage)) => {
- this.update(cx, |this, cx| this.update_token_usage(token_usage, cx))?;
+ Ok(LanguageModelCompletionEvent::UsageUpdate(usage)) => {
+ telemetry::event!(
+ "Agent Thread Completion Usage Updated",
+ thread_id = this.read_with(cx, |this, _| this.id.to_string())?,
+ prompt_id = this.read_with(cx, |this, _| this.prompt_id.to_string())?,
+ model = model.telemetry_id(),
+ model_provider = model.provider_id().to_string(),
+ attempt,
+ input_tokens = usage.input_tokens,
+ output_tokens = usage.output_tokens,
+ cache_creation_input_tokens = usage.cache_creation_input_tokens,
+ cache_read_input_tokens = usage.cache_read_input_tokens,
+ );
+
+ this.update(cx, |this, cx| this.update_token_usage(usage, cx))?;
}
Ok(LanguageModelCompletionEvent::Stop(StopReason::Refusal)) => {
*refusal = true;