diff --git a/packages/kbn-apm-types/src/es_fields/apm.ts b/packages/kbn-apm-types/src/es_fields/apm.ts index 88c1542f6869d..f00d1eeffe3c8 100644 --- a/packages/kbn-apm-types/src/es_fields/apm.ts +++ b/packages/kbn-apm-types/src/es_fields/apm.ts @@ -72,6 +72,8 @@ export const TRANSACTION_OVERFLOW_COUNT = 'transaction.aggregation.overflow_coun // for transaction metrics export const TRANSACTION_ROOT = 'transaction.root'; export const TRANSACTION_PROFILER_STACK_TRACE_IDS = 'transaction.profiler_stack_trace_ids'; +export const TRANSACTION_NAME_TEXT = 'transaction.name.text'; +export const TRANSACTION_REPRESENTATIVE_COUNT = 'transaction.representative_count'; export const EVENT_OUTCOME = 'event.outcome'; @@ -143,6 +145,7 @@ export const LABEL_GC = 'labels.gc'; export const LABEL_TYPE = 'labels.type'; export const LABEL_TELEMETRY_AUTO_VERSION = 'labels.telemetry_auto_version'; export const LABEL_LIFECYCLE_STATE = 'labels.lifecycle_state'; +export const LABEL_SOME_RESOURCE_ATTRIBUTE = 'labels.some_resource_attribute'; export const HOST = 'host'; export const HOST_HOSTNAME = 'host.hostname'; // Do not use. Please use `HOST_NAME` instead. @@ -185,6 +188,8 @@ export const VALUE_OTEL_JVM_PROCESS_MEMORY_NON_HEAP = 'non_heap'; export const TIER = '_tier'; export const INDEX = '_index'; export const DATA_STEAM_TYPE = 'data_stream.type'; +export const DATA_STREAM_NAMESPACE = 'data_stream.namespace'; +export const DATA_STREAM_DATASET = 'data_stream.dataset'; // Mobile export const NETWORK_CONNECTION_TYPE = 'network.connection.type'; diff --git a/x-pack/plugins/observability_solution/apm/server/routes/transactions/get_transaction/index.ts b/x-pack/plugins/observability_solution/apm/server/routes/transactions/get_transaction/index.ts index b807058a4aa43..e5f08762f6d6b 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/transactions/get_transaction/index.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/transactions/get_transaction/index.ts @@ -6,8 +6,7 @@ */ import { rangeQuery, termQuery } from '@kbn/observability-plugin/server'; -import type { Transaction } from '@kbn/apm-types/es_schemas_ui'; -import { normalizeFields } from '../../../utils/normalize_fields'; +import { transactionMapping } from '../../../utils/es_fields_mappings'; import { TRACE_ID, TRANSACTION_ID } from '../../../../common/es_fields/apm'; import { asMutableArray } from '../../../../common/utils/as_mutable_array'; import { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client'; @@ -53,8 +52,5 @@ export async function getTransaction({ }, }); - const fields = resp.hits.hits[0]?.fields; - const fieldsNorm = normalizeFields(fields) as unknown as Transaction; - - return fieldsNorm; + return transactionMapping(resp.hits.hits[0]?.fields); } diff --git a/x-pack/plugins/observability_solution/apm/server/routes/transactions/get_transaction_by_name/index.ts b/x-pack/plugins/observability_solution/apm/server/routes/transactions/get_transaction_by_name/index.ts index f90cad704c049..2de0b2aae04d2 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/transactions/get_transaction_by_name/index.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/transactions/get_transaction_by_name/index.ts @@ -6,13 +6,12 @@ */ import { rangeQuery } from '@kbn/observability-plugin/server'; -import type { Transaction } from '../../../../typings/es_schemas/ui/transaction'; -import { normalizeFields } from '../../../utils/normalize_fields'; import { ApmDocumentType } from '../../../../common/document_type'; import { SERVICE_NAME, TRANSACTION_NAME } from '../../../../common/es_fields/apm'; import { RollupInterval } from '../../../../common/rollup'; import { asMutableArray } from '../../../../common/utils/as_mutable_array'; import { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client'; +import { transactionMapping } from '../../../utils/es_fields_mappings'; export async function getTransactionByName({ transactionName, @@ -53,8 +52,5 @@ export async function getTransactionByName({ }, }); - const fields = resp.hits.hits[0]?.fields; - const fieldsNorm = normalizeFields(fields) as unknown as Transaction; - - return fieldsNorm; + return transactionMapping(resp.hits.hits[0]?.fields); } diff --git a/x-pack/plugins/observability_solution/apm/server/routes/transactions/get_transaction_by_trace/index.ts b/x-pack/plugins/observability_solution/apm/server/routes/transactions/get_transaction_by_trace/index.ts index 68891d3d908e3..b9aca516a5470 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/transactions/get_transaction_by_trace/index.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/transactions/get_transaction_by_trace/index.ts @@ -7,10 +7,9 @@ import { ProcessorEvent } from '@kbn/observability-plugin/common'; import { rangeQuery } from '@kbn/observability-plugin/server'; -import type { Transaction } from '@kbn/apm-types/es_schemas_ui'; -import { normalizeFields } from '../../../utils/normalize_fields'; import { TRACE_ID, PARENT_ID } from '../../../../common/es_fields/apm'; import { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client'; +import { transactionMapping } from '../../../utils/es_fields_mappings'; export async function getRootTransactionByTraceId({ traceId, @@ -52,8 +51,6 @@ export async function getRootTransactionByTraceId({ }; const resp = await apmEventClient.search('get_root_transaction_by_trace_id', params); - const fields = resp.hits.hits[0]?.fields; - const transaction = normalizeFields(fields) as unknown as Transaction; - return { transaction }; + return transactionMapping(resp.hits.hits[0]?.fields); } diff --git a/x-pack/plugins/observability_solution/apm/server/utils/es_fields_mappings.ts b/x-pack/plugins/observability_solution/apm/server/utils/es_fields_mappings.ts index 157212fc01944..0688ab07295d0 100644 --- a/x-pack/plugins/observability_solution/apm/server/utils/es_fields_mappings.ts +++ b/x-pack/plugins/observability_solution/apm/server/utils/es_fields_mappings.ts @@ -11,7 +11,13 @@ import { AGENT_NAME, AGENT_VERSION, AT_TIMESTAMP, + DATA_STEAM_TYPE, + DATA_STREAM_DATASET, + DATA_STREAM_NAMESPACE, EVENT_OUTCOME, + EVENT_SUCCESS_COUNT, + LABEL_SOME_RESOURCE_ATTRIBUTE, + OBSERVER_HOSTNAME, OBSERVER_TYPE, OBSERVER_VERSION, OBSERVER_VERSION_MAJOR, @@ -19,7 +25,9 @@ import { PROCESOR_NAME, PROCESSOR_EVENT, SERVICE_ENVIRONMENT, + SERVICE_FRAMEWORK_NAME, SERVICE_NAME, + SERVICE_NODE_NAME, SPAN_DESTINATION_SERVICE_RESOURCE, SPAN_DURATION, SPAN_ID, @@ -33,6 +41,9 @@ import { TRANSACTION_DURATION, TRANSACTION_ID, TRANSACTION_NAME, + TRANSACTION_REPRESENTATIVE_COUNT, + TRANSACTION_RESULT, + TRANSACTION_SAMPLED, TRANSACTION_TYPE, } from '@kbn/apm-types/src/es_fields/apm'; import { EventOutcome } from '../../common/event_outcome'; @@ -193,6 +204,68 @@ export const linkedParentsOfSpanMapping = (fields: Partial>) => { + return { + transaction: { + representative_count: normalizeValue(fields[TRANSACTION_REPRESENTATIVE_COUNT]), + result: normalizeValue(fields[TRANSACTION_RESULT]), + sampled: normalizeValue(fields[TRANSACTION_SAMPLED]), + id: normalizeValue(fields[TRANSACTION_ID]), + duration: { + us: normalizeValue(fields[TRANSACTION_DURATION]), + }, + type: normalizeValue(fields[TRANSACTION_TYPE]), + name: normalizeValue(fields[TRANSACTION_NAME]), + }, + service: { + node: { + name: normalizeValue(fields[SERVICE_NODE_NAME]), + }, + language: { + name: normalizeValue(fields[SERVICE_NODE_NAME]), + }, + name: normalizeValue(fields[SERVICE_NAME]), + framework: { + name: normalizeValue(fields[SERVICE_FRAMEWORK_NAME]), + }, + }, + trace: { + id: normalizeValue(fields[TRACE_ID]), + }, + agent: { + name: normalizeValue(fields[AGENT_NAME]), + version: normalizeValue(fields[AGENT_VERSION]), + }, + event: { + success_count: normalizeValue(fields[EVENT_SUCCESS_COUNT]), + outcome: normalizeValue(fields[EVENT_OUTCOME]), + }, + processor: { + event: normalizeValue<'transaction'>(fields[PROCESSOR_EVENT]), + }, + data_stream: { + namespace: normalizeValue(fields[DATA_STREAM_NAMESPACE]), + type: normalizeValue(fields[DATA_STEAM_TYPE]), + dataset: normalizeValue(fields[DATA_STREAM_DATASET]), + }, + span: { + id: normalizeValue(fields[SPAN_ID]), + }, + observer: { + hostname: normalizeValue(fields[OBSERVER_HOSTNAME]), + type: normalizeValue(fields[OBSERVER_TYPE]), + version: normalizeValue(fields[OBSERVER_VERSION]), + }, + timestamp: { + us: normalizeValue(fields[TIMESTAMP]), + }, + '@timestamp': normalizeValue(fields[AT_TIMESTAMP]), + labels: { + some_resource_attribute: normalizeValue(fields[LABEL_SOME_RESOURCE_ATTRIBUTE]), + }, + }; +}; + const normalizeValue = (field: unknown[] | unknown): T => { return (Array.isArray(field) && field.length > 0 ? field[0] : field) as T; };