-
Notifications
You must be signed in to change notification settings - Fork 0
GRA-1144: add opt-in SDK WAU telemetry #251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -132,6 +132,24 @@ def cmd_stats(args): | |
| print(f" Has embeddings: {stats['has_embeddings']}") | ||
|
|
||
|
|
||
| def cmd_telemetry(args): | ||
| """Telemetry visibility commands.""" | ||
| from gradata import _telemetry | ||
|
|
||
| if args.telemetry_cmd == "wau": | ||
| data = _telemetry.fetch_wau() | ||
| if args.json: | ||
| print(json.dumps(data, indent=2, sort_keys=True)) | ||
| return | ||
| print(f"WAU: {data.get('wau', 0)}") | ||
| if data.get("week_start"): | ||
| print(f"Week start: {data['week_start']}") | ||
| if data.get("error"): | ||
| print(f"Status: {data['error']}") | ||
| return | ||
| raise SystemExit("unknown telemetry command") | ||
|
Comment on lines
+135
to
+150
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win Add deterministic CLI coverage for This introduces a new user-facing command, but the provided tests only cover As per coding guidelines, "Add unit tests in 🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
| def cmd_status(args): | ||
| """Single human-readable summary of brain health. | ||
|
|
||
|
|
@@ -1988,6 +2006,12 @@ def main(): | |
| # stats | ||
| sub.add_parser("stats", help="Brain statistics") | ||
|
|
||
| # telemetry | ||
| p_telemetry = sub.add_parser("telemetry", help="Anonymous opt-in telemetry commands") | ||
| telemetry_sub = p_telemetry.add_subparsers(dest="telemetry_cmd", required=True) | ||
| p_wau = telemetry_sub.add_parser("wau", help="Show live weekly active user count") | ||
| p_wau.add_argument("--json", action="store_true", help="Output raw aggregate JSON") | ||
|
|
||
| # status (umbrella health check: stats + daemon + cloud + convergence) | ||
| sub.add_parser("status", help="Single-page brain/daemon/cloud summary") | ||
|
|
||
|
|
@@ -2347,6 +2371,7 @@ def main(): | |
| "embed": cmd_embed, | ||
| "manifest": cmd_manifest, | ||
| "stats": cmd_stats, | ||
| "telemetry": cmd_telemetry, | ||
| "status": cmd_status, | ||
| "audit": cmd_audit, | ||
| "sync": cmd_sync, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,6 +136,26 @@ def test_posts_when_enabled(self): | |
| payload = post.call_args[0][0] | ||
| assert payload["event"] == "brain_initialized" | ||
|
|
||
| def test_session_ping_posts_wau_to_ping_endpoint(self, monkeypatch): | ||
| _telemetry.set_enabled(True) | ||
| monkeypatch.setenv(_telemetry.ENV_ENDPOINT, "https://api.example.com/telemetry/event") | ||
| with patch.object(_telemetry, "_post", return_value=True) as post: | ||
| _telemetry.send_session_ping(blocking=True) | ||
| post.assert_called_once() | ||
| assert post.call_args[0][0]["event"] == "wau_ping" | ||
| assert _telemetry._ping_endpoint() == "https://api.example.com/telemetry/ping" | ||
|
Comment on lines
+139
to
+146
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assert the derived endpoint on the This currently proves Suggested assertion with patch.object(_telemetry, "_post", return_value=True) as post:
_telemetry.send_session_ping(blocking=True)
post.assert_called_once()
assert post.call_args[0][0]["event"] == "wau_ping"
+ assert post.call_args.kwargs["endpoint"] == "https://api.example.com/telemetry/ping"
assert _telemetry._ping_endpoint() == "https://api.example.com/telemetry/ping"🤖 Prompt for AI Agents |
||
|
|
||
| def test_session_ping_noop_when_disabled(self): | ||
| with patch.object(_telemetry, "_post") as post: | ||
| _telemetry.send_session_ping(blocking=True) | ||
| post.assert_not_called() | ||
|
|
||
| def test_fetch_wau_returns_error_dict_on_failure(self, monkeypatch): | ||
| monkeypatch.setenv(_telemetry.ENV_ENDPOINT, "http://127.0.0.1:9/telemetry/event") | ||
| data = _telemetry.fetch_wau(timeout=0.01) | ||
| assert data["wau"] == 0 | ||
| assert data["error"] == "unavailable" | ||
|
|
||
| def test_respects_kill_switch(self, monkeypatch): | ||
| _telemetry.set_enabled(True) | ||
| monkeypatch.setenv(_telemetry.ENV_KILL_SWITCH, "0") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not claim the SDK never sends raw IP addresses.
The payload excludes IP fields, but the telemetry service and normal network infrastructure still see the request source IP at transport time. As written, this privacy disclosure is inaccurate.
Suggested rewording
📝 Committable suggestion
🤖 Prompt for AI Agents