diff --git a/README.md b/README.md index 1becc75..40cb63a 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ If you do not have a [Logz.io](http://logz.io) account, you can sign up for a fr - **callback** - A callback function called when an unrecoverable error has occured in the logger. The function API is: function(err) - err being the Error object. - **timeout** - The read/write/connection timeout in milliseconds. - **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` +- **addOtelContext** - Add `trace_id`, `span_id`, `service_name` fields to logs when opentelemetry context is available. Default: `true` - **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 to `false` to send logs without the user-agent field in the request header. Default:`true`. If you want to send data from Firefox browser, set that option to `false`. @@ -164,6 +165,29 @@ tsc --project tsconfig.json +## Add opentelemetry context +If you're sending traces with OpenTelemetry instrumentation (auto or manual), you can correlate your logs with the trace context. That way, your logs will have traces data in it, such as service name, span id and trace id (version >= `5.2.0`). + +This feature is enabled by default, To disable it, set the `AddOtelContext` param in your handler configuration to `false`, like in this example: + +```javascript +const winston = require('winston'); +const LogzioWinstonTransport = require('winston-logzio'); + +const logzioWinstonTransport = new LogzioWinstonTransport({ + level: 'info', + name: 'winston_logzio', + token: '<>', + host: '<>', + addOtelCotext: false, +}); + +const logger = winston.createLogger({ + format: winston.format.simple(), + transports: [logzioWinstonTransport], +}); +``` + ## Build and test locally 1. Clone the repository: ```bash diff --git a/package-lock.json b/package-lock.json index 2658591..1bc52e0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,18 @@ { "name": "winston-logzio", - "version": "5.1.9", + "version": "5.2.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "winston-logzio", - "version": "5.1.9", + "version": "5.2.0", "license": "(Apache-2.0)", "dependencies": { "@types/node": "^14.0.4", "json-stringify-safe": "5.0.1", "lodash.assign": "4.2.0", - "logzio-nodejs": "^2.1.7", + "logzio-nodejs": "^2.2.0", "triple-beam": "^1.3.0", "winston": "^3.8.2", "winston-transport": "^4.5.0" @@ -67,6 +67,146 @@ "kuler": "^2.0.0" } }, + "node_modules/@opentelemetry/api": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.9.0.tgz", + "integrity": "sha512-3giAOQvZiH5F9bMlMiv8+GSPMeqg0dbaeo58/0SlA9sxSqZhnUtxzX9/2FzyhS9sWQf5S0GJE0AKBrFqjpeYcg==", + "license": "Apache-2.0", + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/@opentelemetry/context-async-hooks": { + "version": "1.30.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/context-async-hooks/-/context-async-hooks-1.30.0.tgz", + "integrity": "sha512-roCetrG/cz0r/gugQm/jFo75UxblVvHaNSRoR0kSSRSzXFAiIBqFCZuH458BHBNRtRe+0yJdIJ21L9t94bw7+g==", + "license": "Apache-2.0", + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": ">=1.0.0 <1.10.0" + } + }, + "node_modules/@opentelemetry/core": { + "version": "1.30.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/core/-/core-1.30.0.tgz", + "integrity": "sha512-Q/3u/K73KUjTCnFUP97ZY+pBjQ1kPEgjOfXj/bJl8zW7GbXdkw6cwuyZk6ZTXkVgCBsYRYUzx4fvYK1jxdb9MA==", + "license": "Apache-2.0", + "dependencies": { + "@opentelemetry/semantic-conventions": "1.28.0" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": ">=1.0.0 <1.10.0" + } + }, + "node_modules/@opentelemetry/propagator-b3": { + "version": "1.30.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/propagator-b3/-/propagator-b3-1.30.0.tgz", + "integrity": "sha512-lcobQQmd+hLdtxJJKu/i51lNXmF1PJJ7Y9B97ciHRVQuMI260vSZG7Uf4Zg0fqR8PB+fT/7rnlDwS0M7QldZQQ==", + "license": "Apache-2.0", + "dependencies": { + "@opentelemetry/core": "1.30.0" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": ">=1.0.0 <1.10.0" + } + }, + "node_modules/@opentelemetry/propagator-jaeger": { + "version": "1.30.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/propagator-jaeger/-/propagator-jaeger-1.30.0.tgz", + "integrity": "sha512-0hdP495V6HPRkVpowt54+Swn5NdesMIRof+rlp0mbnuIUOM986uF+eNxnPo9q5MmJegVBRTxgMHXXwvnXRnKRg==", + "license": "Apache-2.0", + "dependencies": { + "@opentelemetry/core": "1.30.0" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": ">=1.0.0 <1.10.0" + } + }, + "node_modules/@opentelemetry/resources": { + "version": "1.30.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/resources/-/resources-1.30.0.tgz", + "integrity": "sha512-5mGMjL0Uld/99t7/pcd7CuVtJbkARckLVuiOX84nO8RtLtIz0/J6EOHM2TGvPZ6F4K+XjUq13gMx14w80SVCQg==", + "license": "Apache-2.0", + "dependencies": { + "@opentelemetry/core": "1.30.0", + "@opentelemetry/semantic-conventions": "1.28.0" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": ">=1.0.0 <1.10.0" + } + }, + "node_modules/@opentelemetry/sdk-trace-base": { + "version": "1.30.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/sdk-trace-base/-/sdk-trace-base-1.30.0.tgz", + "integrity": "sha512-RKQDaDIkV7PwizmHw+rE/FgfB2a6MBx+AEVVlAHXRG1YYxLiBpPX2KhmoB99R5vA4b72iJrjle68NDWnbrE9Dg==", + "license": "Apache-2.0", + "dependencies": { + "@opentelemetry/core": "1.30.0", + "@opentelemetry/resources": "1.30.0", + "@opentelemetry/semantic-conventions": "1.28.0" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": ">=1.0.0 <1.10.0" + } + }, + "node_modules/@opentelemetry/sdk-trace-node": { + "version": "1.30.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/sdk-trace-node/-/sdk-trace-node-1.30.0.tgz", + "integrity": "sha512-MeXkXEdBs9xq1JSGTr/3P1lHBSUBaVmo1+UpoQhUpviPMzDXy0MNsdTC7KKI6/YcG74lTX6eqeNjlC1jV4Rstw==", + "license": "Apache-2.0", + "dependencies": { + "@opentelemetry/context-async-hooks": "1.30.0", + "@opentelemetry/core": "1.30.0", + "@opentelemetry/propagator-b3": "1.30.0", + "@opentelemetry/propagator-jaeger": "1.30.0", + "@opentelemetry/sdk-trace-base": "1.30.0", + "semver": "^7.5.2" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@opentelemetry/api": ">=1.0.0 <1.10.0" + } + }, + "node_modules/@opentelemetry/sdk-trace-node/node_modules/semver": { + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", + "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@opentelemetry/semantic-conventions": { + "version": "1.28.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-1.28.0.tgz", + "integrity": "sha512-lp4qAiMTD4sNWW4DbKLBkfiMZ4jbAboJIGOQr5DvciMRI494OapieI9qiODpOt0XBr1LjIDy1xAGAnVs5supTA==", + "license": "Apache-2.0", + "engines": { + "node": ">=14" + } + }, "node_modules/@types/node": { "version": "14.0.4", "resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.4.tgz", @@ -1296,10 +1436,14 @@ } }, "node_modules/logzio-nodejs": { - "version": "2.1.7", - "resolved": "https://registry.npmjs.org/logzio-nodejs/-/logzio-nodejs-2.1.7.tgz", - "integrity": "sha512-gGyd6YV8q68IxY+RLhpb2qyMAoJYF6xtU2GY6X2OQRGT58rZWeQShysuw2zoRIYpO64IhE47sJuixIwlrJ5sGw==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/logzio-nodejs/-/logzio-nodejs-2.2.0.tgz", + "integrity": "sha512-lsSAF2PL0rUMHGSdi+QjEJZnr09gTvI/mhMEoq7LBz8K8upO+6WWxq/CWWNYogAVlt8+UFZRLmT7KZVf01qSsg==", + "license": "(Apache-2.0)", "dependencies": { + "@opentelemetry/api": "^1.9.0", + "@opentelemetry/context-async-hooks": "^1.30.0", + "@opentelemetry/sdk-trace-node": "^1.30.0", "axios": "^1.6.4", "json-stringify-safe": "5.0.1", "lodash.assign": "4.2.0", @@ -2346,6 +2490,85 @@ "kuler": "^2.0.0" } }, + "@opentelemetry/api": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.9.0.tgz", + "integrity": "sha512-3giAOQvZiH5F9bMlMiv8+GSPMeqg0dbaeo58/0SlA9sxSqZhnUtxzX9/2FzyhS9sWQf5S0GJE0AKBrFqjpeYcg==" + }, + "@opentelemetry/context-async-hooks": { + "version": "1.30.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/context-async-hooks/-/context-async-hooks-1.30.0.tgz", + "integrity": "sha512-roCetrG/cz0r/gugQm/jFo75UxblVvHaNSRoR0kSSRSzXFAiIBqFCZuH458BHBNRtRe+0yJdIJ21L9t94bw7+g==", + "requires": {} + }, + "@opentelemetry/core": { + "version": "1.30.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/core/-/core-1.30.0.tgz", + "integrity": "sha512-Q/3u/K73KUjTCnFUP97ZY+pBjQ1kPEgjOfXj/bJl8zW7GbXdkw6cwuyZk6ZTXkVgCBsYRYUzx4fvYK1jxdb9MA==", + "requires": { + "@opentelemetry/semantic-conventions": "1.28.0" + } + }, + "@opentelemetry/propagator-b3": { + "version": "1.30.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/propagator-b3/-/propagator-b3-1.30.0.tgz", + "integrity": "sha512-lcobQQmd+hLdtxJJKu/i51lNXmF1PJJ7Y9B97ciHRVQuMI260vSZG7Uf4Zg0fqR8PB+fT/7rnlDwS0M7QldZQQ==", + "requires": { + "@opentelemetry/core": "1.30.0" + } + }, + "@opentelemetry/propagator-jaeger": { + "version": "1.30.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/propagator-jaeger/-/propagator-jaeger-1.30.0.tgz", + "integrity": "sha512-0hdP495V6HPRkVpowt54+Swn5NdesMIRof+rlp0mbnuIUOM986uF+eNxnPo9q5MmJegVBRTxgMHXXwvnXRnKRg==", + "requires": { + "@opentelemetry/core": "1.30.0" + } + }, + "@opentelemetry/resources": { + "version": "1.30.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/resources/-/resources-1.30.0.tgz", + "integrity": "sha512-5mGMjL0Uld/99t7/pcd7CuVtJbkARckLVuiOX84nO8RtLtIz0/J6EOHM2TGvPZ6F4K+XjUq13gMx14w80SVCQg==", + "requires": { + "@opentelemetry/core": "1.30.0", + "@opentelemetry/semantic-conventions": "1.28.0" + } + }, + "@opentelemetry/sdk-trace-base": { + "version": "1.30.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/sdk-trace-base/-/sdk-trace-base-1.30.0.tgz", + "integrity": "sha512-RKQDaDIkV7PwizmHw+rE/FgfB2a6MBx+AEVVlAHXRG1YYxLiBpPX2KhmoB99R5vA4b72iJrjle68NDWnbrE9Dg==", + "requires": { + "@opentelemetry/core": "1.30.0", + "@opentelemetry/resources": "1.30.0", + "@opentelemetry/semantic-conventions": "1.28.0" + } + }, + "@opentelemetry/sdk-trace-node": { + "version": "1.30.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/sdk-trace-node/-/sdk-trace-node-1.30.0.tgz", + "integrity": "sha512-MeXkXEdBs9xq1JSGTr/3P1lHBSUBaVmo1+UpoQhUpviPMzDXy0MNsdTC7KKI6/YcG74lTX6eqeNjlC1jV4Rstw==", + "requires": { + "@opentelemetry/context-async-hooks": "1.30.0", + "@opentelemetry/core": "1.30.0", + "@opentelemetry/propagator-b3": "1.30.0", + "@opentelemetry/propagator-jaeger": "1.30.0", + "@opentelemetry/sdk-trace-base": "1.30.0", + "semver": "^7.5.2" + }, + "dependencies": { + "semver": { + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", + "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==" + } + } + }, + "@opentelemetry/semantic-conventions": { + "version": "1.28.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-1.28.0.tgz", + "integrity": "sha512-lp4qAiMTD4sNWW4DbKLBkfiMZ4jbAboJIGOQr5DvciMRI494OapieI9qiODpOt0XBr1LjIDy1xAGAnVs5supTA==" + }, "@types/node": { "version": "14.0.4", "resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.4.tgz", @@ -3358,10 +3581,13 @@ } }, "logzio-nodejs": { - "version": "2.1.7", - "resolved": "https://registry.npmjs.org/logzio-nodejs/-/logzio-nodejs-2.1.7.tgz", - "integrity": "sha512-gGyd6YV8q68IxY+RLhpb2qyMAoJYF6xtU2GY6X2OQRGT58rZWeQShysuw2zoRIYpO64IhE47sJuixIwlrJ5sGw==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/logzio-nodejs/-/logzio-nodejs-2.2.0.tgz", + "integrity": "sha512-lsSAF2PL0rUMHGSdi+QjEJZnr09gTvI/mhMEoq7LBz8K8upO+6WWxq/CWWNYogAVlt8+UFZRLmT7KZVf01qSsg==", "requires": { + "@opentelemetry/api": "^1.9.0", + "@opentelemetry/context-async-hooks": "^1.30.0", + "@opentelemetry/sdk-trace-node": "^1.30.0", "axios": "^1.6.4", "json-stringify-safe": "5.0.1", "lodash.assign": "4.2.0", diff --git a/package.json b/package.json index 894b73b..1e7341c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "winston-logzio", "description": "A winston transport wrapper for logzio", - "version": "5.1.9", + "version": "5.2.0", "author": "Gilly Barr ", "contributors": [ { @@ -46,7 +46,7 @@ "@types/node": "^14.0.4", "json-stringify-safe": "5.0.1", "lodash.assign": "4.2.0", - "logzio-nodejs": "^2.1.7", + "logzio-nodejs": "^2.2.0", "triple-beam": "^1.3.0", "winston": "^3.8.2", "winston-transport": "^4.5.0"