Skip to content

Commit 1977322

Browse files
authored
Update telemetry string (#12)
Drop version metadata from telemetry string
1 parent 9de2b99 commit 1977322

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

src/client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ if (clientVersion.includes('-')) {
5656
// clean prerelease
5757
clientVersion = clientVersion.slice(0, clientVersion.indexOf('-')) + 'p'
5858
}
59+
const clientVersionNoMeta = clientVersion.split('+')[0]
5960
let transportVersion: string = require('@elastic/transport/package.json').version // eslint-disable-line
6061
/* istanbul ignore next */
6162
if (transportVersion.includes('-')) {
@@ -202,7 +203,7 @@ export default class Client extends API {
202203
}
203204

204205
if (options.enableMetaHeader) {
205-
options.headers['x-elastic-client-meta'] = `esv=${clientVersion},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion}`
206+
options.headers['x-elastic-client-meta'] = `esv=${clientVersionNoMeta},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion}`
206207
}
207208

208209
this.name = options.name
@@ -265,7 +266,7 @@ export default class Client extends API {
265266
this.helpers = new Helpers({
266267
client: this,
267268
metaHeader: options.enableMetaHeader
268-
? `esv=${clientVersion},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion}`
269+
? `esv=${clientVersionNoMeta},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion}`
269270
: null,
270271
maxRetries: options.maxRetries
271272
})

test/unit/client.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,10 @@ test('name as symbol', t => {
363363
test('Meta header enabled by default', async t => {
364364
t.plan(1)
365365

366+
const clientVersionNoMeta = clientVersion.split('+')[0]
366367
const Connection = connection.buildMockConnection({
367368
onRequest (opts) {
368-
t.match(opts.headers, { 'x-elastic-client-meta': `esv=${clientVersion},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion}` })
369+
t.match(opts.headers, { 'x-elastic-client-meta': `esv=${clientVersionNoMeta},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion}` })
369370
return {
370371
statusCode: 200,
371372
body: { hello: 'world' }

test/unit/helpers/bulk.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ let clientVersion: string = require('../../../package.json').version // eslint-d
3030
if (clientVersion.includes('-')) {
3131
clientVersion = clientVersion.slice(0, clientVersion.indexOf('-')) + 'p'
3232
}
33+
const clientVersionNoMeta = clientVersion.split('+')[0]
3334
let transportVersion: string = require('@elastic/transport/package.json').version // eslint-disable-line
3435
if (transportVersion.includes('-')) {
3536
transportVersion = transportVersion.slice(0, transportVersion.indexOf('-')) + 'p'
@@ -56,7 +57,7 @@ test('bulk index', t => {
5657
t.equal(params.path, '/_bulk')
5758
t.match(params.headers, {
5859
'content-type': 'application/vnd.elasticsearch+x-ndjson; compatible-with=8',
59-
'x-elastic-client-meta': `esv=${clientVersion},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion},h=bp`
60+
'x-elastic-client-meta': `esv=${clientVersionNoMeta},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion},h=bp`
6061
})
6162
// @ts-expect-error
6263
const [action, payload] = params.body.split('\n')
@@ -103,7 +104,7 @@ test('bulk index', t => {
103104
t.equal(params.path, '/_bulk')
104105
t.match(params.headers, { 'content-type': 'application/vnd.elasticsearch+x-ndjson; compatible-with=8' })
105106
t.notMatch(params.headers, {
106-
'x-elastic-client-meta': `esv=${clientVersion},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion},h=bp`
107+
'x-elastic-client-meta': `esv=${clientVersionNoMeta},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion},h=bp`
107108
})
108109
// @ts-expect-error
109110
const [action, payload] = params.body.split('\n')
@@ -1320,7 +1321,7 @@ test('Flush interval', t => {
13201321
t.equal(params.path, '/_bulk')
13211322
t.match(params.headers, {
13221323
'content-type': 'application/vnd.elasticsearch+x-ndjson; compatible-with=8',
1323-
'x-elastic-client-meta': `esv=${clientVersion},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion},h=bp`
1324+
'x-elastic-client-meta': `esv=${clientVersionNoMeta},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion},h=bp`
13241325
})
13251326
// @ts-expect-error
13261327
const [action, payload] = params.body.split('\n')

test/unit/helpers/scroll.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ let clientVersion: string = require('../../../package.json').version // eslint-d
2525
if (clientVersion.includes('-')) {
2626
clientVersion = clientVersion.slice(0, clientVersion.indexOf('-')) + 'p'
2727
}
28+
let clientVersionNoMeta = clientVersion.split('+')[0]
2829
let transportVersion: string = require('@elastic/transport/package.json').version // eslint-disable-line
2930
if (transportVersion.includes('-')) {
3031
transportVersion = transportVersion.slice(0, transportVersion.indexOf('-')) + 'p'
@@ -36,7 +37,7 @@ test('Scroll search', async t => {
3637
const MockConnection = connection.buildMockConnection({
3738
onRequest (params) {
3839
t.match(params.headers, {
39-
'x-elastic-client-meta': `esv=${clientVersion},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion},h=s`
40+
'x-elastic-client-meta': `esv=${clientVersionNoMeta},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion},h=s`
4041
})
4142

4243
count += 1
@@ -92,7 +93,7 @@ test('Clear a scroll search', async t => {
9293
const MockConnection = connection.buildMockConnection({
9394
onRequest (params) {
9495
t.notMatch(params.headers, {
95-
'x-elastic-client-meta': `esv=${clientVersion},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion},h=s`
96+
'x-elastic-client-meta': `esv=${clientVersionNoMeta},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion},h=s`
9697
})
9798
if (params.method === 'DELETE') {
9899
// @ts-expect-error

0 commit comments

Comments
 (0)