Skip to content

Commit fce1bae

Browse files
authored
Show AI log assistant with fallback message fields (#243437)
The AI assistant on log messages was only showing if the field was `message` and not falling back if `exception.message` or oher fields are used. | before | after | | --- | --- | | <img width="1042" height="1710" alt="Image" src="https://github.com/user-attachments/assets/995891c2-d145-42ae-9f30-2e43585a47de" />| <img width="1066" height="1734" alt="CleanShot 2025-11-18 at 22 52 30@2x" src="https://github.com/user-attachments/assets/9fe8fc87-7704-4e8e-b35d-8e7e4fe72579" /> | Fixes #243436
1 parent 1211f0f commit fce1bae

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import type { Message } from '@kbn/observability-ai-assistant-plugin/common';
9+
import { observabilityAIAssistantPluginMock } from '@kbn/observability-ai-assistant-plugin/public/mock';
10+
import { render } from '@testing-library/react';
11+
import React from 'react';
12+
import { LogAIAssistant } from './log_ai_assistant';
13+
14+
const observabilityAIAssistant = observabilityAIAssistantPluginMock.createStartContract();
15+
jest
16+
.spyOn(observabilityAIAssistant, 'getContextualInsightMessages')
17+
.mockReturnValue([{ message: { content: 'hello' } } as Message]);
18+
19+
describe('LogAIAssistant', () => {
20+
describe('when a message field is present', () => {
21+
it('shows the assistant panel', () => {
22+
const doc = { fields: [{ field: 'message', value: ['hello'] }] };
23+
24+
const elements = render(
25+
<LogAIAssistant doc={doc} observabilityAIAssistant={observabilityAIAssistant} />
26+
);
27+
28+
expect(elements.container.getElementsByClassName('euiFlexGroup').length).toBe(1);
29+
});
30+
});
31+
32+
describe('when an alternate message field is present', () => {
33+
it('shows the assistant panel', () => {
34+
const doc = { fields: [{ field: 'exception.message', value: ['hello'] }] };
35+
36+
const elements = render(
37+
<LogAIAssistant doc={doc} observabilityAIAssistant={observabilityAIAssistant} />
38+
);
39+
40+
expect(elements.container.getElementsByClassName('euiFlexGroup').length).toBe(1);
41+
});
42+
});
43+
});

x-pack/platform/plugins/shared/logs_shared/public/components/log_ai_assistant/log_ai_assistant.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import React, { useMemo } from 'react';
99
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
10+
import { type LogDocumentOverview, getMessageFieldWithFallbacks } from '@kbn/discover-utils';
1011
import type {
1112
Message,
1213
ObservabilityAIAssistantPublicStart,
@@ -35,7 +36,7 @@ export const LogAIAssistant = ({
3536
return undefined;
3637
}
3738

38-
const message = doc.fields.find((field) => field.field === 'message')?.value[0];
39+
const message = getMessageFieldWithFallbacks(doc as unknown as LogDocumentOverview);
3940

4041
if (!message) {
4142
return undefined;

0 commit comments

Comments
 (0)