[Backport 7.x] Always display request params and options in request event (#1538)

Co-authored-by: Tomas Della Vedova <delvedor@users.noreply.github.com>
This commit is contained in:
github-actions[bot]
2021-08-24 11:27:59 +02:00
committed by GitHub
parent ee867daad0
commit 642b15cd5c
2 changed files with 40 additions and 2 deletions

View File

@ -420,8 +420,6 @@ class Transport {
// handles request timeout // handles request timeout
params.timeout = toMs(options.requestTimeout || this.requestTimeout) params.timeout = toMs(options.requestTimeout || this.requestTimeout)
if (options.asStream === true) params.asStream = true if (options.asStream === true) params.asStream = true
meta.request.params = params
meta.request.options = options
// handle compression // handle compression
if (params.body !== '' && params.body != null) { if (params.body !== '' && params.body != null) {
@ -452,6 +450,8 @@ class Transport {
} }
} }
meta.request.params = params
meta.request.options = options
// still need to check the product or waiting for the check to finish // still need to check the product or waiting for the check to finish
if (this[kProductCheck] === 0 || this[kProductCheck] === 1) { if (this[kProductCheck] === 0 || this[kProductCheck] === 1) {
// let pass info requests // let pass info requests

View File

@ -1247,3 +1247,41 @@ test('No multiple checks with child clients', t => {
}) })
}, 100) }, 100)
}) })
test('Observability events should have all the expected properties', t => {
t.plan(5)
const MockConnection = buildMockConnection({
onRequest (params) {
return {
statusCode: 200,
body: {
name: '1ef419078577',
cluster_name: 'docker-cluster',
cluster_uuid: 'cQ5pAMvRRTyEzObH4L5mTA',
tagline: 'You Know, for Search'
}
}
}
})
const client = new Client({
node: 'http://localhost:9200',
Connection: MockConnection
})
client.on('request', (e, event) => {
t.ok(event.meta.request.params)
t.ok(event.meta.request.options)
})
client.search({
index: 'foo',
body: {
query: {
match_all: {}
}
}
}, (err, result) => {
t.equal(err.message, 'The client noticed that the server is not Elasticsearch and we do not support this unknown product.')
})
})