From ea2e336e0c0b95f3edbeca1e302afe8a8cd64f3e Mon Sep 17 00:00:00 2001 From: Simplychee Date: Sun, 12 Jan 2025 17:04:47 +0200 Subject: [PATCH 1/6] winston-logzio --- docs/shipping/Code/node-js.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/shipping/Code/node-js.md b/docs/shipping/Code/node-js.md index 440b9f43..f4462d63 100644 --- a/docs/shipping/Code/node-js.md +++ b/docs/shipping/Code/node-js.md @@ -233,6 +233,30 @@ var obj = { logger.log(obj); ``` +### Add opentelemetry context +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`). + +This feature is enabled by default. To disable it, set the `AddOtelContext` param in your handler configuration to `false`, as shown 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], +}); +``` + + From 032dcc4ca32fc5a2b6b702a9dcf818d5b9f9912f Mon Sep 17 00:00:00 2001 From: Simplychee Date: Sun, 12 Jan 2025 17:06:32 +0200 Subject: [PATCH 2/6] context --- docs/shipping/Code/node-js.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/shipping/Code/node-js.md b/docs/shipping/Code/node-js.md index f4462d63..3367fe2f 100644 --- a/docs/shipping/Code/node-js.md +++ b/docs/shipping/Code/node-js.md @@ -170,6 +170,8 @@ For a complete list of your options, see the configuration parameters below.👇 | timeout | Read/write/connection timeout, in milliseconds. | -- | | extraFields | Adds custom fields to each log in JSON format: `extraFields : { field_1: "val_1", field_2: "val_2" , ... }` | -- | | 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` | +| addOtelContext | Add `trace_id`, `span_id`, and `service_name` fields to logs when OpenTelemetry context is available. | Default: `true` | + ### Additional configuration options From 38af3176169bb1c6fb9fcf21ae96822f3e1c5cb7 Mon Sep 17 00:00:00 2001 From: Simplychee Date: Sun, 12 Jan 2025 17:26:16 +0200 Subject: [PATCH 3/6] more node changes and past merges --- docs/shipping/Code/node-js.md | 100 +++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 3 deletions(-) diff --git a/docs/shipping/Code/node-js.md b/docs/shipping/Code/node-js.md index 3367fe2f..e1c72649 100644 --- a/docs/shipping/Code/node-js.md +++ b/docs/shipping/Code/node-js.md @@ -56,18 +56,68 @@ var logger = require('logzio-nodejs').createLogger({ | Parameter | Description | Required/Default | |---|---|---| | 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 | -| protocol | `http` or `https`. The value of this parameter affects the default of the `port` parameter. | `http` | +| protocol | `http`, `https` or `udp`. The value of this parameter affects the default of the `port` parameter. | `http` | | host | {@include: ../../_include/log-shipping/listener-var.md} Replace `<>` 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` | -| port | Destination port. The default port depends on the `protocol` parameter: `8070` (for HTTP) or `8071` (for HTTPS) | `8070` / `8071` | +| port | Destination port. The default port depends on the `protocol` parameter. For udp default port is `5050`, http is `8070`, and https is `8071` | `5050` / `8070` / `8071` | | type | {@include: ../../_include/log-shipping/type.md} | `nodejs` | | sendIntervalMs | Time to wait between retry attempts, in milliseconds. | `2000` (2 seconds) | | bufferSize | Maximum number of messages the logger accumulates before sending them all as a bulk. | `100` | | numberOfRetries | Maximum number of retry attempts. | `3` | | debug | Set to `true` to print debug messages to the console. | `false` | -| 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. | -- | +| 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. | -- | | timeout | Read/write/connection timeout, in milliseconds. | -- | | extraFields | JSON format. Adds your custom fields to each log. Format: `extraFields : { field_1: "val_1", field_2: "val_2" , ... }` | -- | | setUserAgent | Set to false to send logs without the user-agent field in the request header. | `true` | +| addOtelContext | Add `trace_id`, `span_id`, and `service_name` fields to logs when OpenTelemetry context is available. | Default: `true` | + +### Using UDP + +While the UDP protocol can be used, it has limitations that make it less than ideal: + +* Lack of Reliability: UDP does not guarantee that logs are received, making it less reliable than other protocols. +* Suboptimal Performance: UDP cannot utilize the bulk API, leading to reduced performance. + +When using UDP, each message is sent individually rather than in batches. However, the `bufferSize` parameter still applies differently: + +The logger waits for the buffer to reach the specified size before sending all messages. To send each message immediately, set `bufferSize = 1`. + +For better reliability and performance, consider using a different protocol when possible. + +### Callback usage + +The `callback` option lets you manage errors and confirm successful log transmissions when logging messages. The callback function can be used to handle different scenarios, such as logging errors or confirming successful log transmissions. + +### Callback invocation + +1. **On Error**: The callback is invoked with an error object if an issue occured during log transmission. +2. **On Success**: The callback is invoked without arguments when the log messages are successfully sent. + +#### Example Usage + +```javascript +var logger = require('logzio-nodejs').createLogger({ + token: '__YOUR_ACCOUNT_TOKEN__', + type: 'YourLogType', + callback: function(err) { + if (err) { + console.error('Error sending log:', err); + } else { + console.log('Log sent successfully'); + } + } +}); + +// Sending a log message +logger.log('This is a log message'); +``` +### Default callback +```javascript + _defaultCallback(err) { + if (err && !this.supressErrors) { + this.internalLogger.log(`logzio-logger error: ${err}`, err); + } + } +``` **Code example:** @@ -95,6 +145,35 @@ For serverless environments, such as AWS Lambda, Azure Functions, or Google Clou logger.sendAndClose(); ``` + +### 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 >= `2.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 +var logger = require('logzio-nodejs').createLogger({ + token: 'token', + type: 'no-otel-context', + addOtelContext: false +}); +``` + +### Build and test locally +1. Clone the repository: + +```bash + git clone https://github.com/logzio/logzio-nodejs.git + cd logzio-nodejs + ``` + +2. Build and run tests: + +```bash + npm install + npm test + ``` + @@ -258,6 +337,21 @@ const logger = winston.createLogger({ }); ``` +### Build and test locally + +1. Clone the repository: + +```bash + git clone https://github.com/logzio/winston-logzio.git + cd winston-logzio + ``` + +2. Build and run tests: + +```bash + npm install + npm test + ``` From edb7b532ace2d733bf020949577879a24898abf7 Mon Sep 17 00:00:00 2001 From: Simplychee Date: Sun, 12 Jan 2025 17:30:35 +0200 Subject: [PATCH 4/6] link to nodejs --- docs/user-guide/explore/trace-view.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/user-guide/explore/trace-view.md b/docs/user-guide/explore/trace-view.md index 45ac5b98..6eb4f03b 100644 --- a/docs/user-guide/explore/trace-view.md +++ b/docs/user-guide/explore/trace-view.md @@ -28,6 +28,7 @@ Supported integrations for Trace context: * [.NET](https://docs.logz.io/docs/shipping/Code/dotnet/#add-trace-context-1) * [Python](https://docs.logz.io/docs/shipping/Code/Python/#trace-context) +* [Node.js](https://docs.logz.io/docs/shipping/code/node-js/) Additional integrations will be available in future updates. From d414193fe9c28f564fb64f864daf37bc6bcc6eef Mon Sep 17 00:00:00 2001 From: Simplychee Date: Mon, 13 Jan 2025 13:10:04 +0200 Subject: [PATCH 5/6] updates --- docs/shipping/Code/node-js.md | 70 ++--------------------------------- 1 file changed, 4 insertions(+), 66 deletions(-) diff --git a/docs/shipping/Code/node-js.md b/docs/shipping/Code/node-js.md index e1c72649..88ede8e2 100644 --- a/docs/shipping/Code/node-js.md +++ b/docs/shipping/Code/node-js.md @@ -58,7 +58,7 @@ var logger = require('logzio-nodejs').createLogger({ | 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 | | protocol | `http`, `https` or `udp`. The value of this parameter affects the default of the `port` parameter. | `http` | | host | {@include: ../../_include/log-shipping/listener-var.md} Replace `<>` 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` | -| port | Destination port. The default port depends on the `protocol` parameter. For udp default port is `5050`, http is `8070`, and https is `8071` | `5050` / `8070` / `8071` | +| port | Destination port. The default port depends on the `protocol` parameter. `8070` for HTTP, `8071` for HTTPS | `8070` / `8071` | | type | {@include: ../../_include/log-shipping/type.md} | `nodejs` | | sendIntervalMs | Time to wait between retry attempts, in milliseconds. | `2000` (2 seconds) | | bufferSize | Maximum number of messages the logger accumulates before sending them all as a bulk. | `100` | @@ -70,55 +70,6 @@ var logger = require('logzio-nodejs').createLogger({ | setUserAgent | Set to false to send logs without the user-agent field in the request header. | `true` | | addOtelContext | Add `trace_id`, `span_id`, and `service_name` fields to logs when OpenTelemetry context is available. | Default: `true` | -### Using UDP - -While the UDP protocol can be used, it has limitations that make it less than ideal: - -* Lack of Reliability: UDP does not guarantee that logs are received, making it less reliable than other protocols. -* Suboptimal Performance: UDP cannot utilize the bulk API, leading to reduced performance. - -When using UDP, each message is sent individually rather than in batches. However, the `bufferSize` parameter still applies differently: - -The logger waits for the buffer to reach the specified size before sending all messages. To send each message immediately, set `bufferSize = 1`. - -For better reliability and performance, consider using a different protocol when possible. - -### Callback usage - -The `callback` option lets you manage errors and confirm successful log transmissions when logging messages. The callback function can be used to handle different scenarios, such as logging errors or confirming successful log transmissions. - -### Callback invocation - -1. **On Error**: The callback is invoked with an error object if an issue occured during log transmission. -2. **On Success**: The callback is invoked without arguments when the log messages are successfully sent. - -#### Example Usage - -```javascript -var logger = require('logzio-nodejs').createLogger({ - token: '__YOUR_ACCOUNT_TOKEN__', - type: 'YourLogType', - callback: function(err) { - if (err) { - console.error('Error sending log:', err); - } else { - console.log('Log sent successfully'); - } - } -}); - -// Sending a log message -logger.log('This is a log message'); -``` -### Default callback -```javascript - _defaultCallback(err) { - if (err && !this.supressErrors) { - this.internalLogger.log(`logzio-logger error: ${err}`, err); - } - } -``` - **Code example:** You can send log lines as a raw string or an object. For consistent and reliable parsing, we recommend sending them as objects: @@ -146,8 +97,9 @@ For serverless environments, such as AWS Lambda, Azure Functions, or Google Clou ``` -### 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 >= `2.2.0`). +### Add OpenTelemetry context + +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`). This feature is enabled by default, To disable it, set the `AddOtelContext` param in your handler configuration to `false`, like in this example: @@ -159,20 +111,6 @@ var logger = require('logzio-nodejs').createLogger({ }); ``` -### Build and test locally -1. Clone the repository: - -```bash - git clone https://github.com/logzio/logzio-nodejs.git - cd logzio-nodejs - ``` - -2. Build and run tests: - -```bash - npm install - npm test - ``` From 783083305d71e371f6f9c2e6ac2bc1612b95ab51 Mon Sep 17 00:00:00 2001 From: Simplychee Date: Mon, 13 Jan 2025 15:28:09 +0200 Subject: [PATCH 6/6] no build and test --- docs/shipping/Code/node-js.md | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/docs/shipping/Code/node-js.md b/docs/shipping/Code/node-js.md index 88ede8e2..b9c36f1b 100644 --- a/docs/shipping/Code/node-js.md +++ b/docs/shipping/Code/node-js.md @@ -275,23 +275,6 @@ const logger = winston.createLogger({ }); ``` -### Build and test locally - -1. Clone the repository: - -```bash - git clone https://github.com/logzio/winston-logzio.git - cd winston-logzio - ``` - -2. Build and run tests: - -```bash - npm install - npm test - ``` - -