[8.7] [APM] Improve stack traces for internal server side errors (#151429) (#152066)

# Backport

This will backport the following commits from `main` to `8.7`:
- [[APM] Improve stack traces for internal server side errors
(#151429)](https://github.com/elastic/kibana/pull/151429)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Søren
Louv-Jansen","email":"soren.louv@elastic.co"},"sourceCommit":{"committedDate":"2023-02-24T08:42:30Z","message":"[APM]
Improve stack traces for internal server side errors
(#151429)","sha":"2bd82afe7a55a209ba902e8e3f8f8786035a252f","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:APM","release_note:skip","v8.7.0","v8.8.0","apm:instrumentation"],"number":151429,"url":"https://github.com/elastic/kibana/pull/151429","mergeCommit":{"message":"[APM]
Improve stack traces for internal server side errors
(#151429)","sha":"2bd82afe7a55a209ba902e8e3f8f8786035a252f"}},"sourceBranch":"main","suggestedTargetBranches":["8.7"],"targetPullRequestStates":[{"branch":"8.7","label":"v8.7.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/151429","number":151429,"mergeCommit":{"message":"[APM]
Improve stack traces for internal server side errors
(#151429)","sha":"2bd82afe7a55a209ba902e8e3f8f8786035a252f"}}]}]
BACKPORT-->

Co-authored-by: Søren Louv-Jansen <soren.louv@elastic.co>
This commit is contained in:
Kibana Machine 2023-02-24 04:51:20 -05:00 committed by GitHub
parent 25f432e627
commit 708e6056f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,6 +19,7 @@ import {
} from '@kbn/server-route-repository';
import { jsonRt, mergeRt } from '@kbn/io-ts-utils';
import { InspectResponse } from '@kbn/observability-plugin/typings/common';
import apm from 'elastic-apm-node';
import { pickKeys } from '../../../common/utils/pick_keys';
import { APMRouteHandlerResources, TelemetryUsageCounter } from '../typings';
import type { ApmPluginRequestHandlerContext } from '../typings';
@ -181,6 +182,9 @@ export function registerRoutes({
opts.statusCode = error.output.statusCode;
}
// capture error with APM node agent
apm.captureError(error);
return response.custom(opts);
} finally {
// cleanup