From c862beb0b1f36f9f6af51049613d40eadc3ebfff Mon Sep 17 00:00:00 2001 From: Josh Mock Date: Tue, 9 Dec 2025 12:20:04 -0600 Subject: [PATCH] Detect Deno and Bun usage --- src/client.ts | 5 +++++ test/unit/client.test.ts | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/client.ts b/src/client.ts index d8739e87d..ebaa69d41 100644 --- a/src/client.ts +++ b/src/client.ts @@ -314,6 +314,11 @@ export default class Client extends API { // assumes HttpConnection clientMeta += `,hc=${nodeVersion}` } + + // detect alternative runtimes + if (process.versions.bun != null) clientMeta += `,bn=${process.versions.bun}` + if (process.versions.deno != null) clientMeta += `,dn=${process.versions.deno}` + options.headers['x-elastic-client-meta'] = clientMeta } diff --git a/test/unit/client.test.ts b/test/unit/client.test.ts index ac8203f55..a3c4a6ead 100644 --- a/test/unit/client.test.ts +++ b/test/unit/client.test.ts @@ -493,6 +493,42 @@ test('Meta header indicates when HttpConnection is used', async t => { await client.transport.request({ method: 'GET', path: '/' }) }) +test('Meta header indicates when Bun is used', async t => { + t.plan(1) + + function handler(req: http.IncomingMessage, res: http.ServerResponse) { + t.equal(req.headers['x-elastic-client-meta'], `es=${clientVersion},js=${nodeVersion},t=${transportVersion},un=${nodeVersion},bn=1.2.3`) + res.end('ok') + } + + const [{ port }, server] = await buildServer(handler) + t.after(() => server.stop()) + + process.versions.bun = "1.2.3" + const client = new Client({ node: `http://localhost:${port}` }) + delete process.versions.bun + + await client.transport.request({ method: 'GET', path: '/' }) +}) + +test('Meta header indicates when Deno is used', async t => { + t.plan(1) + + function handler(req: http.IncomingMessage, res: http.ServerResponse) { + t.equal(req.headers['x-elastic-client-meta'], `es=${clientVersion},js=${nodeVersion},t=${transportVersion},un=${nodeVersion},dn=1.2.3`) + res.end('ok') + } + + const [{ port }, server] = await buildServer(handler) + t.after(() => server.stop()) + + process.versions.deno = "1.2.3" + const client = new Client({ node: `http://localhost:${port}` }) + delete process.versions.deno + + await client.transport.request({ method: 'GET', path: '/' }) +}) + test('caFingerprint', t => { const client = new Client({ node: 'https://localhost:9200',