Repository navigation
feat(Telemetry): Emit CLI usage events from an API middleware - #9010
Conversation
Cover the cli.request.made event emitted for authenticated Flagsmith CLI requests: the user-agent pattern, status, organisation resolution for users and master API keys, and that the key paths read no database.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Log unresolved organisations as None at WARNING, as the MCP middleware does, cover SDK requests carrying a CLI user-agent, and drop the query-count tests now that organisation resolution follows MCP.
Rename MCPUsageLoggerMiddleware to ClientUsageLoggerMiddleware and have it also emit cli.request.made for authenticated requests whose user-agent is the Flagsmith CLI's. Both events share authentication, status and organisation resolution, so they keep a single, last slot in MIDDLEWARE. Emit both events from literal log calls so the events catalogue picks them up, which also documents the status attribute of mcp.tool.called.
Docker builds report
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9010 +/- ##
=======================================
Coverage 98.92% 98.92%
=======================================
Files 1713 1713
Lines 72482 72566 +84
=======================================
+ Hits 71705 71789 +84
Misses 777 777 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
All reported issues were addressed across 4 files
Reply with feedback, questions, or to request a fix.
Turn on auto-fix | Re-trigger cubic
✅ private-cloud · depot-ubuntu-latest-arm-16 — run #23434 (attempt 1)Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
🗂️ Previous results✅ private-cloud · depot-ubuntu-latest-16 — run #23434 (attempt 1)Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
✅ oss · depot-ubuntu-latest-16 — run #23434 (attempt 1)Playwright Test Results (oss - depot-ubuntu-latest-16)Details
✅ oss · depot-ubuntu-latest-arm-16 — run #23434 (attempt 1)Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
|
Visual Regression25 screenshots compared. See report for details. |
emyller
left a comment
There was a problem hiding this comment.
LGTM
I'd be curious to track how many warnings we get on SaaS, and revisit the MultipleObjectsReturned case for multi-org users if necessary. I think it's not.
docs/if required so people know about the feature.Changes
Closes #8319
In this PR, we adapt the existing
MCPUsageLoggerMiddlewareto also log CLI usage, and rename it accordingly.The middleware now works out which client sent the request (MCP baggage first, then the CLI user-agent) before it reads
request.user.cli.request.made:cli.version,cli.os,cli.arch, andcli.versioncome from the user-agent.amplitude.user_idisstr(request.user.uuid). It is absent for master API keys.statusiserrorfor any response with a status code of 400 or above,successotherwise. The event is emitted after the response is obtained, so a 500 is recorded too.organisation.idis resolved as for MCP.Nothing is logged for unauthenticated requests, SDK requests, or other user-agents.
How did you test this code?
Added new unit tests.