Always display request params and options in request event (#1531)

This commit is contained in:
Tomas Della Vedova
2021-08-24 11:25:48 +02:00
committed by GitHub
parent a9b62049cd
commit a7658b2a66
2 changed files with 40 additions and 2 deletions

View File

@ -420,8 +420,6 @@ class Transport {
// handles request timeout
params.timeout = toMs(options.requestTimeout || this.requestTimeout)
if (options.asStream === true) params.asStream = true
meta.request.params = params
meta.request.options = options
// handle compression
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
if (this[kProductCheck] === 0 || this[kProductCheck] === 1) {
// let pass info requests

View File

@ -1247,3 +1247,41 @@ test('No multiple checks with child clients', t => {
})
}, 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.')
})
})