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
2 changes: 2 additions & 0 deletions x-pack/platform/packages/shared/kbn-streams-schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export {
export {
keepFields,
namespacePrefixes,
otelReservedFields,
isNamespacedEcsField,
isOtelReservedField,
getRegularEcsField,
} from './src/helpers/namespaced_ecs';
export { getAdvancedParameters } from './src/helpers/get_advanced_parameters';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ import { KEEP_FIELDS, NAMESPACE_PREFIXES } from '@kbn/streamlang';
export const keepFields: readonly string[] = KEEP_FIELDS;
export const namespacePrefixes: readonly string[] = NAMESPACE_PREFIXES;

/**
* Field names that are reserved for OTel compatibility mode.
* These are either passthrough objects or alias fields that cannot be used as custom field names.
* IMPORTANT: This list must match the keys of baseMappings in logs_layer.ts.
* A test in logs_layer.test.ts ensures these stay in sync.
*/
export const otelReservedFields = [
'body',
'attributes',
'scope',
'resource',
'span.id',
'message',
'trace.id',
'log.level',
] as const;

export const aliases: Record<string, string> = {
trace_id: 'trace.id',
span_id: 'span.id',
Expand Down Expand Up @@ -38,3 +55,11 @@ export function isNamespacedEcsField(field: string): boolean {
KEEP_FIELDS.includes(field as any)
);
}

/**
* Checks if a field name is reserved for OTel compatibility mode.
* Reserved fields are either passthrough objects or alias fields that cannot be redefined.
*/
export function isOtelReservedField(field: string): boolean {
return otelReservedFields.includes(field as (typeof otelReservedFields)[number]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@
*/

import type { InheritedFieldDefinition, Streams } from '@kbn/streams-schema';
import { otelReservedFields } from '@kbn/streams-schema';
import { addAliasesForNamespacedFields, baseMappings, baseFields } from './logs_layer';

describe('logs_layer', () => {
describe('baseMappings and otelReservedFields sync', () => {
it('should have baseMappings keys match otelReservedFields', () => {
const baseMappingsKeys = Object.keys(baseMappings).sort();
const reservedFieldsSorted = [...otelReservedFields].sort();

expect(baseMappingsKeys).toEqual(reservedFieldsSorted);
});
});
describe('addAliasesForNamespacedFields', () => {
let mockStreamDefinition: Streams.WiredStream.Definition;
let mockInheritedFields: InheritedFieldDefinition;
Expand Down
Loading
Loading