diff --git a/src/platform/packages/shared/kbn-discover-utils/src/field_constants.ts b/src/platform/packages/shared/kbn-discover-utils/src/field_constants.ts index 30693bef840ee..a1d6b5718f8ca 100644 --- a/src/platform/packages/shared/kbn-discover-utils/src/field_constants.ts +++ b/src/platform/packages/shared/kbn-discover-utils/src/field_constants.ts @@ -32,6 +32,7 @@ export const SPAN_TYPE_FIELD = 'span.type'; export const SPAN_SUBTYPE_FIELD = 'span.subtype'; export const SPAN_DESTINATION_SERVICE_RESOURCE_FIELD = 'span.destination.service.resource'; export const PROCESSOR_EVENT_FIELD = 'processor.event'; +export const OTEL_SPAN_KIND = 'kind'; export const LOG_FILE_PATH_FIELD = 'log.file.path'; export const DATASTREAM_NAMESPACE_FIELD = 'data_stream.namespace'; diff --git a/src/platform/plugins/shared/discover/public/context_awareness/profile_providers/observability/traces_document_profile/span_document_profile/profile.test.ts b/src/platform/plugins/shared/discover/public/context_awareness/profile_providers/observability/traces_document_profile/span_document_profile/profile.test.ts index 96a395f1918a0..a2b56be8b756c 100644 --- a/src/platform/plugins/shared/discover/public/context_awareness/profile_providers/observability/traces_document_profile/span_document_profile/profile.test.ts +++ b/src/platform/plugins/shared/discover/public/context_awareness/profile_providers/observability/traces_document_profile/span_document_profile/profile.test.ts @@ -76,6 +76,44 @@ describe('spanDocumentProfileProvider', () => { }) ).toEqual(RESOLUTION_MISMATCH); }); + + it('does not match records with the correct data stream type but the incorrect processor event', () => { + expect( + spanDocumentProfileProvider.resolve({ + rootContext: getRootContext({ profileId }), + dataSourceContext: DATA_SOURCE_CONTEXT, + record: buildMockRecord('index', { + 'data_stream.type': ['traces'], + 'processor.event': ['other'], + }), + }) + ).toEqual(RESOLUTION_MISMATCH); + }); + + it('matches records with the correct data stream type and any OTEL `kind` field', () => { + expect( + spanDocumentProfileProvider.resolve({ + rootContext: getRootContext({ profileId }), + dataSourceContext: DATA_SOURCE_CONTEXT, + record: buildMockRecord('index', { + 'data_stream.type': ['traces'], + kind: 'Internal', + }), + }) + ).toEqual(RESOLUTION_MATCH); + }); + + it('defaults to matching records with the correct data stream type but no processor event field', () => { + expect( + spanDocumentProfileProvider.resolve({ + rootContext: getRootContext({ profileId }), + dataSourceContext: DATA_SOURCE_CONTEXT, + record: buildMockRecord('index', { + 'data_stream.type': ['traces'], + }), + }) + ).toEqual(RESOLUTION_MATCH); + }); }); describe('when root profile is NOT observability', () => { diff --git a/src/platform/plugins/shared/discover/public/context_awareness/profile_providers/observability/traces_document_profile/span_document_profile/profile.ts b/src/platform/plugins/shared/discover/public/context_awareness/profile_providers/observability/traces_document_profile/span_document_profile/profile.ts index 57577c57603cf..275b362ac03c9 100644 --- a/src/platform/plugins/shared/discover/public/context_awareness/profile_providers/observability/traces_document_profile/span_document_profile/profile.ts +++ b/src/platform/plugins/shared/discover/public/context_awareness/profile_providers/observability/traces_document_profile/span_document_profile/profile.ts @@ -8,7 +8,12 @@ */ import type { DataTableRecord } from '@kbn/discover-utils'; -import { DATASTREAM_TYPE_FIELD, getFieldValue, PROCESSOR_EVENT_FIELD } from '@kbn/discover-utils'; +import { + DATASTREAM_TYPE_FIELD, + getFieldValue, + OTEL_SPAN_KIND, + PROCESSOR_EVENT_FIELD, +} from '@kbn/discover-utils'; import { TRACES_PRODUCT_FEATURE_ID } from '../../../../../../common/constants'; import type { DocumentProfileProvider } from '../../../../profiles'; import { DocumentType, SolutionType } from '../../../../profiles'; @@ -65,5 +70,10 @@ const getIsSpanRecord = ({ record }: { record: DataTableRecord }) => { const isSpanDocument = (record: DataTableRecord) => { const dataStreamType = getFieldValue(record, DATASTREAM_TYPE_FIELD); const processorEvent = getFieldValue(record, PROCESSOR_EVENT_FIELD); - return dataStreamType === 'traces' && processorEvent === 'span'; + const spanKind = getFieldValue(record, OTEL_SPAN_KIND); + + const isApmSpan = processorEvent === 'span'; + const isOtelSpan = spanKind != null || processorEvent == null; + + return dataStreamType === 'traces' && (isApmSpan || isOtelSpan); };