Add AiTracking for Duo Chat REST API path

What does this MR do and why?

Adds track_internal_event('request_duo_chat_response', ...) to Gitlab::Duo::Chat::Completions#execute so IDE-originated Duo Chat via POST /api/v4/chat/completions lands in ai_usage_events.

The Web UI path (Llm::ChatService#perform) already fires this event, and Gitlab::Tracking::AiTracking is now wired automatically as a default tracker via ee/lib/ee/gitlab/tracking/event_definition.rb, so no event YAML change is needed. The IDE REST endpoint calls Completions#execute directly rather than through ChatService, so it was the one path still missing the tracking call.

This closes the IDE Duo Chat row of the audit at #567159. Without it, IDE Chat is invisible to AiUsageData, AiUserMetrics, and the Duo and SDLC Trends dashboard.

Tracks #567159.

How to set up and validate locally

  1. Stand up a self-managed GitLab instance with ClickHouse configured.
  2. Run the new spec:
    bundle exec rspec ee/spec/lib/gitlab/duo/chat/completions_spec.rb -e "#execute attribution"
  3. To verify end-to-end: invoke Gitlab::Duo::Chat::Completions.new(user, organization: org).execute(safe_params: { content: 'hi' }) in a rails console. After the write buffer flushes, Ai::UsageEvent.where(event: :request_duo_chat_response).count increases by 1, attributed to the invoking user.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Andrew Dunn

Merge request reports

Loading