Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { OTEL_SPAN_KIND, PROCESSOR_EVENT_FIELD, DataTableRecord } from '@kbn/discover-utils';
import { PROCESSOR_EVENT_FIELD, DataTableRecord } from '@kbn/discover-utils';
import { isSpanHit } from './is_span';

describe('isSpanHit', () => {
Expand All @@ -19,17 +19,6 @@ describe('isSpanHit', () => {
expect(isSpanHit(hit)).toBe(false);
});

it('returns true for an OTEL span (spanKind is present)', () => {
const hit = {
flattened: {
[OTEL_SPAN_KIND]: 'client',
[PROCESSOR_EVENT_FIELD]: 'span',
},
} as unknown as DataTableRecord;

expect(isSpanHit(hit)).toBe(true);
});

it('returns true when processorEvent is null (OTEL fallback)', () => {
const hit = {
flattened: {
Expand All @@ -50,11 +39,10 @@ describe('isSpanHit', () => {
expect(isSpanHit(hit)).toBe(true);
});

it('returns false when processorEvent is not "span" and spanKind is null', () => {
it('returns false when processorEvent is not "span" ', () => {
const hit = {
flattened: {
[PROCESSOR_EVENT_FIELD]: 'transaction',
[OTEL_SPAN_KIND]: null,
},
} as unknown as DataTableRecord;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { DataTableRecord, OTEL_SPAN_KIND, PROCESSOR_EVENT_FIELD } from '@kbn/discover-utils';
import { DataTableRecord, PROCESSOR_EVENT_FIELD } from '@kbn/discover-utils';
import { getFlattenedFields } from '@kbn/discover-utils/src/utils/get_flattened_fields';

export const isSpanHit = (hit: DataTableRecord | null): boolean => {
if (!hit?.flattened) {
return false;
}

const processorEvent = hit.flattened[PROCESSOR_EVENT_FIELD];
const spanKind = hit.flattened[OTEL_SPAN_KIND];
const processorEvent = getFlattenedFields<{ [PROCESSOR_EVENT_FIELD]: string }>(hit, [
PROCESSOR_EVENT_FIELD,
])[PROCESSOR_EVENT_FIELD];

const isOtelSpan = spanKind != null || processorEvent == null;
const isOtelSpan = processorEvent == null;
const isApmSpan = processorEvent === 'span';

return isApmSpan || isOtelSpan;
Expand Down