Skip to content

Commit c88328f

Browse files
authored
[Discover][APM] Detect OTEL spans for doc viewer (elastic#224439)
## Summary This PR modifies the Span doc viewer check to be better equipped for dealing with unprocessed OTEL trace spans. If there is no `processed.event` field, we can start assuming there'd be OTEL specific fields to check. Here, we check for `kind` which *should* be present, so any value determines this to be a trace span. In the absence of `kind` being present and no `processed.event` field (just a `data_stream.type` field, we can assume it is a span regardless. ## How to test * Add the following to your `kibana.dev.yml` file: ```yaml discover.experimental.enabledProfiles: - observability-traces-data-source-profile - observability-traces-transaction-document-profile - observability-traces-span-document-profile ``` * Set up a source of unprocessed OTEL data to feed into ES (Open telemetry demo, etc) * Set your space to Observability mode, and go to Discover. * Query for `traces-*` and open any record for the document viewer * The Span Overview tab should be visible.
1 parent b991e82 commit c88328f

3 files changed

Lines changed: 51 additions & 2 deletions

File tree

  • src/platform

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const SPAN_TYPE_FIELD = 'span.type';
3232
export const SPAN_SUBTYPE_FIELD = 'span.subtype';
3333
export const SPAN_DESTINATION_SERVICE_RESOURCE_FIELD = 'span.destination.service.resource';
3434
export const PROCESSOR_EVENT_FIELD = 'processor.event';
35+
export const OTEL_SPAN_KIND = 'kind';
3536

3637
export const LOG_FILE_PATH_FIELD = 'log.file.path';
3738
export const DATASTREAM_NAMESPACE_FIELD = 'data_stream.namespace';

src/platform/plugins/shared/discover/public/context_awareness/profile_providers/observability/traces_document_profile/span_document_profile/profile.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,44 @@ describe('spanDocumentProfileProvider', () => {
7676
})
7777
).toEqual(RESOLUTION_MISMATCH);
7878
});
79+
80+
it('does not match records with the correct data stream type but the incorrect processor event', () => {
81+
expect(
82+
spanDocumentProfileProvider.resolve({
83+
rootContext: getRootContext({ profileId }),
84+
dataSourceContext: DATA_SOURCE_CONTEXT,
85+
record: buildMockRecord('index', {
86+
'data_stream.type': ['traces'],
87+
'processor.event': ['other'],
88+
}),
89+
})
90+
).toEqual(RESOLUTION_MISMATCH);
91+
});
92+
93+
it('matches records with the correct data stream type and any OTEL `kind` field', () => {
94+
expect(
95+
spanDocumentProfileProvider.resolve({
96+
rootContext: getRootContext({ profileId }),
97+
dataSourceContext: DATA_SOURCE_CONTEXT,
98+
record: buildMockRecord('index', {
99+
'data_stream.type': ['traces'],
100+
kind: 'Internal',
101+
}),
102+
})
103+
).toEqual(RESOLUTION_MATCH);
104+
});
105+
106+
it('defaults to matching records with the correct data stream type but no processor event field', () => {
107+
expect(
108+
spanDocumentProfileProvider.resolve({
109+
rootContext: getRootContext({ profileId }),
110+
dataSourceContext: DATA_SOURCE_CONTEXT,
111+
record: buildMockRecord('index', {
112+
'data_stream.type': ['traces'],
113+
}),
114+
})
115+
).toEqual(RESOLUTION_MATCH);
116+
});
79117
});
80118

81119
describe('when root profile is NOT observability', () => {

src/platform/plugins/shared/discover/public/context_awareness/profile_providers/observability/traces_document_profile/span_document_profile/profile.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
*/
99

1010
import type { DataTableRecord } from '@kbn/discover-utils';
11-
import { DATASTREAM_TYPE_FIELD, getFieldValue, PROCESSOR_EVENT_FIELD } from '@kbn/discover-utils';
11+
import {
12+
DATASTREAM_TYPE_FIELD,
13+
getFieldValue,
14+
OTEL_SPAN_KIND,
15+
PROCESSOR_EVENT_FIELD,
16+
} from '@kbn/discover-utils';
1217
import { TRACES_PRODUCT_FEATURE_ID } from '../../../../../../common/constants';
1318
import type { DocumentProfileProvider } from '../../../../profiles';
1419
import { DocumentType, SolutionType } from '../../../../profiles';
@@ -65,5 +70,10 @@ const getIsSpanRecord = ({ record }: { record: DataTableRecord }) => {
6570
const isSpanDocument = (record: DataTableRecord) => {
6671
const dataStreamType = getFieldValue(record, DATASTREAM_TYPE_FIELD);
6772
const processorEvent = getFieldValue(record, PROCESSOR_EVENT_FIELD);
68-
return dataStreamType === 'traces' && processorEvent === 'span';
73+
const spanKind = getFieldValue(record, OTEL_SPAN_KIND);
74+
75+
const isApmSpan = processorEvent === 'span';
76+
const isOtelSpan = spanKind != null || processorEvent == null;
77+
78+
return dataStreamType === 'traces' && (isApmSpan || isOtelSpan);
6979
};

0 commit comments

Comments
 (0)