From 046cfc854dfbcf946d775c8f204b0a2c74414cd6 Mon Sep 17 00:00:00 2001 From: Coen Warmer Date: Mon, 4 Sep 2023 15:49:48 +0200 Subject: [PATCH] [Observability AI Assistant] Return `errorDoc` instead of `error` in GetApmErrorDocument function (#165588) --- .../get_apm_error_document/index.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/apm/server/routes/assistant_functions/get_apm_error_document/index.ts b/x-pack/plugins/apm/server/routes/assistant_functions/get_apm_error_document/index.ts index c460acf4c3b3f..ffb1158270455 100644 --- a/x-pack/plugins/apm/server/routes/assistant_functions/get_apm_error_document/index.ts +++ b/x-pack/plugins/apm/server/routes/assistant_functions/get_apm_error_document/index.ts @@ -54,14 +54,14 @@ export async function getApmErrorDocument({ }, }); - const error = response.hits.hits[0]?._source as APMError; + const errorDoc = response.hits.hits[0]?._source as APMError; - if (!error) { + if (!errorDoc) { return undefined; } - return pick( - error, + const formattedResponse = pick( + errorDoc, 'message', 'error', '@timestamp', @@ -71,4 +71,11 @@ export async function getApmErrorDocument({ 'span.type', 'span.subtype' ); + + const { error, ...rest } = formattedResponse; + + return { + ...rest, + errorDoc: formattedResponse.error, + }; }