Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚧 WIP 🚧 Replace _source in the APM queries #192608

Closed
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
45ff639
WIP Replace _source in the APM queries
jennypavlova Sep 11, 2024
b082ebd
Add fields to some queries
jennypavlova Sep 11, 2024
e3ca03e
lint fixes
jennypavlova Sep 11, 2024
91a5bbc
Convert more queries
jennypavlova Sep 12, 2024
73a5731
Add types and more _source changes
jennypavlova Sep 12, 2024
0354d3a
Agent name query _source to fields
jennypavlova Sep 12, 2024
8d921bb
Change _source to fields
jennypavlova Sep 16, 2024
8e5614c
Merge branch 'main' into 192606-poc-otel-data-with-apm-ui-replacing-_…
jennypavlova Sep 16, 2024
a9474cd
Add fields to snapshots
jennypavlova Sep 16, 2024
a246c31
Type fixes
jennypavlova Sep 16, 2024
53dabf7
Snapshot update
jennypavlova Sep 16, 2024
55ea137
Merge branch 'main' into 192606-poc-otel-data-with-apm-ui-replacing-_…
jennypavlova Sep 16, 2024
638b1cc
Error fix
jennypavlova Sep 17, 2024
00d88b5
Add undefined check
jennypavlova Sep 17, 2024
02ef2f5
Use observer version field
jennypavlova Sep 26, 2024
bb8c710
Remove _source
jennypavlova Sep 26, 2024
536773d
Merge branch 'main' into 192606-poc-otel-data-with-apm-ui-replacing-_…
jennypavlova Sep 26, 2024
32c2a59
Fix normalizeFields and replace _source
jennypavlova Sep 27, 2024
2a67dc9
Service runtime name workaround
jennypavlova Sep 27, 2024
03a86d9
'dependency metadata' mappings
miloszmarcinkowski Sep 18, 2024
2e97e81
'dependency spans' mapping
miloszmarcinkowski Sep 18, 2024
a6244f5
`span` mappings
miloszmarcinkowski Sep 19, 2024
cb9f1d4
`span links` mappings
miloszmarcinkowski Sep 19, 2024
0b86fc2
replace field keys with TS constants
miloszmarcinkowski Sep 20, 2024
f54e2b3
'transaction' mapping
miloszmarcinkowski Sep 20, 2024
37dd831
'trace items' mappings
miloszmarcinkowski Sep 20, 2024
8e55406
'error group main statistics' mapping
miloszmarcinkowski Sep 20, 2024
0cabafb
'error sample details' mapping
miloszmarcinkowski Sep 20, 2024
f5e627c
'service metadata' mapping
miloszmarcinkowski Sep 20, 2024
c52ddfd
'metadata and service version' mappings
miloszmarcinkowski Sep 23, 2024
e77d9a4
'service agent name' mappings
miloszmarcinkowski Sep 23, 2024
f8f9b78
add fields to Span mapping
miloszmarcinkowski Sep 25, 2024
3eac633
remove unused properties in Span mapping
miloszmarcinkowski Sep 26, 2024
d467a38
improve name consistency in mapping functions
miloszmarcinkowski Sep 26, 2024
ac07c73
remove unused fields from 'service instance metadata details'
miloszmarcinkowski Sep 27, 2024
cef6b68
Update snapshots
jennypavlova Sep 27, 2024
2e26dc5
Merge branch 'main' into 192606-poc-otel-data-with-apm-ui-replacing-_…
jennypavlova Sep 27, 2024
8666c00
add check against undefined
miloszmarcinkowski Sep 27, 2024
8a66ac7
Fix metadata icon tooltips
jennypavlova Sep 27, 2024
5dbdbc4
Merge branch 'main' into 192606-poc-otel-data-with-apm-ui-replacing-_…
jennypavlova Sep 27, 2024
06545b5
added span-link normalization and fixed errors in getTransaction
bryce-b Sep 25, 2024
a08ef93
fix service metadata endpoints
bryce-b Sep 26, 2024
f156559
PR feedback fix
bryce-b Sep 27, 2024
e7da158
Make _source optional
jennypavlova Sep 27, 2024
45f6285
Error changes
jennypavlova Sep 27, 2024
0c6a4cb
Merge branch 'main' into 192606-poc-otel-data-with-apm-ui-replacing-_…
jennypavlova Sep 27, 2024
4372e43
Add comment for the error id issue
jennypavlova Sep 27, 2024
2ef8527
added mapping for metadata_details
bryce-b Sep 27, 2024
004f587
fixed kubernetes check in metadata mappings
bryce-b Sep 27, 2024
354d821
use one mapping for metadata details
miloszmarcinkowski Sep 30, 2024
aebea67
update 'todo' and processor_name typo
miloszmarcinkowski Sep 30, 2024
60e4870
Remove error fields changes
jennypavlova Sep 30, 2024
fe9be17
Merge branch 'main' into 192606-poc-otel-data-with-apm-ui-replacing-_…
jennypavlova Sep 30, 2024
3f99bae
Merge branch '192749-refactor-the-normalize-function-into-per-data-st…
miloszmarcinkowski Sep 30, 2024
b4c5a95
Merge pull request #2 from bryce-b/192749-refactor-the-normalize-func…
miloszmarcinkowski Sep 30, 2024
9d040cf
Merge remote-tracking branch 'jennypavlova/192606-poc-otel-data-with-…
miloszmarcinkowski Sep 30, 2024
e4fac40
add `container` mapping
miloszmarcinkowski Sep 30, 2024
634b899
Merge pull request #6 from miloszmarcinkowski/192749-refactor-the-nor…
jennypavlova Sep 30, 2024
9438e85
Merge branch 'main' into 192606-poc-otel-data-with-apm-ui-replacing-_…
jennypavlova Sep 30, 2024
850b331
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine Sep 30, 2024
12ad0a5
Merge branch 'main' into 192606-poc-otel-data-with-apm-ui-replacing-_…
jennypavlova Sep 30, 2024
9bcb917
Remove LABEL_SOME_RESOURCE_ATTRIBUTE
jennypavlova Sep 30, 2024
12dffee
getMetadataForDependency: Use SPAN_TYPE and SPAN_SUBTYPE instead of a…
jennypavlova Sep 30, 2024
8bcec36
Fix: Use span links mapping and fix undefined error
jennypavlova Sep 30, 2024
05acbbb
getServiceInstanceContainerMetadata: restrict fields to kubernetes
jennypavlova Sep 30, 2024
51b0f0b
getServiceInstanceMetadataDetails: restrict fields in the query
jennypavlova Sep 30, 2024
4d866bb
Restrict fields to the expected once in the transactionMapping
jennypavlova Sep 30, 2024
f9b8b23
Restrict fields for span and transaction
jennypavlova Sep 30, 2024
ba589cd
Update test snapshot to include the fields changes
jennypavlova Sep 30, 2024
e8362c3
Merge branch 'main' into 192606-poc-otel-data-with-apm-ui-replacing-_…
jennypavlova Sep 30, 2024
65a3580
Revert error changes
jennypavlova Oct 1, 2024
d11b7e4
Handle optional values
jennypavlova Oct 1, 2024
0a98a64
Extract mapping logic and share common parts
jennypavlova Oct 1, 2024
c7eeaa0
Revert entity endpoint change
jennypavlova Oct 1, 2024
3dd2acb
Replace and remove normalizeFields function
jennypavlova Oct 1, 2024
e5b99df
Set strict date to the fields test and update snapshot
jennypavlova Oct 1, 2024
cc592fb
Fix todos
jennypavlova Oct 1, 2024
d069d97
CR changed
jennypavlova Oct 1, 2024
fe06eb5
Merge branch 'main' into 192606-poc-otel-data-with-apm-ui-replacing-_…
jennypavlova Oct 1, 2024
cf86079
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine Oct 1, 2024
d4b4a83
Fix timestamp
jennypavlova Oct 2, 2024
8a27f0d
Merge branch '192606-poc-otel-data-with-apm-ui-replacing-_source-with…
jennypavlova Oct 2, 2024
95f2cf7
Use string for timestamp in the tests
jennypavlova Oct 2, 2024
7a34150
Fix getDownstreamServiceResource fields value
jennypavlova Oct 2, 2024
d7d4372
Revert errors to use source
jennypavlova Oct 2, 2024
f083497
Revert normalizeValue change
jennypavlova Oct 2, 2024
ec61907
Revert span links change
jennypavlova Oct 2, 2024
7142a51
CR and diskussions fixed
jennypavlova Oct 2, 2024
1a99043
Refactor mappers
jennypavlova Oct 2, 2024
630c6d0
Merge branch 'main' into 192606-poc-otel-data-with-apm-ui-replacing-_…
jennypavlova Oct 2, 2024
57338e1
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Oct 2, 2024
d543e39
Use SPAN_LINKS from _sources
crespocarlos Oct 3, 2024
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
29 changes: 29 additions & 0 deletions packages/kbn-apm-types/src/es_fields/apm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

export const TIMESTAMP = 'timestamp.us';
export const AT_TIMESTAMP = '@timestamp';
export const AGENT = 'agent';
export const AGENT_NAME = 'agent.name';
export const AGENT_VERSION = 'agent.version';
Expand All @@ -20,12 +21,18 @@ 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';

export const EVENT_SUCCESS_COUNT = 'event.success_count';
export const EVENT_SUCCESS_COUNT_SUM = 'event.success_count.sum';
export const EVENT_SUCCESS_COUNT_VALUE_COUNT = 'event.success_count.value_count';

export const SERVICE = 'service';
export const SERVICE_NAME = 'service.name';
Expand All @@ -39,18 +46,28 @@ export const SERVICE_RUNTIME_VERSION = 'service.runtime.version';
export const SERVICE_NODE_NAME = 'service.node.name';
export const SERVICE_VERSION = 'service.version';
export const SERVICE_TARGET_TYPE = 'service.target.type';
export const SERVICE_TARGET_NAME = 'service.target.name';
export const SERVICE_OVERFLOW_COUNT = 'service_transaction.aggregation.overflow_count';

export const URL_FULL = 'url.full';
export const HTTP_REQUEST_METHOD = 'http.request.method';
export const HTTP_RESPONSE_STATUS_CODE = 'http.response.status_code';

export const USER_ID = 'user.id';
export const USER_AGENT_ORIGINAL = 'user_agent.original';
export const USER_AGENT_NAME = 'user_agent.name';
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_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';

export const TRANSACTION_DURATION = 'transaction.duration.us';
export const TRANSACTION_DURATION_HISTOGRAM = 'transaction.duration.histogram';
Expand All @@ -67,6 +84,9 @@ 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 TRANSACTION_SPAN_COUNT_STARTED = 'transaction.span_count.started';

export const EVENT_OUTCOME = 'event.outcome';

Expand Down Expand Up @@ -95,6 +115,7 @@ export const SPAN_COMPOSITE_SUM = 'span.composite.sum.us';
export const SPAN_COMPOSITE_COMPRESSION_STRATEGY = 'span.composite.compression_strategy';

export const SPAN_SYNC = 'span.sync';
export const SPAN_REPRESENTATIVE_COUNT = 'span.representative_count';

// Parent ID for a transaction or span
export const PARENT_ID = 'parent.id';
Expand Down Expand Up @@ -145,14 +166,19 @@ export const HOST_NAME = 'host.name';
export const HOST_OS_PLATFORM = 'host.os.platform';
export const HOST_ARCHITECTURE = 'host.architecture';
export const HOST_OS_VERSION = 'host.os.version';
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';
export const KUBERNETES_POD_UID = 'kubernetes.pod.uid';
export const KUBERNETES_NAMESPACE = 'kubernetes.namespace';
export const KUBERNETES_NODE_NAME = 'kubernetes.node.name';

export const FAAS_ID = 'faas.id';
export const FAAS_NAME = 'faas.name';
Expand Down Expand Up @@ -180,6 +206,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';
Expand All @@ -194,6 +222,7 @@ export const CLIENT_GEO_REGION_ISO_CODE = 'client.geo.region_iso_code';
export const CLIENT_GEO_COUNTRY_NAME = 'client.geo.country_name';
export const CLIENT_GEO_CITY_NAME = 'client.geo.city_name';
export const CLIENT_GEO_REGION_NAME = 'client.geo.region_name';
export const CLIENT_IP = 'client.ip';

export const CHILD_ID = 'child.id';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ export interface ResponseHitSource {
[s: string]: unknown;
}

export interface ResponseHitFields {
[s: string]: unknown;
}

export interface ResponseHit {
_source: ResponseHitSource;
_source?: ResponseHitSource;
fields: ResponseHitFields;
}

export interface CommonCorrelationsQueryParams {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export function ErrorSampleDetails({
const status = error.http?.response?.status_code;
const environment = error.service.environment;
const serviceVersion = error.service.version;
const isUnhandled = error.error.exception?.[0].handled === false;
const isUnhandled = error.error.exception?.[0]?.handled === false;

const traceExplorerLink = router.link('/traces/explorer/waterfall', {
query: {
Expand Down Expand Up @@ -352,8 +352,8 @@ export function ErrorSampleDetailTabContent({
currentTab: ErrorTab;
}) {
const codeLanguage = error?.service.language?.name;
const exceptions = error?.error.exception || [];
const logStackframes = error?.error.log?.stacktrace;
const exceptions = error?.error?.exception || [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the first ? is not necessary - APMError is always defined (I understand these were here before, but let's not add to it)

const logStackframes = error?.error?.log?.stacktrace;
const isPlaintextException =
!!error?.error.stack_trace && exceptions.length === 1 && !exceptions[0].stacktrace;
switch (currentTab.key) {
Expand All @@ -362,8 +362,8 @@ export function ErrorSampleDetailTabContent({
case ErrorTabKey.ExceptionStacktrace:
return isPlaintextException ? (
<PlaintextStacktrace
message={exceptions[0].message}
type={exceptions[0].type}
message={exceptions[0]?.message}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not be necessary either, given the assertion on line 357 (isPlaintextException...)

type={exceptions[0]?.type}
stacktrace={error?.error.stack_trace}
codeLanguage={codeLanguage}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ function getErrorItem(
const errorItem: IWaterfallError = {
docType: 'error',
doc: error,
id: error.error.id,
// To be fixed after https://github.com/elastic/opentelemetry-lib/issues/86
id: error?.error?.id ?? '',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are these needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of the blocker here - the error id in the Otel PoC data is missing currently. I will update it once it is fixed and I added it to unblock the testing of the other parts

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I linked the issue in a comment

parent,
parentId: parent?.id,
offset: error.timestamp.us - entryTimestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function NameLabel({ item }: { item: IWaterfallSpanOrTransaction }) {
switch (item.docType) {
case 'span':
let name = item.doc.span.name;
if (item.doc.span.composite) {
if (item.doc.span.composite && item.doc.span.composite.count) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it matter that this returns false when count is 0? probably not, but might be good to be more specific here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was shown in the name so I had undefined in every span when I was testing - I don't think we should show 0 either but maybe what I faced was more of an edge case

const compositePrefix =
item.doc.span.composite.compression_strategy === 'exact_match' ? 'x' : '';
name = `${item.doc.span.composite.count}${compositePrefix} ${name}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ import {
SavedServiceGroup,
} from '../../../../common/service_groups';
import { asMutableArray } from '../../../../common/utils/as_mutable_array';
import { APMError } from '../../../../typings/es_schemas/ui/apm_error';
import { AgentName } from '../../../../typings/es_schemas/ui/fields/agent';
import { Span } from '../../../../typings/es_schemas/ui/span';
import { Transaction } from '../../../../typings/es_schemas/ui/transaction';
import {
APMDataTelemetry,
APMPerService,
Expand All @@ -74,6 +71,7 @@ import {
APM_CUSTOM_DASHBOARDS_SAVED_OBJECT_TYPE,
SavedApmCustomDashboard,
} from '../../../../common/custom_dashboards';
import { serviceVersionMapping } from '../../../utils/es_fields_mappings';

type ISavedObjectsClient = Pick<SavedObjectsClient, 'find'>;
const TIME_RANGES = ['1d', 'all'] as const;
Expand Down Expand Up @@ -690,10 +688,11 @@ export const tasks: TelemetryTask[] = [
sort: {
'@timestamp': 'desc',
},
fields: ['observer.version'],
},
});

const hit = response.hits.hits[0]?._source as Pick<Transaction | Span | APMError, 'observer'>;
const hit = serviceVersionMapping(response.hits.hits[0]?.fields);

if (!hit || !hit.observer?.version) {
return {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export async function getDownstreamServiceResource({
body: {
track_total_hits: false,
size: 1,
_source: ['span.destination.service'],
query: {
bool: {
filter: [
Expand All @@ -50,9 +49,10 @@ export async function getDownstreamServiceResource({
],
},
},
fields: ['span.destination.service'],
},
});

const hit = response.hits.hits[0];
return hit?._source?.span.destination?.service.resource;
return hit?.fields?.['span.destination?.service?.resource']?.[0] as string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question marks here in the string need to be removed and the type should be string | undefined presumably?

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
import { rangeQuery } from '@kbn/observability-plugin/server';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { maybe } from '../../../common/utils/maybe';
import { SPAN_DESTINATION_SERVICE_RESOURCE } from '../../../common/es_fields/apm';
import {
SPAN_DESTINATION_SERVICE_RESOURCE,
SPAN_SUBTYPE,
SPAN_TYPE,
} from '../../../common/es_fields/apm';
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client';
import { metadataForDependencyMapping } from '../../utils/es_fields_mappings';

export interface MetadataForDependencyResponse {
spanType: string | undefined;
Expand Down Expand Up @@ -46,16 +51,18 @@ export async function getMetadataForDependency({
],
},
},
fields: [SPAN_TYPE, SPAN_SUBTYPE],
sort: {
'@timestamp': 'desc',
},
},
});

const sample = maybe(sampleResponse.hits.hits[0])?._source;
const sample = maybe(sampleResponse.hits.hits[0])?.fields;
const sampleNorm = sample ? metadataForDependencyMapping(sample) : null;

return {
spanType: sample?.span.type,
spanSubtype: sample?.span.subtype,
spanType: sampleNorm?.span.type,
spanSubtype: sampleNorm?.span.subtype,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ import { environmentQuery } from '../../../common/utils/environment_query';
import { maybe } from '../../../common/utils/maybe';
import { AgentName } from '../../../typings/es_schemas/ui/fields/agent';
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client';
import {
topDependencySpansMapping,
transactionsForDependencySpansMapping,
} from '../../utils/es_fields_mappings';

const MAX_NUM_SPANS = 1000;

Expand Down Expand Up @@ -98,7 +102,7 @@ export async function getTopDependencySpans({
],
},
},
_source: [
fields: [
SPAN_ID,
TRACE_ID,
TRANSACTION_ID,
Expand All @@ -112,7 +116,7 @@ export async function getTopDependencySpans({
],
},
})
).hits.hits.map((hit) => hit._source);
).hits.hits.map((hit) => topDependencySpansMapping(hit?.fields));

const transactionIds = spans.map((span) => span.transaction!.id);

Expand All @@ -129,13 +133,13 @@ export async function getTopDependencySpans({
filter: [...termsQuery(TRANSACTION_ID, ...transactionIds)],
},
},
_source: [TRANSACTION_ID, TRANSACTION_TYPE, TRANSACTION_NAME],
fields: [TRANSACTION_ID, TRANSACTION_TYPE, TRANSACTION_NAME],
sort: {
'@timestamp': 'desc',
},
},
})
).hits.hits.map((hit) => hit._source);
).hits.hits.map((hit) => transactionsForDependencySpansMapping(hit.fields));

const transactionsById = keyBy(transactions, (transaction) => transaction.transaction.id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { environmentQuery } from '../../../common/utils/environment_query';
import { EntitiesESClient } from '../../lib/helpers/create_es_client/create_entities_es_client/create_entities_es_client';
import { entitiesRangeQuery } from './get_entities';
import { EntityLatestServiceRaw, EntityType } from './types';
import { normalizeFields } from '../../utils/normalize_fields';

export async function getEntityLatestServices({
entitiesESClient,
Expand All @@ -40,7 +41,7 @@ export async function getEntityLatestServices({
body: {
size,
track_total_hits: false,
_source: [AGENT_NAME, ENTITY, DATA_STEAM_TYPE, SERVICE_NAME, SERVICE_ENVIRONMENT],
fields: [AGENT_NAME, ENTITY, DATA_STEAM_TYPE, SERVICE_NAME, SERVICE_ENVIRONMENT],
query: {
bool: {
filter: [
Expand All @@ -54,7 +55,7 @@ export async function getEntityLatestServices({
},
},
})
).hits.hits.map((hit) => hit._source);
).hits.hits.map((hit) => normalizeFields(hit?.fields ?? {}) as unknown as EntityLatestServiceRaw);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to replace with an explicit mapping, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! It's on our list to replace this function everywhere. We discussed that with @miloszmarcinkowski and I am wondering if we want to have this change for the services that are coming from EEM - so the view is still in tech preview and idk if we want to have the changes there as this should not affect open telemetry "classic" view.
This is for the "new" view when this button is clicked:
image

Do we want to do this change there as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please. In fact, any new feature being developed in the UI should be from now on "OTel-native" (i.e. not using _source) from the beginning.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted the changes and it won't affect the services with Otel ( I see no errors when I enabled the new view )


return latestEntityServices;
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async function getTopErroneousTransactions({
sample: {
top_hits: {
size: 1,
_source: [TRANSACTION_TYPE],
fields: [TRANSACTION_TYPE],
},
},
timeseries: {
Expand All @@ -117,7 +117,9 @@ async function getTopErroneousTransactions({
({ key, doc_count: docCount, sample, timeseries }) => {
return {
transactionName: key as string,
transactionType: sample.hits.hits[0]._source.transaction?.type,
transactionType: sample.hits.hits[0].fields?.['transaction.type']?.[0] as
| string
| undefined,
occurrences: docCount,
timeseries: timeseries.buckets.map((timeseriesBucket) => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ export async function getErrorGroupSampleIds({
should: [{ term: { [TRANSACTION_SAMPLED]: true } }], // prefer error samples with related transactions
},
},
_source: [ERROR_ID, 'transaction'],
fields: [ERROR_ID, 'transaction'],
sort: asMutableArray([
{ _score: { order: 'desc' } }, // sort by _score first to ensure that errors with transaction.sampled:true ends up on top
{ '@timestamp': { order: 'desc' } }, // sort by timestamp to get the most recent error
] as const),
},
});
const errorSampleIds = resp.hits.hits.map((item) => {
const source = item._source;
return source.error.id;
const source = item?._source;
return source?.error?.id;
});

return {
Expand Down
Loading