From 99883c25439434f26c4f2eb437681897097cfcb2 Mon Sep 17 00:00:00 2001 From: Naama Bendalak <74866605+8naama@users.noreply.github.com> Date: Mon, 10 Jun 2024 15:19:25 +0300 Subject: [PATCH] 2.1.8 * make user-agent not optional --- README.md | 4 +++- lib/logzio-nodejs.d.ts | 1 - lib/logzio-nodejs.js | 6 ++---- package.json | 2 +- test/logger.test.js | 8 ++++---- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index dbc173c..4f9ad4b 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,6 @@ logger.log(obj); * **addTimestampWithNanoSecs** - Add a timestamp with nano seconds granularity. This is needed when many logs are sent in the same millisecond, so you can properly order the logs in kibana. The added timestamp field will be `@timestamp_nano` Default: `false` * **compress** - If true the the logs are compressed in gzip format. Default: `false` * **internalLogger** - set internal logger that supports the function log. Default: console. -* **setUserAgent** - Set `false` to send logs without user-agent field in request header. Default:`true`. * **extraFields** - Adds your own custom fields to each log. Add in JSON Format, for example: `extraFields : { field_1: "val_1", field_2: "val_2" , ... }`. @@ -62,6 +61,9 @@ A few notes are worth mentioning regarding the use of the UDP protocol: ## Update log +**2.1.8** +- Make `User-Agent` not optional and add the version to it. + **2.1.7** - upgrade `axios` to `v1.6.4` (contributed by @gcagle3) diff --git a/lib/logzio-nodejs.d.ts b/lib/logzio-nodejs.d.ts index 4cbd459..9c8b8a4 100644 --- a/lib/logzio-nodejs.d.ts +++ b/lib/logzio-nodejs.d.ts @@ -11,7 +11,6 @@ interface ILoggerOptions { compress?: boolean; internalLogger?: { log(message: string, ...args: any[]): any } & Record; protocol?: string; - setUserAgent?: boolean; port?: string; timeout?: number; sleepUntilNextRetry?: number; diff --git a/lib/logzio-nodejs.js b/lib/logzio-nodejs.js index 5da05f0..5cce963 100755 --- a/lib/logzio-nodejs.js +++ b/lib/logzio-nodejs.js @@ -35,7 +35,7 @@ const protocolToPortMap = { https: 8071, }; -const USER_AGENT = 'Logzio-Logger NodeJS'; +const prop = require('../package.json'); class LogzioLogger { constructor({ @@ -55,7 +55,6 @@ class LogzioLogger { timeout, sleepUntilNextRetry = 2 * 1000, callback = this._defaultCallback, - setUserAgent = true, extraFields = {}, }) { if (!token) { @@ -74,7 +73,6 @@ class LogzioLogger { this.compress = compress; this.internalLogger = internalLogger; this.sleepUntilNextRetry = sleepUntilNextRetry; - this.setUserAgent = setUserAgent; this.timer = null; this.closed = false; @@ -87,7 +85,7 @@ class LogzioLogger { Host: this.host, Accept: '*/*', 'Content-Type': 'text/plain', - ...(this.setUserAgent ? { 'user-agent': USER_AGENT } : {}), + 'user-agent': `NodeJS/${prop.version} logs`, ...(this.compress ? { 'content-encoding': 'gzip' } : {}), }; diff --git a/package.json b/package.json index 1faae9b..bf35039 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "logzio-nodejs", "description": "A nodejs implementation for sending logs to Logz.IO cloud service Copy of logzio-nodejs", - "version": "2.1.7", + "version": "2.1.8", "author": "Gilly Barr ", "maintainers": [ { diff --git a/test/logger.test.js b/test/logger.test.js index 9844497..1a3b2b0 100644 --- a/test/logger.test.js +++ b/test/logger.test.js @@ -7,6 +7,7 @@ const zlib = require('zlib'); const logzioLogger = require('../lib/logzio-nodejs.js'); const hrtimemock = require('hrtimemock'); const axiosInstance = require('../lib/axiosInstance.js'); +const prop = require('../package.json'); axiosInstance.defaults.adapter = 'http'; @@ -61,11 +62,10 @@ describe('logger', () => { logger.close(); }); - it('sends log without user-agent header', (done) => { + it('sends log with user-agent header', (done) => { const logger = createLogger({ bufferSize: 1, - callback: onDone, - setUserAgent:false + callback: onDone }); sinon.spy(logger, '_tryToSend'); @@ -73,7 +73,7 @@ describe('logger', () => { logger.log(logMsg); function onDone() { - assert.equal(axiosInstance.defaults.headers.common['user-agent'], undefined); + assert.equal(axiosInstance.defaults.headers.post['user-agent'], `NodeJS/${prop.version} logs`); logger._tryToSend.restore(); logger.close(); done();