Skip to content

Commit 3b6c7aa

Browse files
authored
Merge pull request #748 from logzio/more-trace-context-jan12
More trace context
2 parents fcf3273 + 7830833 commit 3b6c7aa

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

docs/shipping/Code/node-js.md

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,19 @@ var logger = require('logzio-nodejs').createLogger({
5656
| Parameter | Description | Required/Default |
5757
|---|---|---|
5858
| token | Your Logz.io log shipping token securely directs the data to your [Logz.io account](https://app.logz.io/#/dashboard/settings/manage-tokens/log-shipping). {@include: ../../_include/log-shipping/log-shipping-token.html} | Required |
59-
| protocol | `http` or `https`. The value of this parameter affects the default of the `port` parameter. | `http` |
59+
| protocol | `http`, `https` or `udp`. The value of this parameter affects the default of the `port` parameter. | `http` |
6060
| host | {@include: ../../_include/log-shipping/listener-var.md} Replace `<<LISTENER-HOST>>` with the host [for your region](https://docs.logz.io/docs/user-guide/admin/hosting-regions/account-region/#available-regions). The required port depends whether HTTP or HTTPS is used: HTTP = 8070, HTTPS = 8071. | `listener.logz.io` |
61-
| port | Destination port. The default port depends on the `protocol` parameter: `8070` (for HTTP) or `8071` (for HTTPS) | `8070` / `8071` |
61+
| port | Destination port. The default port depends on the `protocol` parameter. `8070` for HTTP, `8071` for HTTPS | `8070` / `8071` |
6262
| type | {@include: ../../_include/log-shipping/type.md} | `nodejs` |
6363
| sendIntervalMs | Time to wait between retry attempts, in milliseconds. | `2000` (2 seconds) |
6464
| bufferSize | Maximum number of messages the logger accumulates before sending them all as a bulk. | `100` |
6565
| numberOfRetries | Maximum number of retry attempts. | `3` |
6666
| debug | Set to `true` to print debug messages to the console. | `false` |
67-
| callback | A callback function to call when the logger encounters an unrecoverable error. The function API is `function(err)`, where `err` is the Error object. | -- |
67+
| callback | A callback function to call when the logger encounters an unrecoverable error. On success: `callback()`. On error: `callback(error)` where `error` is the Error object. This function enables you to handle errors and successful transmissions independently. | -- |
6868
| timeout | Read/write/connection timeout, in milliseconds. | -- |
6969
| extraFields | JSON format. Adds your custom fields to each log. Format: `extraFields : { field_1: "val_1", field_2: "val_2" , ... }` | -- |
7070
| setUserAgent | Set to false to send logs without the user-agent field in the request header. | `true` |
71+
| addOtelContext | Add `trace_id`, `span_id`, and `service_name` fields to logs when OpenTelemetry context is available. | Default: `true` |
7172

7273
**Code example:**
7374

@@ -95,6 +96,22 @@ For serverless environments, such as AWS Lambda, Azure Functions, or Google Clou
9596
logger.sendAndClose();
9697
```
9798

99+
100+
### Add OpenTelemetry context
101+
102+
If you're sending traces with OpenTelemetry instrumentation (auto or manual), you can correlate your logs with the trace context. This ensures your logs include trace data, such as service name, `span_id` and `trace_id` (version >= `2.2.0`).
103+
104+
This feature is enabled by default, To disable it, set the `AddOtelContext` param in your handler configuration to `false`, like in this example:
105+
106+
```javascript
107+
var logger = require('logzio-nodejs').createLogger({
108+
token: 'token',
109+
type: 'no-otel-context',
110+
addOtelContext: false
111+
});
112+
```
113+
114+
98115
</TabItem>
99116
<TabItem value="winston-logzio" label="winston-logzio">
100117

@@ -170,6 +187,8 @@ For a complete list of your options, see the configuration parameters below.👇
170187
| timeout | Read/write/connection timeout, in milliseconds. | -- |
171188
| extraFields | Adds custom fields to each log in JSON format: `extraFields : { field_1: "val_1", field_2: "val_2" , ... }` | -- |
172189
| setUserAgent | Set to `false` to send logs without the user-agent field in the request header. Set to `false` if sending data from Firefox browser. | `true` |
190+
| addOtelContext | Add `trace_id`, `span_id`, and `service_name` fields to logs when OpenTelemetry context is available. | Default: `true` |
191+
173192

174193
### Additional configuration options
175194

@@ -233,6 +252,28 @@ var obj = {
233252
logger.log(obj);
234253
```
235254

255+
### Add opentelemetry context
256+
If you're sending traces with OpenTelemetry instrumentation (auto or manual), you can correlate your logs with the trace context. This ensures your logs include trace data, such as service name, `span_id` and `trace_id` (version >= `5.2.0`).
257+
258+
This feature is enabled by default. To disable it, set the `AddOtelContext` param in your handler configuration to `false`, as shown in this example:
259+
260+
```javascript
261+
const winston = require('winston');
262+
const LogzioWinstonTransport = require('winston-logzio');
263+
264+
const logzioWinstonTransport = new LogzioWinstonTransport({
265+
level: 'info',
266+
name: 'winston_logzio',
267+
token: '<<SHIPPING-TOKEN>>',
268+
host: '<<LISTENER-HOST>>',
269+
addOtelCotext: false,
270+
});
271+
272+
const logger = winston.createLogger({
273+
format: winston.format.simple(),
274+
transports: [logzioWinstonTransport],
275+
});
276+
```
236277

237278
</TabItem>
238279
<TabItem value="Typescript" label="winston-logzio Typescript">

docs/user-guide/explore/trace-view.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Supported integrations for Trace context:
2828

2929
* [.NET](https://docs.logz.io/docs/shipping/Code/dotnet/#add-trace-context-1)
3030
* [Python](https://docs.logz.io/docs/shipping/Code/Python/#trace-context)
31+
* [Node.js](https://docs.logz.io/docs/shipping/code/node-js/)
3132

3233
Additional integrations will be available in future updates.
3334

0 commit comments

Comments
 (0)