diff --git a/ee/config/events/include_repository_xray_data_into_code_generation_prompt.yml b/ee/config/events/include_repository_xray_data_into_code_generation_prompt.yml
new file mode 100644
index 0000000000000000000000000000000000000000..a1573ab7a9af424bb8a991e81a584861025a126e
--- /dev/null
+++ b/ee/config/events/include_repository_xray_data_into_code_generation_prompt.yml
@@ -0,0 +1,18 @@
+---
+description: Repository X-Ray data being included into code generation prompt
+category: InternalEventTracking
+action: include_repository_xray_data_into_code_generation_prompt
+identifiers:
+- project
+- namespace
+- user
+product_section: dev
+product_stage: create
+product_group: code_creation
+milestone: '16.9'
+introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/142807
+distributions:
+- ee
+tiers:
+- premium
+- ultimate
diff --git a/ee/config/metrics/counts_28d/count_distinct_project_id_from_include_repository_xray_data_into_code_generation_prompt_monthly.yml b/ee/config/metrics/counts_28d/count_distinct_project_id_from_include_repository_xray_data_into_code_generation_prompt_monthly.yml
new file mode 100644
index 0000000000000000000000000000000000000000..83cfb80208a75b95869b3d1d95422316da5ea297
--- /dev/null
+++ b/ee/config/metrics/counts_28d/count_distinct_project_id_from_include_repository_xray_data_into_code_generation_prompt_monthly.yml
@@ -0,0 +1,25 @@
+---
+key_path: redis_hll_counters.count_distinct_project_id_from_include_repository_xray_data_into_code_generation_prompt_monthly
+description: Monthly count of unique projects that have repository x-ray data included into code generation AI prompt
+product_section: dev
+product_stage: create
+product_group: code_creation
+performance_indicator_type: []
+value_type: number
+status: active
+milestone: '16.9'
+introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/142807
+time_frame: 28d
+data_source: internal_events
+data_category: optional
+distribution:
+- ee
+tier:
+- premium
+- ultimate
+options:
+  events:
+  - include_repository_xray_data_into_code_generation_prompt
+events:
+- name: include_repository_xray_data_into_code_generation_prompt
+  unique: project.id
diff --git a/ee/config/metrics/counts_28d/count_total_include_repository_xray_data_into_code_generation_prompt_monthly.yml b/ee/config/metrics/counts_28d/count_total_include_repository_xray_data_into_code_generation_prompt_monthly.yml
new file mode 100644
index 0000000000000000000000000000000000000000..159ab69646e7bc75a13f8af3e2f7258f5d99d610
--- /dev/null
+++ b/ee/config/metrics/counts_28d/count_total_include_repository_xray_data_into_code_generation_prompt_monthly.yml
@@ -0,0 +1,24 @@
+---
+key_path: counts.count_total_include_repository_xray_data_into_code_generation_prompt_monthly
+description: Monthly count of repository x-ray data being added into code generation AI prompt
+product_section: dev
+product_stage: create
+product_group: code_creation
+performance_indicator_type: []
+value_type: number
+status: active
+milestone: '16.9'
+introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/142807
+time_frame: 28d
+data_source: internal_events
+data_category: optional
+distribution:
+- ee
+tier:
+- premium
+- ultimate
+options:
+  events:
+  - include_repository_xray_data_into_code_generation_prompt
+events:
+- name: include_repository_xray_data_into_code_generation_prompt
diff --git a/ee/config/metrics/counts_7d/count_distinct_project_id_from_include_repository_xray_data_into_code_generation_prompt_weekly.yml b/ee/config/metrics/counts_7d/count_distinct_project_id_from_include_repository_xray_data_into_code_generation_prompt_weekly.yml
new file mode 100644
index 0000000000000000000000000000000000000000..4def151073a02c1fe7e27221a1a79cbe92e04b7a
--- /dev/null
+++ b/ee/config/metrics/counts_7d/count_distinct_project_id_from_include_repository_xray_data_into_code_generation_prompt_weekly.yml
@@ -0,0 +1,25 @@
+---
+key_path: redis_hll_counters.count_distinct_project_id_from_include_repository_xray_data_into_code_generation_prompt_weekly
+description: Weekly count of unique projects that have repository x-ray data included into code generation AI prompt
+product_section: dev
+product_stage: create
+product_group: code_creation
+performance_indicator_type: []
+value_type: number
+status: active
+milestone: '16.9'
+introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/142807
+time_frame: 7d
+data_source: internal_events
+data_category: optional
+distribution:
+- ee
+tier:
+- premium
+- ultimate
+options:
+  events:
+  - include_repository_xray_data_into_code_generation_prompt
+events:
+- name: include_repository_xray_data_into_code_generation_prompt
+  unique: project.id
diff --git a/ee/config/metrics/counts_7d/count_total_include_repository_xray_data_into_code_generation_prompt_weekly.yml b/ee/config/metrics/counts_7d/count_total_include_repository_xray_data_into_code_generation_prompt_weekly.yml
new file mode 100644
index 0000000000000000000000000000000000000000..a9a1cb397672b909319dd57ae957090e5faa1d2c
--- /dev/null
+++ b/ee/config/metrics/counts_7d/count_total_include_repository_xray_data_into_code_generation_prompt_weekly.yml
@@ -0,0 +1,24 @@
+---
+key_path: counts.count_total_include_repository_xray_data_into_code_generation_prompt_weekly
+description: Weekly count of repository x-ray data being added into code generation AI prompt
+product_section: dev
+product_stage: create
+product_group: code_creation
+performance_indicator_type: []
+value_type: number
+status: active
+milestone: '16.9'
+introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/142807
+time_frame: 7d
+data_source: internal_events
+data_category: optional
+distribution:
+- ee
+tier:
+- premium
+- ultimate
+options:
+  events:
+  - include_repository_xray_data_into_code_generation_prompt
+events:
+- name: include_repository_xray_data_into_code_generation_prompt
diff --git a/ee/lib/code_suggestions/prompts/code_generation/anthropic.rb b/ee/lib/code_suggestions/prompts/code_generation/anthropic.rb
index 62fc770635424e6375804d3f29d3602223157a5a..1c6fed3be18b19b602df09986bfe08e0cb03faa3 100644
--- a/ee/lib/code_suggestions/prompts/code_generation/anthropic.rb
+++ b/ee/lib/code_suggestions/prompts/code_generation/anthropic.rb
@@ -86,6 +86,13 @@ def libraries_block
             "#{lib['name']}: #{lib['description']}"
           end
 
+          Gitlab::InternalEvents.track_event(
+            'include_repository_xray_data_into_code_generation_prompt',
+            project: params[:project],
+            namespace: params[:project]&.namespace,
+            user: params[:current_user]
+          )
+
           <<~LIBS
           <libs>
           #{libs.join("\n")}
diff --git a/ee/lib/code_suggestions/task_factory.rb b/ee/lib/code_suggestions/task_factory.rb
index f760c24e6e65c0341d12bd72f64c0538f55b0d7e..202ac8bfb5a3e157a7f0412347a5129f80f65711 100644
--- a/ee/lib/code_suggestions/task_factory.rb
+++ b/ee/lib/code_suggestions/task_factory.rb
@@ -50,7 +50,8 @@ def code_generation_params(instructions)
         prefix: instructions[:prefix],
         instruction: instructions[:instruction],
         project: project,
-        model_name: Feature.enabled?(:code_suggestions_claude21, current_user) ? ANTHROPIC_MODEL : nil
+        model_name: Feature.enabled?(:code_suggestions_claude21, current_user) ? ANTHROPIC_MODEL : nil,
+        current_user: current_user
       )
     end
 
diff --git a/ee/spec/lib/code_suggestions/prompts/code_generation/anthropic_spec.rb b/ee/spec/lib/code_suggestions/prompts/code_generation/anthropic_spec.rb
index 130dc428941dc0d4647a02266dcdd755faece032..4d3b06b48d24b0acb29e2fa80da8818a03a9294a 100644
--- a/ee/spec/lib/code_suggestions/prompts/code_generation/anthropic_spec.rb
+++ b/ee/spec/lib/code_suggestions/prompts/code_generation/anthropic_spec.rb
@@ -190,6 +190,8 @@
       end
 
       context 'with XRay data available' do
+        let_it_be(:current_user) { create(:user) }
+
         let(:xray) { create(:xray_report, payload: payload) }
         let(:payload) do
           {
@@ -209,6 +211,7 @@
         let(:params) do
           {
             project: xray.project,
+            current_user: current_user,
             prefix: prefix,
             instruction: instruction,
             current_file: unsafe_params['current_file'].with_indifferent_access
@@ -283,6 +286,17 @@
           allow(::Projects::XrayReport).to receive(:for_lang).and_return([xray])
         end
 
+        describe 'internal events tracking' do
+          subject { described_class.new(params).request_params }
+
+          it_behaves_like 'internal event tracking' do
+            let(:event) { 'include_repository_xray_data_into_code_generation_prompt' }
+            let(:project) { xray.project }
+            let(:namespace) { project.namespace }
+            let(:user) { current_user }
+          end
+        end
+
         it 'fetches xray data' do
           subject.request_params
 
diff --git a/ee/spec/lib/code_suggestions/task_factory_spec.rb b/ee/spec/lib/code_suggestions/task_factory_spec.rb
index d9dc844e61bd28b1a9be201570fa52ced0638589..95071ba2260bb92823e737ab733219d51b023193 100644
--- a/ee/spec/lib/code_suggestions/task_factory_spec.rb
+++ b/ee/spec/lib/code_suggestions/task_factory_spec.rb
@@ -22,6 +22,14 @@
 
     subject(:get_task) { described_class.new(current_user, params: params).task }
 
+    shared_examples 'correct task initializer' do
+      it 'creates task with correct params' do
+        expect(expected_class).to receive(:new).with(**expected_params)
+
+        get_task
+      end
+    end
+
     it 'calls instructions extractor with expected params' do
       expect(CodeSuggestions::InstructionsExtractor)
         .to receive(:new)
@@ -31,18 +39,36 @@
       get_task
     end
 
+    context 'when code completion' do
+      let(:expected_class) { ::CodeSuggestions::Tasks::CodeCompletion }
+      let(:expected_project) { nil }
+      let(:expected_params) do
+        {
+          params: params,
+          unsafe_passthrough_params: {}
+        }
+      end
+
+      before do
+        allow_next_instance_of(CodeSuggestions::InstructionsExtractor) do |instance|
+          allow(instance).to receive(:extract).and_return({})
+        end
+      end
+
+      it_behaves_like 'correct task initializer'
+    end
+
     context 'when code generation' do
       let(:expected_class) { ::CodeSuggestions::Tasks::CodeGeneration }
-      let(:expected_family) { described_class::VERTEX_AI }
       let(:expected_project) { nil }
       let(:expected_params) do
         {
           params: params.merge(
-            code_generation_model_family: expected_family,
             instruction: 'instruction',
             prefix: 'trimmed prefix',
             project: expected_project,
-            model_name: described_class::ANTHROPIC_MODEL
+            model_name: described_class::ANTHROPIC_MODEL,
+            current_user: current_user
           ),
           unsafe_passthrough_params: {}
         }
@@ -56,6 +82,8 @@
         end
       end
 
+      it_behaves_like 'correct task initializer'
+
       context 'with project' do
         let_it_be(:expected_project) { create(:project) }
         let(:params) do