Repository navigation
AI Request Logs: Show usage by plugin, theme, or core source - #1418
HILAYTRIVEDI wants to merge 12 commits into
Conversation
Store the detected request source in an indexed `source` column and add a `by_source` breakdown (requests, tokens, failed requests) to the logs summary, shown as a "Usage by source" table on Tools → AI Request Logs. - Move source detection into Request_Source_Detector and use it for rows logged from generation events as well as the HTTP transporter. - Record schema v2 only once the column exists; keep logging without it if the upgrade fails, and add the column and index in one ALTER. - Shorten overlong source keys on a UTF-8 boundary with a hash suffix and use a binary collation so distinct sources are never merged. - Cache source counts only and resolve translated names per request. See WordPress#348.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1418 +/- ##
=============================================
+ Coverage 85.62% 85.96% +0.33%
- Complexity 5155 5217 +62
=============================================
Files 194 195 +1
Lines 18637 18784 +147
=============================================
+ Hits 15958 16147 +189
+ Misses 2679 2637 -42
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Add Request_Source_DetectorTest so the detector is covered under strict coverage, and cover the remaining source breakdown branches in AI_Request_Log_Repository and AI_Request_Log_Schema. See WordPress#348.
|
Thanks,@jeffpaul. Usage by source now starts collapsed so the main request log stays higher on the page. Clicking a source name or its request count shows that source’s requests for the selected period. Clicking the failed count shows only unsuccessful requests from that source, including timeouts. The active filter is visible above the table and can be cleared there. |
…elop # Conflicts: # includes/Logging/Logging_Http_Transporter.php
What?
See #348
Adds a Usage by source breakdown to Tools → AI Request Logs, showing requests, tokens and failed requests per plugin, theme or WordPress core.
Why?
#348 calls for usage metering with per-plugin tracking. The request logger already detects which plugin or theme made each request, but the result was not stored in a queryable way, so admins could not see which extension was responsible for their AI usage.
How?
Logging_Http_Transporterinto a newRequest_Source_Detectorclass, used both by the HTTP transporter and by rows logged from generation events (Logging_Event_Listener).sourcecolumn to the logs table (schema v2). The column and index are added in a singleALTER. Schema v2 is recorded only once the column exists; if the upgrade fails, logging continues without the column.AI_Request_Log_Repositoryreturns aby_sourcebreakdown in the logs summary. Only the raw counts are cached; translated source names are resolved per request.SourceUsageReact component renders the breakdown as a table on the logs page.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Help with implementation, tests and the PR description; all changes were reviewed, tested and edited by me.
Testing Instructions
sourcecolumn with an index) and logging keeps working.Automated tests:
npm run test:e2e -- tests/e2e/specs/experiments/ai-request-logging.spec.jsnpm run test:php -- --filter 'AI_Request_Log|Logging_'Screenshots or screencast
Changelog Entry