elastic / elastic/apm-agent-nodejs
`error.context.{request,response}` for `@elastic/elasticsearch` instrumentation should use the current req/res
- Dominant language
- JavaScript
- Stars
- 594
- Forks
- 244
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 16
Description
In the `@elastic/elasticsearch` instrumentation the APM error captured for an error on the 'response' event is setting `error.context.{request,response}` using the **current transaction's `.req` and `.res`, if any** (which is a fallback in `agent.captureError()`) rather than using the req/res objects for this Elasticsearch client request.
This ends up being very misleading in APM UI. For example, this shows an error in the Kibana APM UI (this is instrumentation of Kibana itself, which is why the transaction is for a request to "https://kibana..."). Because the `error.context` uses the top-level *transaction req/res*, the error summary shows a request with a "200 OK".

In this case, actually finding the parent ES and HTTP spans shows a "500" status code.
Contributor guide
Assessment
This issue has not been assessed yet.