Skip to content

Commit

Permalink
Fix error object handling
Browse files Browse the repository at this point in the history
  • Loading branch information
crespocarlos committed Oct 11, 2024
1 parent 1d4ebae commit 06ec4ef
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import { AggregationsAggregateOrder } from '@elastic/elasticsearch/lib/api/types';
import { kqlQuery, rangeQuery, termQuery, wildcardQuery } from '@kbn/observability-plugin/server';
import { unflattenKnownApmEventFields } from '@kbn/apm-data-access-plugin/server/utils';
import { castArray } from 'lodash';
import { asMutableArray } from '../../../../common/utils/as_mutable_array';
import {
AT_TIMESTAMP,
Expand Down Expand Up @@ -180,11 +179,10 @@ export async function getErrorGroupMainStatistics({
...event,
error: {
...(event.error ?? {}),
exception: castArray(
errorSource?.error.exception && errorSource?.error.exception?.length > 1
exception:
(errorSource?.error.exception?.length ?? 0) > 1
? errorSource?.error.exception
: event?.error.exception
),
: event?.error.exception && [event.error.exception],
},
};

Expand All @@ -194,8 +192,8 @@ export async function getErrorGroupMainStatistics({
lastSeen: new Date(mergedEvent[AT_TIMESTAMP]).getTime(),
occurrences: bucket.doc_count,
culprit: mergedEvent.error.culprit,
handled: mergedEvent.error.exception[0].handled,
type: mergedEvent.error.exception[0].type,
handled: mergedEvent.error.exception?.[0].handled,
type: mergedEvent.error.exception?.[0].type,
traceId: mergedEvent.trace?.id,
};
}) ?? [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import { AggregationsAggregateOrder } from '@elastic/elasticsearch/lib/api/types';
import { kqlQuery, rangeQuery, termQuery } from '@kbn/observability-plugin/server';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { castArray } from 'lodash';
import { unflattenKnownApmEventFields } from '@kbn/apm-data-access-plugin/server/utils';
import { asMutableArray } from '../../../../../common/utils/as_mutable_array';
import {
Expand Down Expand Up @@ -142,11 +141,10 @@ export async function getMobileCrashGroupMainStatistics({
...event,
error: {
...(event.error ?? {}),
exception: castArray(
errorSource?.error.exception && errorSource?.error.exception?.length > 1
exception:
(errorSource?.error.exception?.length ?? 0) > 1
? errorSource?.error.exception
: event?.error.exception
),
: event?.error.exception && [event.error.exception],
},
};

Expand All @@ -156,8 +154,8 @@ export async function getMobileCrashGroupMainStatistics({
lastSeen: new Date(mergedEvent[AT_TIMESTAMP]).getTime(),
occurrences: bucket.doc_count,
culprit: mergedEvent.error.culprit,
handled: mergedEvent.error.exception[0].handled,
type: mergedEvent.error.exception[0].type,
handled: mergedEvent.error.exception?.[0].handled,
type: mergedEvent.error.exception?.[0].type,
};
}) ?? []
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { 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 { castArray } from 'lodash';
import { asMutableArray } from '../../../../common/utils/as_mutable_array';
import {
AT_TIMESTAMP,
Expand Down Expand Up @@ -143,11 +142,10 @@ export async function getMobileErrorGroupMainStatistics({
...event,
error: {
...(event.error ?? {}),
exception: castArray(
errorSource?.error.exception && errorSource?.error.exception?.length > 1
exception:
(errorSource?.error.exception?.length ?? 0) > 1
? errorSource?.error.exception
: event?.error.exception
),
: event?.error.exception && [event.error.exception],
},
};

Expand All @@ -157,8 +155,8 @@ export async function getMobileErrorGroupMainStatistics({
lastSeen: new Date(mergedEvent[AT_TIMESTAMP]).getTime(),
occurrences: bucket.doc_count,
culprit: mergedEvent.error.culprit,
handled: mergedEvent.error.exception[0].handled,
type: mergedEvent.error.exception[0].type,
handled: mergedEvent.error.exception?.[0].handled,
type: mergedEvent.error.exception?.[0].type,
};
}) ?? []
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { SortResults } from '@elastic/elasticsearch/lib/api/types';
import { QueryDslQueryContainer, Sort } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { rangeQuery } from '@kbn/observability-plugin/server';
import { castArray, last, omit } from 'lodash';
import { last, omit } from 'lodash';
import { unflattenKnownApmEventFields } from '@kbn/apm-data-access-plugin/server/utils';
import { asMutableArray } from '../../../common/utils/as_mutable_array';
import { APMConfig } from '../..';
Expand Down Expand Up @@ -161,11 +161,10 @@ export async function getTraceItems({
...event,
error: {
...(event.error ?? {}),
exception: castArray(
errorSource?.error.exception && errorSource?.error.exception?.length > 1
exception:
(errorSource?.error.exception?.length ?? 0) > 1
? errorSource?.error.exception
: event?.error.exception
),
: event?.error.exception && [event.error.exception],
log: errorSource?.error.log,
},
};
Expand Down

0 comments on commit 06ec4ef

Please sign in to comment.