Files
sure/lib/job_usage_tracking.rb
f4613626fa Update demo assistant banner to credit Vercel AI Gateway (#4295)
* Update demo assistant banner to credit Vercel AI Gateway

* Revise English demo assistant disclosure copy

* Track daily assistant and Sidekiq installation activity

* Unify daily usage event capture

Share daily usage capture across web, assistant, and Sidekiq hooks while preserving user-local and installation-UTC counting. Keep all event names in one allowlist and update regression coverage.

Validation: 11 collector and middleware tests pass in a database-free harness; Ruby lint and Brakeman pass. The full Rails suite cannot start because local PostgreSQL is unavailable.

* Skip web usage context when capture is disabled

Check shared daily-usage eligibility before resolving family timezone and visitor IP. This avoids duplicate invalid-timezone warnings when analytics is disabled or Rails uses a null cache, while keeping installation events independent of the Rails cache.

Add regression coverage for disabled collection and null-cache eligibility. The database-free unit and request-guard checks and Ruby lint pass; local full Rails tests are blocked by unavailable PostgreSQL.

* Align demo banner translations with the English disclosure

* Track daily MCP tool execution activity

Capture mcp_call_served_daily through DailyUsage before an authenticated, permitted MCP tool executes. Reuse installation-scoped UTC claims and the shared feedback project without sending tool names, arguments, results, or user metadata.

Cover OAuth and environment-token calls, tool errors, excluded requests, daily identity and Redis claim independence. Offline collector/dispatch tests, Ruby lint and Brakeman pass; local full Rails tests cannot connect to PostgreSQL.

* Rename daily usage collector to Usage

Keep existing daily event semantics while allowing the collector name to accommodate future time horizons. Update runtime call sites, test filenames, and documented references.

* Generalize usage tracking class names

* Remove extra whitespace

---------

Co-authored-by: SureBot <sure-bot@we-promise.com>
Co-authored-by: Local Review <local-review@example.invalid>
Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
Co-authored-by: Juan José Mata <jjmata@jjmata.com>
2026-10-29 22:20:01 -07:00

8 lines
194 B
Ruby

# Server middleware counts execution attempts, including retries and failures.
class JobUsageTracking
def call(_worker, _job, _queue)
Usage.capture("job_served_daily")
yield
end
end