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 @@ -8,7 +8,7 @@
import type { AggregationsAggregateOrder } from '@elastic/elasticsearch/lib/api/types';
import { kqlQuery, rangeQuery, termQuery } from '@kbn/observability-plugin/server';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { unflattenKnownApmEventFields } from '@kbn/apm-data-access-plugin/server/utils';
import { accessKnownApmEventFields } from '@kbn/apm-data-access-plugin/server/utils';
import { asMutableArray } from '../../../../../common/utils/as_mutable_array';
import {
ERROR_CULPRIT,
Expand All @@ -24,8 +24,8 @@ import {
AT_TIMESTAMP,
} from '../../../../../common/es_fields/apm';
import { environmentQuery } from '../../../../../common/utils/environment_query';
import { getErrorName } from '../../../../lib/helpers/get_error_name';
import type { APMEventClient } from '../../../../lib/helpers/create_es_client/create_apm_event_client';
import { NOT_AVAILABLE_LABEL } from '../../../../../common/i18n';

export type MobileCrashGroupMainStatisticsResponse = Array<{
groupId: string;
Expand Down Expand Up @@ -133,27 +133,25 @@ export async function getMobileCrashGroupMainStatistics({
? bucket.sample.hits.hits[0]._source
: undefined;

const event = unflattenKnownApmEventFields(bucket.sample.hits.hits[0].fields, requiredFields);
const fields = bucket.sample.hits.hits[0].fields;
const event = accessKnownApmEventFields(fields).requireFields(requiredFields);

const mergedEvent = {
...event,
error: {
...(event.error ?? {}),
exception:
(errorSource?.error.exception?.length ?? 0) > 0
? errorSource?.error.exception
: event?.error.exception && [event.error.exception],
},
const exception = errorSource?.error.exception?.[0] ?? {
message: event[ERROR_EXC_MESSAGE],
handled: event[ERROR_EXC_HANDLED],
type: event[ERROR_EXC_TYPE],
};

const errorName = event[ERROR_LOG_MESSAGE] || exception.message || NOT_AVAILABLE_LABEL;
Copy link
Contributor

Choose a reason for hiding this comment

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

I've seen this in another PR. Maybe we should change the getErrorName after all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll do a follow-up PR after to rework getErrorName and use it in all the cases where it was removed for the new approach


return {
groupId: event.error?.grouping_key,
name: getErrorName(mergedEvent),
lastSeen: new Date(mergedEvent[AT_TIMESTAMP]).getTime(),
groupId: event[ERROR_GROUP_ID],
name: errorName,
lastSeen: new Date(event[AT_TIMESTAMP]).getTime(),
occurrences: bucket.doc_count,
culprit: mergedEvent.error.culprit,
handled: mergedEvent.error.exception?.[0].handled,
type: mergedEvent.error.exception?.[0].type,
culprit: event[ERROR_CULPRIT],
handled: exception.handled,
type: exception.type,
};
}) ?? []
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import type { AggregationsAggregateOrder } from '@elastic/elasticsearch/lib/api/types';
import { kqlQuery, rangeQuery, termQuery } from '@kbn/observability-plugin/server';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { unflattenKnownApmEventFields } from '@kbn/apm-data-access-plugin/server/utils';
import { accessKnownApmEventFields } from '@kbn/apm-data-access-plugin/server/utils';
import { asMutableArray } from '../../../../common/utils/as_mutable_array';
import {
AT_TIMESTAMP,
Expand All @@ -23,8 +23,8 @@ import {
TRANSACTION_TYPE,
} from '../../../../common/es_fields/apm';
import { environmentQuery } from '../../../../common/utils/environment_query';
import { getErrorName } from '../../../lib/helpers/get_error_name';
import type { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client';
import { NOT_AVAILABLE_LABEL } from '../../../../common/i18n';

export type MobileErrorGroupMainStatisticsResponse = Array<{
groupId: string;
Expand Down Expand Up @@ -134,27 +134,26 @@ export async function getMobileErrorGroupMainStatistics({
? bucket.sample.hits.hits[0]._source
: undefined;

const event = unflattenKnownApmEventFields(bucket.sample.hits.hits[0].fields, requiredFields);
const event = accessKnownApmEventFields(bucket.sample.hits.hits[0].fields).requireFields(
requiredFields
);

const mergedEvent = {
...event,
error: {
...(event.error ?? {}),
exception:
(errorSource?.error.exception?.length ?? 0) > 0
? errorSource?.error.exception
: event?.error.exception && [event.error.exception],
},
const exception = errorSource?.error.exception?.[0] ?? {
message: event[ERROR_EXC_MESSAGE],
handled: event[ERROR_EXC_HANDLED],
type: event[ERROR_EXC_TYPE],
};

const errorName = event[ERROR_LOG_MESSAGE] || exception.message || NOT_AVAILABLE_LABEL;

return {
groupId: event.error?.grouping_key,
name: getErrorName(mergedEvent),
lastSeen: new Date(mergedEvent[AT_TIMESTAMP]).getTime(),
groupId: event[ERROR_GROUP_ID],
name: errorName,
lastSeen: new Date(event[AT_TIMESTAMP]).getTime(),
occurrences: bucket.doc_count,
culprit: mergedEvent.error.culprit,
handled: mergedEvent.error.exception?.[0].handled,
type: mergedEvent.error.exception?.[0].type,
culprit: event[ERROR_CULPRIT],
handled: exception.handled,
type: exception.type,
};
}) ?? []
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
*/
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { rangeQuery, termQuery, kqlQuery } from '@kbn/observability-plugin/server';
import { isEmpty } from 'lodash';
import { unflattenKnownApmEventFields } from '@kbn/apm-data-access-plugin/server/utils';
import { accessKnownApmEventFields } from '@kbn/apm-data-access-plugin/server/utils';
import {
ELASTIC_PROFILER_STACK_TRACE_IDS,
SERVICE_NAME,
Expand All @@ -17,6 +16,7 @@ import {
} from '../../../common/es_fields/apm';
import { environmentQuery } from '../../../common/utils/environment_query';
import type { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client';
import { maybe } from '../../../common/utils/maybe';

export async function getStacktracesIdsField({
apmEventClient,
Expand Down Expand Up @@ -64,11 +64,15 @@ export async function getStacktracesIdsField({
},
});

const field = unflattenKnownApmEventFields(response.hits.hits[0]?.fields, [
ELASTIC_PROFILER_STACK_TRACE_IDS,
]);
const fields = maybe(response.hits.hits[0])?.fields;

if (!isEmpty(field.elastic.profiler_stack_trace_ids)) {
const field =
fields &&
accessKnownApmEventFields(fields).requireFields([ELASTIC_PROFILER_STACK_TRACE_IDS])[
ELASTIC_PROFILER_STACK_TRACE_IDS
];

if (field?.length) {
return ELASTIC_PROFILER_STACK_TRACE_IDS;
}

Expand Down