Skip to content

Commit

Permalink
Merge pull request #86 from logzio/feature/inject-otel-context
Browse files Browse the repository at this point in the history
Feature/inject otel context
  • Loading branch information
yotamloe authored Dec 25, 2024
2 parents 64c5d8f + b53e21f commit 38d5acc
Show file tree
Hide file tree
Showing 3 changed files with 261 additions and 11 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -164,6 +165,29 @@ tsc --project tsconfig.json

</div>

## 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: '<<SHIPPING-TOKEN>>',
host: '<<LISTENER-HOST>>',
addOtelCotext: false,
});

const logger = winston.createLogger({
format: winston.format.simple(),
transports: [logzioWinstonTransport],
});
```

## Build and test locally
1. Clone the repository:
```bash
Expand Down
244 changes: 235 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"contributors": [
{
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 38d5acc

Please sign in to comment.