X-Opaque-Id support

edit

To improve the overall observability, the client offers an easy way to configure the X-Opaque-Id header. If you set the X-Opaque-Id in a specific request, this will allow you to discover this identifier in the deprecation logs, help you with identifying search slow log origin as well as identifying running tasks.

The X-Opaque-Id should be configured in each request, for doing that you can use the opaqueId option, as you can see in the following example.
The resulting header will be { 'X-Opaque-Id': 'my-search' }.

const { Client } = require('@elastic/elasticsearch')
const client = new Client({
  node: 'http://localhost:9200'
})

client.search({
  index: 'my-index',
  body: { foo: 'bar' }
}, {
  opaqueId: 'my-search'
}, (err, result) => {
  if (err) console.log(err)
})

Sometimes it may be useful to prefix all the X-Opaque-Id headers with a specific string, in case you need to identify a specific client or server. For doing this, the client offers a top-level configuration option: opaqueIdPrefix.
In the following example, the resulting header will be { 'X-Opaque-Id': 'proxy-client::my-search' }.

const { Client } = require('@elastic/elasticsearch')
const client = new Client({
  node: 'http://localhost:9200',
  opaqueIdPrefix: 'proxy-client::'
})

client.search({
  index: 'my-index',
  body: { foo: 'bar' }
}, {
  opaqueId: 'my-search'
}, (err, result) => {
  if (err) console.log(err)
})