Issue #3610924: Record the calling feature for each AI call
What this does
- Adds a
callercolumn toai_metering_usageandai_metering_rollup(update hook 9022), recording which feature or module triggered each AI call. - Attribution is passive and comes straight from the call tags. An explicit
aim_feature:<name>tag wins. Otherwise the first real tag on the call is surfaced as-is, so a module that already tags its calls (ai_translate does) shows up without any mapping on our side. Only pipeline metadata is skipped: the operation-type tag ProviderProxy always prepends, our ownaim_context:*/aim_feature:*markers, andsmart_route:*/route_*routing metadata from ai_provider_universal. - The quota fallback reroute now forwards the original call tags, so caller attribution and
aim_contextgrouping survive a reroute to the local provider. The degraded translate-via-chat path records its caller too. - AI Usage Log page (
/admin/reports/ai-metering/log): new Caller column (after Operation) and an exposed multi-select filter with a(none)option for unattributed calls. The JSON and CSV exports at/admin/reports/ai-metering/log/export/*include the caller, and monthly rollups group by it.
How to test
- On a multilingual site with ai_translate enabled, translate a piece of content. The log at
/admin/reports/ai-metering/logshows atranslate_textrow with callerai_translate. This works on both the direct cloud path and the quota fallback path. - Tag any AI call with
aim_feature:my_feature. The row showsmy_featureas caller. - Untagged calls display
—in the column and can be selected with the(none)filter option. - Run
drush updbon an existing install: update 9022 adds the column to both tables and rebuilds the rollup unique key.
AI assistance
Yes.
Edited by Jérôme Tchania