diff --git a/src/platform/plugins/shared/unified_doc_viewer/public/components/observability/traces/components/full_screen_waterfall/helpers/is_span.ts b/src/platform/plugins/shared/unified_doc_viewer/public/components/observability/traces/components/full_screen_waterfall/helpers/is_span.ts new file mode 100644 index 0000000000000..919318969597f --- /dev/null +++ b/src/platform/plugins/shared/unified_doc_viewer/public/components/observability/traces/components/full_screen_waterfall/helpers/is_span.ts @@ -0,0 +1,14 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +import { DataTableRecord, PARENT_ID_FIELD, TRANSACTION_NAME_FIELD } from '@kbn/discover-utils'; + +export const isSpanHit = (hit: DataTableRecord | null): boolean => { + return !!hit?.flattened[PARENT_ID_FIELD] && !hit?.flattened[TRANSACTION_NAME_FIELD]; +}; diff --git a/src/platform/plugins/shared/unified_doc_viewer/public/components/observability/traces/components/full_screen_waterfall/hooks/use_span/index.ts b/src/platform/plugins/shared/unified_doc_viewer/public/components/observability/traces/components/full_screen_waterfall/hooks/use_span/index.ts index 80ed521328da0..29917da6ed6d9 100644 --- a/src/platform/plugins/shared/unified_doc_viewer/public/components/observability/traces/components/full_screen_waterfall/hooks/use_span/index.ts +++ b/src/platform/plugins/shared/unified_doc_viewer/public/components/observability/traces/components/full_screen_waterfall/hooks/use_span/index.ts @@ -35,6 +35,12 @@ async function getSpanData({ spanId, indexPattern, data, signal }: GetTransactio size: 1, body: { timeout: '20s', + fields: [ + { + field: '*', + include_unmapped: true, + }, + ], query: { match: { [SPAN_ID_FIELD]: spanId, @@ -68,7 +74,7 @@ export const useSpan = ({ spanId, indexPattern }: UseSpanParams) => { try { setLoading(true); const result = await getSpanData({ spanId, indexPattern, data, signal }); - setSpan(result.rawResponse.hits.hits[0]?._source); + setSpan(result.rawResponse.hits.hits[0]?.fields ?? null); setDocId(result.rawResponse.hits.hits[0]?._id ?? null); } catch (err) { if (!signal.aborted) { diff --git a/src/platform/plugins/shared/unified_doc_viewer/public/components/observability/traces/components/full_screen_waterfall/hooks/use_span/use_span.test.ts b/src/platform/plugins/shared/unified_doc_viewer/public/components/observability/traces/components/full_screen_waterfall/hooks/use_span/use_span.test.ts index ac2411289d408..4ba84eea342a4 100644 --- a/src/platform/plugins/shared/unified_doc_viewer/public/components/observability/traces/components/full_screen_waterfall/hooks/use_span/use_span.test.ts +++ b/src/platform/plugins/shared/unified_doc_viewer/public/components/observability/traces/components/full_screen_waterfall/hooks/use_span/use_span.test.ts @@ -45,7 +45,7 @@ describe('useSpan', () => { describe('when parameters are NOT missing', () => { it('should fetch span data successfully', async () => { - const mockHit = { _source: { name: 'test-span' }, _id: 'test-id' }; + const mockHit = { fields: { name: 'test-span' }, _id: 'test-id' }; mockSearch.mockReturnValue( of({ @@ -61,7 +61,7 @@ describe('useSpan', () => { await waitFor(() => !result.current.loading); expect(result.current.loading).toBe(false); - expect(result.current.span).toEqual(mockHit._source); + expect(result.current.span).toEqual(mockHit.fields); expect(result.current.docId).toEqual(mockHit._id); }); }); diff --git a/src/platform/plugins/shared/unified_doc_viewer/public/components/observability/traces/components/full_screen_waterfall/span_flyout/index.tsx b/src/platform/plugins/shared/unified_doc_viewer/public/components/observability/traces/components/full_screen_waterfall/span_flyout/index.tsx index 46496518cb930..e975c39966cd6 100644 --- a/src/platform/plugins/shared/unified_doc_viewer/public/components/observability/traces/components/full_screen_waterfall/span_flyout/index.tsx +++ b/src/platform/plugins/shared/unified_doc_viewer/public/components/observability/traces/components/full_screen_waterfall/span_flyout/index.tsx @@ -15,13 +15,14 @@ import { EuiFlyoutBody, EuiSkeletonTitle, } from '@elastic/eui'; -import { DataTableRecord, PARENT_ID_FIELD } from '@kbn/discover-utils'; +import { DataTableRecord } from '@kbn/discover-utils'; import { flattenObject } from '@kbn/object-utils'; import React, { useMemo } from 'react'; import { i18n } from '@kbn/i18n'; import { DocViewRenderProps } from '@kbn/unified-doc-viewer/types'; import { useSpan } from '../hooks/use_span'; import { SpanFlyoutBody } from './span_flyout_body'; +import { isSpanHit } from '../helpers/is_span'; const flyoutId = 'spanDetailFlyout'; @@ -53,7 +54,8 @@ export const SpanFlyout = ({ flattened: flattenObject(span), }; }, [docId, span]); - const isSpan = !!documentAsHit?.flattened[PARENT_ID_FIELD]; + + const isSpan = isSpanHit(documentAsHit); return ( { const [selectedTabId, setSelectedTabId] = useState(tabIds.OVERVIEW); - const isSpan = !!hit?.flattened[PARENT_ID_FIELD]; + const isSpan = isSpanHit(hit); const { indexes } = useDataSourcesContext(); const onSelectedTabChanged = (id: string) => setSelectedTabId(id);