Track Claude Code ingestion session drops as Internal Events

What does this MR do and why?

Tracks why Claude Code sessions get dropped during Claude Compliance API ingestion, so we can see how often sessions are lost and for which reason.

  • Ai::Compliance::Anthropic::UserResolver tracks an Internal Event (usage tracking event) each time it drops a session. There is one event per drop reason: no_gitlab_user, not_namespace_member, ambiguous_match, no_anthropic_email. Events are tracked with the top-level group as namespace.
  • Each event has an event definition (ee/config/events) and a total-count metric definition (ee/config/metrics/counts_all) with 7d, 28d and all-time time frames.
  • Ai::Compliance::Anthropic::SyncSessionsWorker wraps each page in Gitlab::InternalEvents.with_batched_redis_writes, so one page of up to 500 sessions does not make one Redis write per drop.

These need Analytics Instrumentation review.

Stacked on !261009 (merged), which adds the ingestion workers and the no_anthropic_email drop reason. Retarget to master after that one merges.

How to set up and validate locally

Run the specs:

bundle exec rspec ee/spec/lib/ai/compliance/anthropic/user_resolver_spec.rb ee/spec/workers/ai/compliance/anthropic/sync_sessions_worker_spec.rb spec/lib/gitlab/tracking/event_definition_spec.rb spec/lib/gitlab/internal_events/event_definitions_spec.rb spec/lib/gitlab/usage/metric_definition_validate_all_spec.rb

Optional manual check on GDK:

  1. Set up an enabled Ai::Compliance::Anthropic::Integration and the claude_code_compliance_api_ingestion flag as described in !261009 (merged).
  2. Make sure the Compliance API returns a Claude Code session whose email does not match a confirmed GitLab user.
  3. Run Ai::Compliance::Anthropic::ScheduleIngestionWorker.new.perform and let the jobs run.
  4. Check the event count: Gitlab::Usage::ServicePingReport.for(output: :all_metrics_values).dig('counts', 'count_total_drop_claude_code_session_no_gitlab_user').

References

Related to https://gitlab.com/gitlab-org/gitlab/-/work_items/623177

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist.

Merge request reports

Loading
Loading