Issue #3610924: Record the calling feature for each AI call

What this does

  • Adds a caller column to ai_metering_usage and ai_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 own aim_context:* / aim_feature:* markers, and smart_route:* / route_* routing metadata from ai_provider_universal.
  • The quota fallback reroute now forwards the original call tags, so caller attribution and aim_context grouping 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

  1. On a multilingual site with ai_translate enabled, translate a piece of content. The log at /admin/reports/ai-metering/log shows a translate_text row with caller ai_translate. This works on both the direct cloud path and the quota fallback path.
  2. Tag any AI call with aim_feature:my_feature. The row shows my_feature as caller.
  3. Untagged calls display in the column and can be selected with the (none) filter option.
  4. Run drush updb on 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

Merge request reports

Loading