Skip to content

Commit 38d5acc

Browse files
authored
Merge pull request #86 from logzio/feature/inject-otel-context
Feature/inject otel context
2 parents 64c5d8f + b53e21f commit 38d5acc

File tree

3 files changed

+261
-11
lines changed

3 files changed

+261
-11
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ If you do not have a [Logz.io](http://logz.io) account, you can sign up for a fr
5858
- **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.
5959
- **timeout** - The read/write/connection timeout in milliseconds.
6060
- **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`
61+
- **addOtelContext** - Add `trace_id`, `span_id`, `service_name` fields to logs when opentelemetry context is available. Default: `true`
6162
- **compress** - If true the the logs are compressed in gzip format. Default: `false`
6263
- **internalLogger** - set internal logger that supports the function log. Default: console.
6364
- **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
164165

165166
</div>
166167

168+
## Add opentelemetry context
169+
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`).
170+
171+
This feature is enabled by default, To disable it, set the `AddOtelContext` param in your handler configuration to `false`, like in this example:
172+
173+
```javascript
174+
const winston = require('winston');
175+
const LogzioWinstonTransport = require('winston-logzio');
176+
177+
const logzioWinstonTransport = new LogzioWinstonTransport({
178+
level: 'info',
179+
name: 'winston_logzio',
180+
token: '<<SHIPPING-TOKEN>>',
181+
host: '<<LISTENER-HOST>>',
182+
addOtelCotext: false,
183+
});
184+
185+
const logger = winston.createLogger({
186+
format: winston.format.simple(),
187+
transports: [logzioWinstonTransport],
188+
});
189+
```
190+
167191
## Build and test locally
168192
1. Clone the repository:
169193
```bash

package-lock.json

Lines changed: 235 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "winston-logzio",
33
"description": "A winston transport wrapper for logzio",
4-
"version": "5.1.9",
4+
"version": "5.2.0",
55
"author": "Gilly Barr <[email protected]>",
66
"contributors": [
77
{
@@ -46,7 +46,7 @@
4646
"@types/node": "^14.0.4",
4747
"json-stringify-safe": "5.0.1",
4848
"lodash.assign": "4.2.0",
49-
"logzio-nodejs": "^2.1.7",
49+
"logzio-nodejs": "^2.2.0",
5050
"triple-beam": "^1.3.0",
5151
"winston": "^3.8.2",
5252
"winston-transport": "^4.5.0"

0 commit comments

Comments
 (0)