elastic / elastic/apm-agent-nodejs

improve ES instrumentation to have a span with outcome="failure" for a ProductNotSupportedError or RequestAbortedError

Open
#2,297 0 comments 0 reactions 0 assignees View on GitHub
agent-nodejs
Dominant language
JavaScript
Stars
594
Forks
244
Avg merge
1d 8h
Merged PRs (30d)
16

Description

In `@elastic/elasticsearch@7.14.0` the ES client changed to include a pre-check request to "GET /". This (after https://github.com/elastic/elasticsearch-js/pull/1531 is merged) will result in an `err` argument passed to the "request" [ES client observability event](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/observability.html) that is used by the APM agent's instrumentation of the ES client.

Similarly, if one aborts an ES client request during this pre-check request, then (at least after https://github.com/elastic/elasticsearch-js/pull/1534 is merged, hopefully for v7.14.1 and later) the "request" event will include an `err` argument (a `RequestAbortedError` instance):

```js
const req = esClient.search(...)
setImmediate(function () {
req.abort()
})
```

While the current APM instrumentation will capture an error for these cases, **the problem** is that the error will be a child of the `Elasticsearch: GET /` pre-check request and that request is *successful* (`outcome: "success"`). There is no span created for the `Elasticsearch: POST /_search` attempted request that never actually started. Overall, the only span reported is `outcome: "success"` and that is misleading.

One solution idea is to create (and almost immediately end) a span for the intended ES request (e.g. `POST /_search` for a search), then capture the error as a child of that span, which will result in a span with `outcome: "failure"`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.