Skip to content

Commit d9c0f70

Browse files
authored
feat: improve telemetry (#79)
* feat(cli): print first-run telemetry notice * refactor(cli): switch telemetry mutex to parking_lot * refactor(cli): batch telemetry events via background flusher
1 parent 3ac60dd commit d9c0f70

5 files changed

Lines changed: 172 additions & 83 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ getrandom = "0.4"
4545
libc = "0.2"
4646
tempfile = "3"
4747
jiff = "0.2"
48+
parking_lot = "0.12"
4849

4950
[dev-dependencies]
5051
wiremock = "0.6"

docs/references/steel-cli.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ For generated flags and argument schemas, use [../cli-reference.md](../cli-refer
7777
- Browser session state: `~/.config/steel/browser-session-state.json`
7878
- Profile metadata: `~/.config/steel/profiles/<name>.json`
7979

80+
On the first run where telemetry is enabled, the CLI prints a one-time notice to stderr describing what is collected and how to opt out. The notice is suppressed in JSON/non-TTY output.
81+
8082
Telemetry can be disabled persistently in `config.json` with:
8183

8284
```json

src/commands/mod.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -402,13 +402,14 @@ mod tests {
402402
}
403403

404404
async fn capture_events(server: &MockServer) -> Vec<serde_json::Value> {
405-
server
406-
.received_requests()
407-
.await
408-
.unwrap_or_default()
409-
.into_iter()
410-
.map(|request| serde_json::from_slice(&request.body).unwrap())
411-
.collect()
405+
let mut out = Vec::new();
406+
for request in server.received_requests().await.unwrap_or_default() {
407+
let payload: serde_json::Value = serde_json::from_slice(&request.body).unwrap();
408+
if let Some(batch) = payload.get("batch").and_then(|v| v.as_array()) {
409+
out.extend(batch.iter().cloned());
410+
}
411+
}
412+
out
412413
}
413414

414415
#[tokio::test]
@@ -421,7 +422,7 @@ mod tests {
421422
crate::telemetry::set_test_override(temp.path(), &server.uri());
422423

423424
Mock::given(method("POST"))
424-
.and(path("/i/v0/e/"))
425+
.and(path("/batch/"))
425426
.respond_with(ResponseTemplate::new(200))
426427
.mount(&server)
427428
.await;
@@ -467,7 +468,7 @@ mod tests {
467468
crate::telemetry::set_test_override(temp.path(), &server.uri());
468469

469470
Mock::given(method("POST"))
470-
.and(path("/i/v0/e/"))
471+
.and(path("/batch/"))
471472
.respond_with(ResponseTemplate::new(200))
472473
.mount(&server)
473474
.await;
@@ -539,7 +540,7 @@ mod tests {
539540
crate::telemetry::set_test_override(temp.path(), &server.uri());
540541

541542
Mock::given(method("POST"))
542-
.and(path("/i/v0/e/"))
543+
.and(path("/batch/"))
543544
.respond_with(ResponseTemplate::new(200))
544545
.mount(&server)
545546
.await;

0 commit comments

Comments
 (0)