Repository navigation
feat(analytics): report usage to Reo alongside Scarf - #473
marcduiker wants to merge 9 commits into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Marc Duiker <4191277+marcduiker@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Marc Duiker <4191277+marcduiker@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Marc Duiker <4191277+marcduiker@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Marc Duiker <4191277+marcduiker@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Marc Duiker <4191277+marcduiker@users.noreply.github.com>
…tics Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Marc Duiker <4191277+marcduiker@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Marc Duiker <4191277+marcduiker@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Marc Duiker <4191277+marcduiker@users.noreply.github.com>
CasperGN
left a comment
There was a problem hiding this comment.
Thanks for the PR @marcduiker 🙌 Routing both destinations through one Sink list with a shared _select_sinks is a clean way to keep the dedupe and gates from drifting apart. The Reo gate failing closed, and the golden tests that pin Scarf's exact URL and User-Agent, make this easy to trust 🧪 I left a couple of comments inline, please take a look.
Drafted with AI assistance and reviewed by me.
| if analytics is None: | ||
| return | ||
| try: | ||
| analytics.report_usage_blocking("diagrid-cli", sinks=(analytics.REO_SINK,)) |
There was a problem hiding this comment.
This makes diagridpy report on every run, including --help and --version, and it blocks for up to a second. The README covers it, but a CLI user who never reads the README sees nothing. What do you think about printing a one-time notice to stderr on first run that names the opt-out variables (DO_NOT_TRACK, DIAGRID_NO_ANALYTICS)? It could be recorded with a marker file under the user's config dir, the way dotnet, Homebrew and the Azure CLI handle telemetry. It's a small change, and it saves the first person who notices the outbound request from opening an issue about it. Not blocking.
There was a problem hiding this comment.
Added in a4f66c6. The first time diagridpy is about to send an event, it prints a two-line notice to stderr that names DO_NOT_TRACK and DIAGRID_NO_ANALYTICS. Then it writes ~/.diagrid/telemetry-notice-shown (or the same file under $DIAGRID_HOME), so the notice only shows once. When reporting is skipped (opted out, CI, Kubernetes, a Catalyst target, shell completion) it prints nothing and writes no marker. If the marker can't be written, the command still exits normally and the notice shows again on the next run. I added a line about it to the README too.
| def report_usage(package: str, **dimensions: object) -> None: | ||
| # ``sinks`` is accepted and ignored: an older core has no destination list. | ||
| def report_usage( | ||
| package: str, *, sinks: Sequence["Sink"] = (), **dimensions: object |
There was a problem hiding this comment.
nit: the runner never passes sinks (it calls report_usage("diagrid", kind=..., ...)), so the fallback doesn't need the new parameter, the TYPE_CHECKING import of Sink or the Sequence import. The old **dimensions signature still matches every call site.
There was a problem hiding this comment.
I tried that, but mypy rejects it: runner.py:30: error: All conditional function variants must have identical signatures [misc]. The real report_usage now takes the sinks keyword, so the fallback has to match it even though the runner never passes it. I've left it as it is.
…eports Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What and why
This adds Reo as a second usage-analytics destination next to Scarf. Agent runs and
diagridpyinvocations can then be attributed to accounts in Reo. Tracked in DEV-783.diagrid/core/analytics.pyalready sends one anonymous event per package per process to Scarf. This PR adds a second destination to that reporter. It does not add a new tracker, and it adds no dependency.reo-censuswas considered and rejected: it would add a fourth runtime dependency, and it can't see the gate described below.What changes
analytics.pysends through a destination list. Each destination has its own endpoint, gate and request builder, and its own once-per-process dedupe.User-Agent.USAGE_ENDPOINTalready worked this way, andREO_ENDPOINTnow does too.Reo gets an unauthenticated GET. No API key and no auth header:
osbecomesplatformandpython_versionbecomespython.targetandciare not sent to Reo. The gate already filters on both, so their values would always be the same.The Reo gate is stricter than Scarf's, and it fails closed. Reo is skipped when any of these hold:
DO_NOT_TRACK,SCARF_NO_ANALYTICS,DIAGRID_NO_ANALYTICS)KUBERNETES_SERVICE_HOSTis setScarf's gate is still opt-out only. The two services will report different totals, and the README explains why.
diagridpynow reports to Reo only, once per invocation. That includes--helpand--version._DIAGRIDPY_COMPLETE) are not reported. Otherwise every Tab press and every shell start would wait on the network.diagrid-cliallowsdiagrid-core>=0.1.0, andanalyticsonly exists from 0.5.1. The import is guarded the same wayrunner.pyguards it, so an older core turns reporting off instead of crashing the CLI.The README "Usage analytics" section is rewritten. It covers:
diagridpyreportsHow it was tested
uv run pytest tests -m "not integration": 1057 passed, 4 skipped. The analytics and CLI tests also pass underCI=true. Every test that expects Reo to send first clears the CI variables, so none of them passes vacuously on GitHub Actions.No test can reach a real host. The root
conftest.pyblanks both endpoints. The Reo tests use request recorders,example.invalidor 127.0.0.1 listeners.Opt-outs, against a local listener:
DO_NOT_TRACK=1SCARF_NO_ANALYTICS=1DIAGRID_NO_ANALYTICS=1Cost of
diagridpy --help:DO_NOT_TRACK=1Worth a look in review
complete_var, or_{PROG}_COMPLETEfrom the program name). An unrelated tool's exported_*_COMPLETEvariable therefore doesn't switch reporting off.Before release (owner checks, not code)
pypi_downloadevent shows up in the Reo dashboard. A 200 from the endpoint proves nothing. Nonuget_runtimetest event has shown up yet either, and that's being followed up with Reo.core_versiononpypi_downloadin Reo, or Reo will drop it.arch,kind,frameworkandframework_versionare already registered.Checklist
uv run ruff format(no path arguments, soexamples/is covered too)uv run flake8 diagrid tests --ignore=E501,F401,W503,E203,E704uv run mypy --config-file mypy.iniuv run pytest tests -m "not integration"diagrid/carry the license header (no new files)git commit -s)🤖 Generated with Claude Code