From a36fa1151b4af7ecd1565bf2b67fad20835b8209 Mon Sep 17 00:00:00 2001
From: Carlos Crespo <crespocarlos@users.noreply.github.com>
Date: Sat, 19 Oct 2024 01:16:36 +0200
Subject: [PATCH] [APM][Otel]Fix get_error_group_main_statistics making
 trace.id optional field (#196822)

fixes [196821](https://github.com/elastic/kibana/issues/196821)

## Summary

`trace.id` should've been sent as an optional field to the
`get_error_group_main_statistics` query. This PR fixes that

<img width="700" alt="image"
src="https://github.com/user-attachments/assets/20b63361-9645-418f-a611-2c0e29b385c7">


## How to test

- Run the opentelemetry demo:
https://github.com/elastic/opentelemetry-demo/tree/rca_ingress_obs
- Navigate to Application > Services
- Open the service details for loadgenerator
---
 .../get_error_groups/get_error_group_main_statistics.ts   | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/x-pack/plugins/observability_solution/apm/server/routes/errors/get_error_groups/get_error_group_main_statistics.ts b/x-pack/plugins/observability_solution/apm/server/routes/errors/get_error_groups/get_error_group_main_statistics.ts
index 3d6fa0f5a5ef6..8f201efbe6549 100644
--- a/x-pack/plugins/observability_solution/apm/server/routes/errors/get_error_groups/get_error_group_main_statistics.ts
+++ b/x-pack/plugins/observability_solution/apm/server/routes/errors/get_error_groups/get_error_group_main_statistics.ts
@@ -97,14 +97,10 @@ export async function getErrorGroupMainStatistics({
       ]
     : [];
 
-  const requiredFields = asMutableArray([
-    TRACE_ID,
-    AT_TIMESTAMP,
-    ERROR_GROUP_ID,
-    ERROR_ID,
-  ] as const);
+  const requiredFields = asMutableArray([AT_TIMESTAMP, ERROR_GROUP_ID, ERROR_ID] as const);
 
   const optionalFields = asMutableArray([
+    TRACE_ID,
     ERROR_CULPRIT,
     ERROR_LOG_MESSAGE,
     ERROR_EXC_MESSAGE,