diff --git a/packages/kbn-apm-types/src/es_fields/apm.ts b/packages/kbn-apm-types/src/es_fields/apm.ts index a8b7ae558b3e6..6c7276317894c 100644 --- a/packages/kbn-apm-types/src/es_fields/apm.ts +++ b/packages/kbn-apm-types/src/es_fields/apm.ts @@ -21,7 +21,11 @@ export const CLOUD_AVAILABILITY_ZONE = 'cloud.availability_zone'; export const CLOUD_PROVIDER = 'cloud.provider'; export const CLOUD_REGION = 'cloud.region'; export const CLOUD_MACHINE_TYPE = 'cloud.machine.type'; +export const CLOUD_PROJECT_ID = 'cloud.project.id'; +export const CLOUD_PROJECT_NAME = 'cloud.project.name'; +export const CLOUD_IMAGE_ID = 'cloud.image.id'; export const CLOUD_ACCOUNT_ID = 'cloud.account.id'; +export const CLOUD_ACCOUNT_NAME = 'cloud.account.name'; export const CLOUD_INSTANCE_ID = 'cloud.instance.id'; export const CLOUD_INSTANCE_NAME = 'cloud.instance.name'; export const CLOUD_SERVICE_NAME = 'cloud.service.name'; @@ -56,9 +60,11 @@ export const USER_AGENT_DEVICE_NAME = 'user_agent.device.name'; export const USER_AGENT_VERSION = 'user_agent.version'; export const OBSERVER_HOSTNAME = 'observer.hostname'; -export const OBSERVER_LISTENING = 'observer.listening'; +export const OBSERVER_ID = 'observer.id'; export const OBSERVER_TYPE = 'observer.type'; +export const OBSERVER_NAME = 'observer.name'; export const OBSERVER_VERSION = 'observer.version'; +export const OBSERVER_LISTENING = 'observer.listening'; export const OBSERVER_VERSION_MAJOR = 'observer.version_major'; export const PROCESSOR_EVENT = 'processor.event'; export const PROCESSOR_NAME = 'processor.name'; @@ -166,6 +172,8 @@ export const HOST_IP = 'host.ip'; export const CONTAINER_ID = 'container.id'; export const CONTAINER = 'container'; export const CONTAINER_IMAGE = 'container.image.name'; +export const CONTAINER_OS = 'container.os'; +export const CONTAINER_TTL_INSTANCES = 'container.totalNumberInstances'; export const KUBERNETES = 'kubernetes'; export const KUBERNETES_POD_NAME = 'kubernetes.pod.name'; diff --git a/x-pack/plugins/observability_solution/apm/common/correlations/types.ts b/x-pack/plugins/observability_solution/apm/common/correlations/types.ts index 6555e8a5d953d..08b345b2461d5 100644 --- a/x-pack/plugins/observability_solution/apm/common/correlations/types.ts +++ b/x-pack/plugins/observability_solution/apm/common/correlations/types.ts @@ -27,7 +27,6 @@ export interface ResponseHitSource { } export interface ResponseHit { - _source: ResponseHitSource; fields: ResponseHitSource; } diff --git a/x-pack/plugins/observability_solution/apm/common/es_fields/infra_metrics.ts b/x-pack/plugins/observability_solution/apm/common/es_fields/infra_metrics.ts index fbf09e1887dfb..7d7081a0e1900 100644 --- a/x-pack/plugins/observability_solution/apm/common/es_fields/infra_metrics.ts +++ b/x-pack/plugins/observability_solution/apm/common/es_fields/infra_metrics.ts @@ -7,9 +7,12 @@ // Kubernetes export const KUBERNETES_CONTAINER_NAME = 'kubernetes.container.name'; +export const KUBERNETES_NODE_NAME = 'kubernetes.node.name'; +export const KUBERNETES_CONTAINER_ID = 'kubernetes.container.id'; export const KUBERNETES_DEPLOYMENT = 'kubernetes.deployment'; export const KUBERNETES_DEPLOYMENT_NAME = 'kubernetes.deployment.name'; export const KUBERNETES_NAMESPACE_NAME = 'kubernetes.namespace.name'; export const KUBERNETES_NAMESPACE = 'kubernetes.namespace'; export const KUBERNETES_REPLICASET = 'kubernetes.replicaset'; export const KUBERNETES_REPLICASET_NAME = 'kubernetes.replicaset.name'; +export const KUBERNETES_POD_NAME = 'kubernetes.pod.name'; diff --git a/x-pack/plugins/observability_solution/apm/server/routes/errors/get_error_groups/get_error_sample_details.ts b/x-pack/plugins/observability_solution/apm/server/routes/errors/get_error_groups/get_error_sample_details.ts index 28f8a1d4573d1..f008f8d6e44fb 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/errors/get_error_groups/get_error_sample_details.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/errors/get_error_groups/get_error_sample_details.ts @@ -6,7 +6,61 @@ */ import { rangeQuery, kqlQuery } from '@kbn/observability-plugin/server'; -import { ERROR_ID, SERVICE_NAME } from '../../../../common/es_fields/apm'; +import { OBSERVER_VERSION_MAJOR } from '@kbn/observability-shared-plugin/common'; +import { + ERROR_EXCEPTION_STACKTRACE, + ERROR_LOG_STACKTRACE, + ERROR_STACK_TRACE, +} from '@kbn/discover-utils/src/field_constants'; +import { + AGENT_NAME, + AGENT_VERSION, + CONTAINER_ID, + CONTAINER_IMAGE, + ERROR_ID, + HOST_ARCHITECTURE, + HOST_HOSTNAME, + HOST_NAME, + HTTP_RESPONSE_STATUS_CODE, + KUBERNETES_POD_UID, + OBSERVER_HOSTNAME, + OBSERVER_ID, + OBSERVER_TYPE, + OBSERVER_NAME, + OBSERVER_VERSION, + PARENT_ID, + PROCESSOR_EVENT, + PROCESSOR_NAME, + SERVICE_NAME, + TRACE_ID, + SERVICE_ENVIRONMENT, + SERVICE_FRAMEWORK_NAME, + SERVICE_FRAMEWORK_VERSION, + SERVICE_NODE_NAME, + SERVICE_RUNTIME_NAME, + SERVICE_RUNTIME_VERSION, + SERVICE_LANGUAGE_NAME, + SERVICE_LANGUAGE_VERSION, + SERVICE_VERSION, + HOST_OS_PLATFORM, + TRANSACTION_ID, + TRANSACTION_SAMPLED, + TRANSACTION_TYPE, + ERROR_CULPRIT, + ERROR_PAGE_URL, + ERROR_LOG_MESSAGE, + URL_FULL, + USER_ID, + PROCESS_PID, + PROCESS_ARGS, + PROCESS_TITLE, + AT_TIMESTAMP, + ERROR_EXC_HANDLED, + ERROR_EXC_TYPE, + ERROR_EXC_MESSAGE, + URL_DOMAIN, + URL_ORIGINAL, +} from '../../../../common/es_fields/apm'; import { environmentQuery } from '../../../../common/utils/environment_query'; import { ApmDocumentType } from '../../../../common/document_type'; import { RollupInterval } from '../../../../common/rollup'; @@ -15,6 +69,13 @@ import { getTransaction } from '../../transactions/get_transaction'; import { Transaction } from '../../../../typings/es_schemas/ui/transaction'; import { APMError } from '../../../../typings/es_schemas/ui/apm_error'; import { errorSampleDetailsMapping } from '../../../utils/es_fields_mappings'; +import { + KUBERNETES_CONTAINER_NAME, + KUBERNETES_DEPLOYMENT_NAME, + KUBERNETES_NAMESPACE, + KUBERNETES_REPLICASET_NAME, + KUBERNETES_CONTAINER_ID, +} from '../../../../common/es_fields/infra_metrics'; export interface ErrorSampleDetailsResponse { transaction: Transaction | undefined; @@ -61,7 +122,73 @@ export async function getErrorSampleDetails({ ], }, }, - fields: ['*'], + fields: [ + AGENT_VERSION, + AGENT_NAME, + PARENT_ID, + TRACE_ID, + // AGENT_EPHEMERAL_ID, + // OBSERVER_EPHEMERAL_ID, + OBSERVER_HOSTNAME, + OBSERVER_ID, + OBSERVER_TYPE, + OBSERVER_NAME, + OBSERVER_VERSION, + OBSERVER_VERSION_MAJOR, + CONTAINER_ID, + CONTAINER_IMAGE, + PROCESSOR_NAME, + PROCESSOR_EVENT, + HOST_ARCHITECTURE, + HOST_HOSTNAME, + HOST_NAME, + 'host.ip', + 'http.request.method', + HTTP_RESPONSE_STATUS_CODE, + 'http.version', + KUBERNETES_POD_UID, + KUBERNETES_NAMESPACE, + KUBERNETES_REPLICASET_NAME, + KUBERNETES_DEPLOYMENT_NAME, + KUBERNETES_CONTAINER_ID, + KUBERNETES_CONTAINER_NAME, + SERVICE_NAME, + SERVICE_ENVIRONMENT, + SERVICE_FRAMEWORK_NAME, + SERVICE_FRAMEWORK_VERSION, + SERVICE_NODE_NAME, + SERVICE_RUNTIME_NAME, + SERVICE_RUNTIME_VERSION, + SERVICE_LANGUAGE_NAME, + SERVICE_LANGUAGE_VERSION, + SERVICE_VERSION, + PROCESS_ARGS, + PROCESS_PID, + PROCESS_TITLE, + HOST_OS_PLATFORM, + AT_TIMESTAMP, + TRANSACTION_ID, + TRANSACTION_SAMPLED, + TRANSACTION_TYPE, + ERROR_ID, + ERROR_CULPRIT, + 'error.exception.attributes.response', + // ERROR_EXC_ATTRIBUTES_RESPONSE, + // ERROR_EXC_CODE, + ERROR_EXC_MESSAGE, + ERROR_EXC_TYPE, + // ERROR_EXCEPTION_MODULE, + ERROR_EXC_HANDLED, + ERROR_EXCEPTION_STACKTRACE, // todo: fix me + ERROR_PAGE_URL, + ERROR_LOG_MESSAGE, + ERROR_LOG_STACKTRACE, // todo: fixme + ERROR_STACK_TRACE, + URL_DOMAIN, + URL_FULL, + URL_ORIGINAL, + USER_ID, + ], }, }; diff --git a/x-pack/plugins/observability_solution/apm/server/routes/services/get_service_metadata_details.ts b/x-pack/plugins/observability_solution/apm/server/routes/services/get_service_metadata_details.ts index 3609905e2d28f..2c0064e0782c3 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/services/get_service_metadata_details.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/services/get_service_metadata_details.ts @@ -7,32 +7,59 @@ import { rangeQuery } from '@kbn/observability-plugin/server'; import { ProcessorEvent } from '@kbn/observability-plugin/common'; +import { serviceMetadataDetailsMapping } from '../../utils/es_fields_mappings'; import { environmentQuery } from '../../../common/utils/environment_query'; import { - AGENT, - CONTAINER, - CLOUD, + KUBERNETES_CONTAINER_NAME, + KUBERNETES_DEPLOYMENT_NAME, + KUBERNETES_NAMESPACE, + KUBERNETES_REPLICASET_NAME, + KUBERNETES_CONTAINER_ID, + KUBERNETES_NODE_NAME, + KUBERNETES_POD_NAME, +} from '../../../common/es_fields/infra_metrics'; +import { + AGENT_NAME, + AGENT_VERSION, + CONTAINER_ID, + CONTAINER_IMAGE, CLOUD_AVAILABILITY_ZONE, + CLOUD_INSTANCE_ID, CLOUD_REGION, + CLOUD_PROJECT_NAME, CLOUD_MACHINE_TYPE, CLOUD_SERVICE_NAME, - CONTAINER_ID, - HOST, - KUBERNETES, - SERVICE, - SERVICE_NAME, + CLOUD_INSTANCE_NAME, + CLOUD_PROVIDER, + CLOUD_ACCOUNT_ID, + CLOUD_ACCOUNT_NAME, + CLOUD_IMAGE_ID, + CLOUD_PROJECT_ID, + HOST_ARCHITECTURE, + HOST_HOSTNAME, + HOST_NAME, + HOST_IP, + SERVICE_ENVIRONMENT, + SERVICE_FRAMEWORK_NAME, + SERVICE_FRAMEWORK_VERSION, SERVICE_NODE_NAME, + SERVICE_RUNTIME_NAME, + SERVICE_RUNTIME_VERSION, + SERVICE_LANGUAGE_NAME, + SERVICE_LANGUAGE_VERSION, SERVICE_VERSION, + SERVICE_NAME, FAAS_ID, FAAS_TRIGGER_TYPE, LABEL_TELEMETRY_AUTO_VERSION, + CONTAINER_TTL_INSTANCES, + HOST_OS_PLATFORM, } from '../../../common/es_fields/apm'; import { ContainerType } from '../../../common/service_metadata'; import { TransactionRaw } from '../../../typings/es_schemas/raw/transaction_raw'; import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client'; import { should } from './get_service_metadata_icons'; -import { normalizeFields } from '../../utils/normalize_fields'; import { isOpenTelemetryAgentName, hasOpenTelemetryPrefix } from '../../../common/agent_name'; type ServiceMetadataDetailsRaw = Pick< @@ -113,6 +140,7 @@ export async function getServiceMetadataDetails({ body: { track_total_hits: 1, size: 1, + _source: false, query: { bool: { filter, should } }, aggs: { serviceVersions: { @@ -166,7 +194,48 @@ export async function getServiceMetadataDetails({ }, totalNumberInstances: { cardinality: { field: SERVICE_NODE_NAME } }, }, - fields: [SERVICE, AGENT, HOST, CONTAINER, KUBERNETES, CLOUD, LABEL_TELEMETRY_AUTO_VERSION], + fields: [ + SERVICE_ENVIRONMENT, + SERVICE_FRAMEWORK_NAME, + SERVICE_FRAMEWORK_VERSION, + SERVICE_NODE_NAME, + SERVICE_RUNTIME_NAME, + SERVICE_RUNTIME_VERSION, + SERVICE_LANGUAGE_NAME, + SERVICE_LANGUAGE_VERSION, + SERVICE_VERSION, + SERVICE_NAME, + AGENT_NAME, + AGENT_VERSION, + CONTAINER_ID, + CONTAINER_IMAGE, + HOST_ARCHITECTURE, + HOST_HOSTNAME, + HOST_NAME, + HOST_IP, + HOST_OS_PLATFORM, + CONTAINER_TTL_INSTANCES, + KUBERNETES_NAMESPACE, + KUBERNETES_NODE_NAME, + KUBERNETES_POD_NAME, + KUBERNETES_REPLICASET_NAME, + KUBERNETES_DEPLOYMENT_NAME, + KUBERNETES_CONTAINER_ID, + KUBERNETES_CONTAINER_NAME, + CLOUD_AVAILABILITY_ZONE, + CLOUD_INSTANCE_NAME, + CLOUD_INSTANCE_ID, + CLOUD_MACHINE_TYPE, + CLOUD_PROJECT_ID, + CLOUD_PROJECT_NAME, + CLOUD_PROVIDER, + CLOUD_REGION, + CLOUD_ACCOUNT_ID, + CLOUD_ACCOUNT_NAME, + CLOUD_IMAGE_ID, + CLOUD_SERVICE_NAME, + LABEL_TELEMETRY_AUTO_VERSION, + ], }, }; @@ -174,7 +243,7 @@ export async function getServiceMetadataDetails({ const fields = response.hits.hits[0]?.fields; // todo: missing `fields` property? - const fieldsNorm = (fields ? normalizeFields(fields) : undefined) as + const fieldsNorm = (fields ? serviceMetadataDetailsMapping(fields) : undefined) as | ServiceMetadataDetailsRaw | undefined; diff --git a/x-pack/plugins/observability_solution/apm/server/routes/services/get_service_metadata_icons.ts b/x-pack/plugins/observability_solution/apm/server/routes/services/get_service_metadata_icons.ts index 8ba26cf5a55c5..3108b07524ec2 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/services/get_service_metadata_icons.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/services/get_service_metadata_icons.ts @@ -7,24 +7,44 @@ import { rangeQuery } from '@kbn/observability-plugin/server'; import { ProcessorEvent } from '@kbn/observability-plugin/common'; +import { TransactionRaw } from '@kbn/apm-types'; import { serviceMetadataIconsMapping } from '../../utils/es_fields_mappings'; import { AGENT_NAME, CLOUD_PROVIDER, CLOUD_SERVICE_NAME, CONTAINER_ID, - KUBERNETES, SERVICE_NAME, KUBERNETES_POD_NAME, HOST_OS_PLATFORM, LABEL_TELEMETRY_AUTO_VERSION, AGENT_VERSION, SERVICE_FRAMEWORK_NAME, + CLOUD_AVAILABILITY_ZONE, + CLOUD_INSTANCE_NAME, + CLOUD_INSTANCE_ID, + CLOUD_MACHINE_TYPE, + CLOUD_PROJECT_ID, + CLOUD_PROJECT_NAME, + CLOUD_REGION, + CLOUD_ACCOUNT_ID, + CLOUD_ACCOUNT_NAME, + CLOUD_IMAGE_ID, } from '../../../common/es_fields/apm'; import { ContainerType } from '../../../common/service_metadata'; import { getProcessorEventForTransactions } from '../../lib/helpers/transactions'; import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client'; import { ServerlessType, getServerlessTypeFromCloudData } from '../../../common/serverless'; +import { + KUBERNETES_CONTAINER_ID, + KUBERNETES_CONTAINER_NAME, + KUBERNETES_DEPLOYMENT_NAME, + KUBERNETES_NAMESPACE, + KUBERNETES_NODE_NAME, + KUBERNETES_REPLICASET_NAME, +} from '../../../common/es_fields/infra_metrics'; + +type ServiceMetadataIconsRaw = Pick; export interface ServiceMetadataIcons { agentName?: string; @@ -70,8 +90,32 @@ export async function getServiceMetadataIcons({ body: { track_total_hits: 1, size: 1, + _source: false, query: { bool: { filter, should } }, - fields: [KUBERNETES, CLOUD_PROVIDER, CONTAINER_ID, AGENT_NAME, CLOUD_SERVICE_NAME], + fields: [ + KUBERNETES_NAMESPACE, + KUBERNETES_NODE_NAME, + KUBERNETES_POD_NAME, + KUBERNETES_REPLICASET_NAME, + KUBERNETES_DEPLOYMENT_NAME, + KUBERNETES_CONTAINER_ID, + KUBERNETES_CONTAINER_NAME, + CLOUD_AVAILABILITY_ZONE, + CLOUD_INSTANCE_NAME, + CLOUD_INSTANCE_ID, + CLOUD_MACHINE_TYPE, + CLOUD_PROJECT_ID, + CLOUD_PROJECT_NAME, + CLOUD_PROVIDER, + CLOUD_REGION, + CLOUD_ACCOUNT_ID, + CLOUD_ACCOUNT_NAME, + CLOUD_IMAGE_ID, + CLOUD_SERVICE_NAME, + CONTAINER_ID, + AGENT_NAME, + CLOUD_SERVICE_NAME, + ], }, }; @@ -88,7 +132,7 @@ export async function getServiceMetadataIcons({ const { kubernetes, cloud, container, agent } = serviceMetadataIconsMapping( response.hits.hits[0].fields - ); + ) as ServiceMetadataIconsRaw; let containerType: ContainerType; if (!!kubernetes) { 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 e5f08762f6d6b..b3ce38f1df4a3 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 @@ -7,7 +7,34 @@ import { rangeQuery, termQuery } from '@kbn/observability-plugin/server'; import { transactionMapping } from '../../../utils/es_fields_mappings'; -import { TRACE_ID, TRANSACTION_ID } from '../../../../common/es_fields/apm'; +import { + AGENT_NAME, + AGENT_VERSION, + DATA_STEAM_TYPE, + DATA_STREAM_DATASET, + DATA_STREAM_NAMESPACE, + EVENT_OUTCOME, + EVENT_SUCCESS_COUNT, + LABEL_SOME_RESOURCE_ATTRIBUTE, + OBSERVER_HOSTNAME, + OBSERVER_TYPE, + OBSERVER_VERSION, + PROCESSOR_EVENT, + SERVICE_FRAMEWORK_NAME, + SERVICE_NAME, + SERVICE_NODE_NAME, + TIMESTAMP, + TRACE_ID, + TRANSACTION_DURATION, + TRANSACTION_ID, + TRANSACTION_NAME, + TRANSACTION_RESULT, + TRANSACTION_SAMPLED, + TRANSACTION_TYPE, + SPAN_ID, + AT_TIMESTAMP, + TRANSACTION_REPRESENTATIVE_COUNT, +} 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'; import { ApmDocumentType } from '../../../../common/document_type'; @@ -48,7 +75,34 @@ export async function getTransaction({ ]), }, }, - fields: ['*'], + fields: [ + TRANSACTION_REPRESENTATIVE_COUNT, + TRANSACTION_RESULT, + TRANSACTION_SAMPLED, + TRANSACTION_ID, + TRANSACTION_DURATION, + TRANSACTION_TYPE, + TRANSACTION_NAME, + SERVICE_NODE_NAME, + SERVICE_NAME, + SERVICE_FRAMEWORK_NAME, + TRACE_ID, + AGENT_NAME, + AGENT_VERSION, + EVENT_SUCCESS_COUNT, + EVENT_OUTCOME, + PROCESSOR_EVENT, + DATA_STREAM_NAMESPACE, + DATA_STEAM_TYPE, + DATA_STREAM_DATASET, + SPAN_ID, + OBSERVER_HOSTNAME, + OBSERVER_TYPE, + OBSERVER_VERSION, + TIMESTAMP, + AT_TIMESTAMP, + LABEL_SOME_RESOURCE_ATTRIBUTE, + ], }, }); 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 ccd116c8d5949..1bc570365b33d 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 @@ -48,7 +48,6 @@ import { SPAN_SUBTYPE, SPAN_SYNC, SPAN_TYPE, - SPAN_LINKS, TIMESTAMP, TRACE_ID, TRANSACTION_DURATION, @@ -64,11 +63,10 @@ import { ERROR_ID, ERROR_LOG_MESSAGE, HOST_NAME, - Container, - Kubernetes, + CONTAINER_ID, + CONTAINER_IMAGE, CLOUD_PROVIDER, - CONTAINER, - KUBERNETES, + CLOUD_INSTANCE_NAME, AGENT_ACTIVATION_METHOD, HOST_ARCHITECTURE, HOST_HOSTNAME, @@ -88,7 +86,23 @@ import { SERVICE_TARGET_TYPE, SPAN_REPRESENTATIVE_COUNT, SERVICE_LANGUAGE_VERSION, + CLOUD_AVAILABILITY_ZONE, + CLOUD_INSTANCE_ID, + CLOUD_MACHINE_TYPE, + CLOUD_PROJECT_ID, + CLOUD_PROJECT_NAME, + CLOUD_REGION, + CLOUD_ACCOUNT_ID, + CLOUD_ACCOUNT_NAME, + CLOUD_IMAGE_ID, + CLOUD_SERVICE_NAME, } from '@kbn/apm-types'; +import { + KUBERNETES_CONTAINER_NAME, + KUBERNETES_DEPLOYMENT_NAME, + KUBERNETES_REPLICASET_NAME, + KUBERNETES_CONTAINER_ID, +} from '../../common/es_fields/infra_metrics'; import { Transaction } from '../../typings/es_schemas/ui/transaction'; import { TransactionRaw } from '../../typings/es_schemas/raw/transaction_raw'; import { @@ -100,7 +114,10 @@ import { EventOutcome } from '../../common/event_outcome'; import { Exception } from '../../typings/es_schemas/raw/error_raw'; type ServiceMetadataIconsRaw = Pick; - +type ServiceMetadataDetailsRaw = Pick< + TransactionRaw, + 'service' | 'agent' | 'host' | 'container' | 'kubernetes' | 'cloud' | 'labels' +>; const normalizeValue = (field: unknown[] | unknown): T => { return (Array.isArray(field) && field.length > 0 ? field[0] : field) as T; }; @@ -275,20 +292,16 @@ export const spanLinksDetailsMapping = (fields: Partial>) => { if (!fields) return undefined; - return { - span: { - links: [ - { - trace: { - id: normalizeValue(fields[SPAN_LINKS_TRACE_ID]), - }, - span: { - id: normalizeValue(fields[SPAN_LINKS_SPAN_ID]), - }, - }, - ], - }, - }; + return (fields[SPAN_LINKS_TRACE_ID] as string[]).map((v, index) => { + return { + trace: { + id: v, + }, + span: { + id: fields[SPAN_LINKS_SPAN_ID]?.[index] ?? '', + }, + }; + }) as SpanLink[]; }; export const transactionMapping = (fields: Partial>) => { @@ -330,7 +343,8 @@ export const transactionMapping = (fields: Partial>) = outcome: normalizeValue(fields[EVENT_OUTCOME]), }, processor: { - event: normalizeValue(fields[PROCESSOR_EVENT]), + event: normalizeValue<'transaction'>(fields[PROCESSOR_EVENT]), + name: normalizeValue<'transaction'>(fields[PROCESSOR_NAME]), }, data_stream: { namespace: normalizeValue(fields[DATA_STREAM_NAMESPACE]), @@ -339,11 +353,13 @@ export const transactionMapping = (fields: Partial>) = }, span: { id: normalizeValue(fields[SPAN_ID]), + links: linkedParentsOfSpanMapping(fields), }, observer: { hostname: normalizeValue(fields[OBSERVER_HOSTNAME]), type: normalizeValue(fields[OBSERVER_TYPE]), version: normalizeValue(fields[OBSERVER_VERSION]), + version_major: normalizeValue(fields[OBSERVER_VERSION_MAJOR]), }, timestamp: { us: normalizeValue(fields[TIMESTAMP]), @@ -404,7 +420,7 @@ export const traceDocMapping = ( us: normalizeValue(fields[SPAN_DURATION]), }, action: normalizeValue(fields[SPAN_ACTION]), - links: normalizeValue(fields[SPAN_LINKS]), + links: linkedParentsOfSpanMapping(fields) as SpanLink[], composite: { count: normalizeValue(fields[SPAN_COMPOSITE_COUNT]), sum: { @@ -532,24 +548,185 @@ export const errorSampleDetailsMapping = ( }; }; +export const serviceMetadataDetailsMapping = ( + fields: Partial> +): ServiceMetadataDetailsRaw | undefined => { + if (!fields) return undefined; + const kubernetesNamespace = normalizeValue(fields[KUBERNETES_NAMESPACE]); + const containerId = normalizeValue(fields[CONTAINER_ID]); + const cloudServiceName = normalizeValue(fields[CLOUD_PROVIDER]); + const serviceRuntimeName = normalizeValue(fields[SERVICE_RUNTIME_NAME]); + return { + service: { + name: normalizeValue(fields[SERVICE_NAME]), + version: normalizeValue(fields[SERVICE_VERSION]), + environment: normalizeValue(fields[SERVICE_ENVIRONMENT]), + framework: { + name: normalizeValue(fields[SERVICE_FRAMEWORK_NAME]), + version: normalizeValue(fields[SERVICE_FRAMEWORK_VERSION]), + }, + node: { + name: normalizeValue(fields[SERVICE_NODE_NAME]), + }, + ...(serviceRuntimeName + ? { + runtime: { + name: serviceRuntimeName, + version: normalizeValue(fields[SERVICE_RUNTIME_VERSION]), + }, + } + : undefined), + language: { + name: normalizeValue(fields[SERVICE_LANGUAGE_NAME]), + version: normalizeValue(fields[SERVICE_LANGUAGE_VERSION]), + }, + }, + agent: { + name: normalizeValue(fields[AGENT_NAME]), + version: normalizeValue(fields[AGENT_VERSION]), + }, + host: { + architecture: normalizeValue(fields[HOST_ARCHITECTURE]), + hostname: normalizeValue(fields[HOST_HOSTNAME]), + name: normalizeValue(fields[HOST_NAME]), + ip: normalizeValue(fields[HOST_IP]), + os: { + platform: normalizeValue(fields[HOST_OS_PLATFORM]), + }, + }, + ...(containerId + ? { + container: { + id: containerId, + image: normalizeValue(fields[CONTAINER_IMAGE]), + }, + } + : undefined), + ...(kubernetesNamespace + ? { + kubernetes: { + pod: { + name: normalizeValue(fields[KUBERNETES_POD_NAME]), + uid: normalizeValue(fields[KUBERNETES_POD_UID]), + }, + namespace: kubernetesNamespace, + replicaset: { + name: normalizeValue(fields[KUBERNETES_REPLICASET_NAME]), + }, + deployment: { + name: normalizeValue(fields[KUBERNETES_DEPLOYMENT_NAME]), + }, + container: { + id: normalizeValue(fields[KUBERNETES_CONTAINER_ID]), + name: normalizeValue(fields[KUBERNETES_CONTAINER_NAME]), + }, + }, + } + : undefined), + ...(cloudServiceName + ? { + cloud: { + availability_zone: normalizeValue(fields[CLOUD_AVAILABILITY_ZONE]), + instance: { + name: normalizeValue(fields[CLOUD_INSTANCE_NAME]), + id: normalizeValue(fields[CLOUD_INSTANCE_ID]), + }, + machine: { + type: normalizeValue(fields[CLOUD_MACHINE_TYPE]), + }, + project: { + id: normalizeValue(fields[CLOUD_PROJECT_ID]), + name: normalizeValue(fields[CLOUD_PROJECT_NAME]), + }, + provider: normalizeValue(fields[CLOUD_PROVIDER]), + region: normalizeValue(fields[CLOUD_REGION]), + account: { + id: normalizeValue(fields[CLOUD_ACCOUNT_ID]), + name: normalizeValue(fields[CLOUD_ACCOUNT_NAME]), + }, + image: { + id: normalizeValue(fields[CLOUD_IMAGE_ID]), + }, + service: { + name: normalizeValue(fields[CLOUD_SERVICE_NAME]), + }, + }, + } + : undefined), + }; +}; + export const serviceMetadataIconsMapping = ( fields: Partial> ): ServiceMetadataIconsRaw | undefined => { if (!fields) return undefined; - + const kubernetesPodName = normalizeValue(fields[KUBERNETES_POD_NAME]); + const containerId = normalizeValue(fields[CONTAINER_ID]); + const cloudProvider = normalizeValue(fields[CLOUD_PROVIDER]); return { agent: { name: normalizeValue(fields[AGENT_NAME]), version: '', }, - cloud: { - provider: normalizeValue(fields[CLOUD_PROVIDER]), - service: { - name: normalizeValue(fields[CLOUD_PROVIDER]), - }, - }, - container: normalizeValue(fields[CONTAINER]), - kubernetes: normalizeValue(fields[KUBERNETES]), + ...(cloudProvider + ? { + cloud: { + availability_zone: normalizeValue(fields[CLOUD_AVAILABILITY_ZONE]), + instance: { + name: normalizeValue(fields[CLOUD_INSTANCE_NAME]), + id: normalizeValue(fields[CLOUD_INSTANCE_ID]), + }, + machine: { + type: normalizeValue(fields[CLOUD_MACHINE_TYPE]), + }, + project: { + id: normalizeValue(fields[CLOUD_PROJECT_ID]), + name: normalizeValue(fields[CLOUD_PROJECT_NAME]), + }, + provider: cloudProvider, + region: normalizeValue(fields[CLOUD_REGION]), + account: { + id: normalizeValue(fields[CLOUD_ACCOUNT_ID]), + name: normalizeValue(fields[CLOUD_ACCOUNT_NAME]), + }, + image: { + id: normalizeValue(fields[CLOUD_IMAGE_ID]), + }, + service: { + name: normalizeValue(fields[CLOUD_SERVICE_NAME]), + }, + }, + } + : undefined), + ...(containerId + ? { + container: { + id: containerId, + image: normalizeValue(fields[CONTAINER_IMAGE]), + }, + } + : undefined), + ...(kubernetesPodName + ? { + kubernetes: { + pod: { + name: normalizeValue(fields[KUBERNETES_POD_NAME]), + uid: normalizeValue(fields[KUBERNETES_POD_UID]), + }, + namespace: normalizeValue(fields[KUBERNETES_NAMESPACE]), + replicaset: { + name: normalizeValue(fields[KUBERNETES_REPLICASET_NAME]), + }, + deployment: { + name: normalizeValue(fields[KUBERNETES_DEPLOYMENT_NAME]), + }, + container: { + id: normalizeValue(fields[KUBERNETES_CONTAINER_ID]), + name: normalizeValue(fields[KUBERNETES_CONTAINER_NAME]), + }, + }, + } + : undefined), }; };