Skip to content

Commit a569698

Browse files
authored
[Discover][Logs] Unify value treatment for log.level and error.log.level (elastic#245891)
## Summary Closes elastic#245348. With the introduction of improvements to the log overview for errors/exceptions ([PR](elastic#241342)), we added `error.log.level` information to be shown as a badge, in the same way we do for `log.level`. <img width="1668" height="969" alt="Screenshot 2025-12-10 at 17 50 58" src="https://github.com/user-attachments/assets/938789b4-9b64-494e-bb27-68a7c55d6afd" /> We recently noticed that `error.log.level` was showing the value with the plain highlight tags. <img width="1427" height="566" alt="522848417-3f9d9b1f-2ac4-4dad-b32c-9e8437a8cd68" src="https://github.com/user-attachments/assets/de4cf722-bd92-4d91-bb87-257c8134db3c" /> The issue was that `log.level` was using in `getLogDocumentOverview` its raw value, ignoring the formatted information that ES provides, which includes highlighting when a filter matches. The logical change here is to make the badge behave consistently for all "log level" data types. If `log.level` didn’t originally have highlighting, then other values displayed with the same UI and the same user-facing value shouldn’t have it either. So, the change is straightforward: treat `error.log.level` in the same way as `log.level`. |Before|After| |-|-| |<img width="1627" height="969" alt="Screenshot 2025-12-10 at 18 16 01" src="https://github.com/user-attachments/assets/98fa7337-e4ef-4da2-8444-9bf96890e5ff" />|<img width="1627" height="969" alt="Screenshot 2025-12-10 at 18 13 40" src="https://github.com/user-attachments/assets/59255df5-de05-40ff-a952-a61be5eb1129" />| ## Out of scope of the related issue, but worth fixing While taking screenshots, I noticed that documents can contain `timestamp` in an array, not just as a plain string. This caused the “current document” annotation not to appear in the Similar Errors chart ([PR](elastic#244665)), so I included a quick fix for that in this PR. <img width="867" height="216" alt="Screenshot 2025-12-04 at 11 47 47" src="https://github.com/user-attachments/assets/44e2bcb8-a5f3-4ded-b7a8-57f6988fb37e" /> ## Future considerations (not to be tackled in this PR, but cc @roshan) - Why is `log.level` ignoring the highlight tags? Should we consider highlighting it? - Worth noting that highlighting is only available in Classic mode at the moment. - `log.level` has its own cell renderer in the Discover results, showing the badge. Should we do the same for `error.log.level`?
1 parent 7c01ff3 commit a569698

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed

src/platform/packages/shared/kbn-discover-utils/src/utils/get_log_document_overview.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ export function getLogDocumentOverview(
6060
const agentName = formatField(fieldConstants.AGENT_NAME_FIELD);
6161

6262
// apm log fields
63-
const errorLogLevel = formatField(fieldConstants.ERROR_LOG_LEVEL_FIELD);
63+
const errorLogLevelArray = doc.flattened[fieldConstants.ERROR_LOG_LEVEL_FIELD];
64+
const errorLogLevel =
65+
Array.isArray(errorLogLevelArray) && errorLogLevelArray.length > 0
66+
? errorLogLevelArray[0]
67+
: errorLogLevelArray;
6468
const errorExceptionMessage = formatField(fieldConstants.ERROR_EXCEPTION_MESSAGE);
6569
const processorEvent = formatField(fieldConstants.PROCESSOR_EVENT_FIELD);
6670

src/platform/plugins/shared/unified_doc_viewer/public/components/doc_viewer_logs_overview/sub_components/similar_errors/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ export function SimilarErrors({ hit }: SimilarErrorsProps) {
7171
hitFlattened,
7272
fieldConstants.TIMESTAMP_FIELD
7373
);
74+
const normalizedTimestamp = Array.isArray(timestampValue)
75+
? String(timestampValue[0])
76+
: String(timestampValue);
7477

7578
const sectionDescription = useMemo(
7679
() =>
@@ -147,7 +150,7 @@ export function SimilarErrors({ hit }: SimilarErrorsProps) {
147150
>
148151
<SimilarErrorsOccurrencesChart
149152
baseEsqlQuery={esqlQuery}
150-
currentDocumentTimestamp={typeof timestampValue === 'string' ? timestampValue : undefined}
153+
currentDocumentTimestamp={normalizedTimestamp}
151154
/>
152155
</ContentFrameworkSection>
153156
);

src/platform/plugins/shared/unified_doc_viewer/public/components/doc_viewer_logs_overview/sub_components/similar_errors/similar_errors.test.tsx

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ jest.mock('../../../content_framework/lazy_content_framework_section', () => ({
3838
}));
3939

4040
jest.mock('./similar_errors_occurrences_chart', () => ({
41-
SimilarErrorsOccurrencesChart: ({ baseEsqlQuery }: any) => (
42-
<div data-test-subj="SimilarErrorsOccurrencesChart" />
41+
SimilarErrorsOccurrencesChart: ({ baseEsqlQuery, currentDocumentTimestamp }: any) => (
42+
<div
43+
data-test-subj="SimilarErrorsOccurrencesChart"
44+
data-current-document-timestamp={currentDocumentTimestamp}
45+
/>
4346
),
4447
}));
4548

@@ -140,15 +143,47 @@ describe('SimilarErrors', () => {
140143
});
141144
});
142145

143-
it('renders chart', () => {
144-
const hit = buildHit({
145-
[fieldConstants.SERVICE_NAME_FIELD]: 'test-service',
146-
[fieldConstants.ERROR_CULPRIT_FIELD]: 'test-culprit',
147-
message: 'test error message',
146+
describe('Chart rendering', () => {
147+
it('renders chart', () => {
148+
const hit = buildHit({
149+
[fieldConstants.SERVICE_NAME_FIELD]: 'test-service',
150+
[fieldConstants.ERROR_CULPRIT_FIELD]: 'test-culprit',
151+
message: 'test error message',
152+
});
153+
154+
renderSimilarErrors(hit);
155+
156+
expect(screen.getByTestId('SimilarErrorsOccurrencesChart')).toBeInTheDocument();
148157
});
149158

150-
renderSimilarErrors(hit);
159+
it('passes currentDocumentTimestamp to chart when timestamp is available', () => {
160+
const timestamp = '2024-12-10T10:30:00.000Z';
161+
const hit = buildHit({
162+
[fieldConstants.SERVICE_NAME_FIELD]: 'test-service',
163+
[fieldConstants.ERROR_CULPRIT_FIELD]: 'test-culprit',
164+
message: 'test error message',
165+
'@timestamp': timestamp,
166+
});
151167

152-
expect(screen.getByTestId('SimilarErrorsOccurrencesChart')).toBeInTheDocument();
168+
renderSimilarErrors(hit);
169+
170+
const chart = screen.getByTestId('SimilarErrorsOccurrencesChart');
171+
expect(chart).toHaveAttribute('data-current-document-timestamp', timestamp);
172+
});
173+
174+
it('handles array timestamp values correctly', () => {
175+
const timestampArray = ['2024-12-10T10:30:00.000Z'];
176+
const hit = buildHit({
177+
[fieldConstants.SERVICE_NAME_FIELD]: 'test-service',
178+
[fieldConstants.ERROR_CULPRIT_FIELD]: 'test-culprit',
179+
message: 'test error message',
180+
'@timestamp': timestampArray,
181+
});
182+
183+
renderSimilarErrors(hit);
184+
185+
const chart = screen.getByTestId('SimilarErrorsOccurrencesChart');
186+
expect(chart).toHaveAttribute('data-current-document-timestamp', timestampArray[0]);
187+
});
153188
});
154189
});

0 commit comments

Comments
 (0)