From 9a5f421013bdb0c5f1ec09032e3045913eda0d45 Mon Sep 17 00:00:00 2001 From: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com> Date: Wed, 26 Jun 2024 13:33:00 -0700 Subject: [PATCH 1/5] Add extra details about @opentelemetry/winston-transport scenarios --- packages/winston-transport/README.md | 3 ++ .../README.md | 38 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/packages/winston-transport/README.md b/packages/winston-transport/README.md index 73b360ad95..25726fd9ae 100644 --- a/packages/winston-transport/README.md +++ b/packages/winston-transport/README.md @@ -49,6 +49,9 @@ const logger = winston.createLogger({ }); ``` +[!WARNING] +> Duplication of logs could happen if @opentelemetry/winston-transport is added as a transport in Winston logger and @opentelemetry/instrumentation-winston is also enabled with disableLogSending config as false. + ### Supported versions - [`winston`](https://www.npmjs.com/package/winston) versions `>=3.0.0 <4` diff --git a/plugins/node/opentelemetry-instrumentation-winston/README.md b/plugins/node/opentelemetry-instrumentation-winston/README.md index 4680f759e2..5ccdd00cf1 100644 --- a/plugins/node/opentelemetry-instrumentation-winston/README.md +++ b/plugins/node/opentelemetry-instrumentation-winston/README.md @@ -104,6 +104,44 @@ logHook: (span, record) => { Log injection can be disabled with the `disableLogCorrelation: true` option. +### Using OpenTelemetryTransportV3 without instrumentation + +[@opentelemetry/winston-transport](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/winston-transport) package exports the Winston transport class that is used to send records to the +OpenTelemetry Logs SDK. It can be used directly when configuring a Winston logger. +For example: + +```js +const logsAPI = require('@opentelemetry/api-logs'); +const { + LoggerProvider, + SimpleLogRecordProcessor, + ConsoleLogRecordExporter, +} = require('@opentelemetry/sdk-logs'); +const { OpenTelemetryTransportV3 } = require('@opentelemetry/winston-transport'); +const winston = require('winston'); + + +// To start a logger, you first need to initialize the Logger provider. +const loggerProvider = new LoggerProvider(); +// Add a processor to export log record +loggerProvider.addLogRecordProcessor( + new SimpleLogRecordProcessor(new ConsoleLogRecordExporter()) +); +logsAPI.logs.setGlobalLoggerProvider(loggerProvider); + +const logger = winston.createLogger({ + level: 'info', + transports: [ + new winston.transports.Console(), + new OpenTelemetryTransportV3() + ] +}); +``` + +[!WARNING] +> Duplication of logs could happen if @opentelemetry/winston-transport is added as a transport in Winston logger and @opentelemetry/instrumentation-winston is also enabled with disableLogSending config as false. + + ## Semantic Conventions This package does not currently generate any attributes from semantic conventions. From 134c7ab1ce1acd6172eadd64e09fffd501967712 Mon Sep 17 00:00:00 2001 From: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com> Date: Wed, 26 Jun 2024 13:36:45 -0700 Subject: [PATCH 2/5] Removed warning markdown --- packages/winston-transport/README.md | 3 +-- plugins/node/opentelemetry-instrumentation-winston/README.md | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/winston-transport/README.md b/packages/winston-transport/README.md index 25726fd9ae..3f6c4d9c0d 100644 --- a/packages/winston-transport/README.md +++ b/packages/winston-transport/README.md @@ -49,8 +49,7 @@ const logger = winston.createLogger({ }); ``` -[!WARNING] -> Duplication of logs could happen if @opentelemetry/winston-transport is added as a transport in Winston logger and @opentelemetry/instrumentation-winston is also enabled with disableLogSending config as false. +Duplication of logs could happen if @opentelemetry/winston-transport is added as a transport in Winston logger and @opentelemetry/instrumentation-winston is also enabled with disableLogSending config as false. ### Supported versions diff --git a/plugins/node/opentelemetry-instrumentation-winston/README.md b/plugins/node/opentelemetry-instrumentation-winston/README.md index 5ccdd00cf1..ceae0c0944 100644 --- a/plugins/node/opentelemetry-instrumentation-winston/README.md +++ b/plugins/node/opentelemetry-instrumentation-winston/README.md @@ -138,8 +138,7 @@ const logger = winston.createLogger({ }); ``` -[!WARNING] -> Duplication of logs could happen if @opentelemetry/winston-transport is added as a transport in Winston logger and @opentelemetry/instrumentation-winston is also enabled with disableLogSending config as false. +Duplication of logs could happen if @opentelemetry/winston-transport is added as a transport in Winston logger and @opentelemetry/instrumentation-winston is also enabled with disableLogSending config as false. ## Semantic Conventions From 4ef3654d3b8ac1decf0e840eef3bed61bc68a050 Mon Sep 17 00:00:00 2001 From: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com> Date: Wed, 26 Jun 2024 13:42:11 -0700 Subject: [PATCH 3/5] Lint fix --- plugins/node/opentelemetry-instrumentation-winston/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/node/opentelemetry-instrumentation-winston/README.md b/plugins/node/opentelemetry-instrumentation-winston/README.md index ceae0c0944..65cbc197e5 100644 --- a/plugins/node/opentelemetry-instrumentation-winston/README.md +++ b/plugins/node/opentelemetry-instrumentation-winston/README.md @@ -140,7 +140,6 @@ const logger = winston.createLogger({ Duplication of logs could happen if @opentelemetry/winston-transport is added as a transport in Winston logger and @opentelemetry/instrumentation-winston is also enabled with disableLogSending config as false. - ## Semantic Conventions This package does not currently generate any attributes from semantic conventions. From 7cda7e31b90343a57e73f06081e8e8c8f91c7d72 Mon Sep 17 00:00:00 2001 From: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com> Date: Wed, 26 Jun 2024 13:53:51 -0700 Subject: [PATCH 4/5] Lint fix --- plugins/node/opentelemetry-instrumentation-winston/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/node/opentelemetry-instrumentation-winston/README.md b/plugins/node/opentelemetry-instrumentation-winston/README.md index 65cbc197e5..1c551fd587 100644 --- a/plugins/node/opentelemetry-instrumentation-winston/README.md +++ b/plugins/node/opentelemetry-instrumentation-winston/README.md @@ -107,7 +107,7 @@ Log injection can be disabled with the `disableLogCorrelation: true` option. ### Using OpenTelemetryTransportV3 without instrumentation [@opentelemetry/winston-transport](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/winston-transport) package exports the Winston transport class that is used to send records to the -OpenTelemetry Logs SDK. It can be used directly when configuring a Winston logger. +OpenTelemetry Logs SDK. It can be used directly when configuring a Winston logger. For example: ```js From 6b04f294400f2012fdbad5a8918c7a66b16306fa Mon Sep 17 00:00:00 2001 From: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com> Date: Thu, 27 Jun 2024 10:06:59 -0700 Subject: [PATCH 5/5] Update duplication message --- packages/winston-transport/README.md | 3 ++- plugins/node/opentelemetry-instrumentation-winston/README.md | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/winston-transport/README.md b/packages/winston-transport/README.md index 3f6c4d9c0d..8da57f9634 100644 --- a/packages/winston-transport/README.md +++ b/packages/winston-transport/README.md @@ -49,7 +49,8 @@ const logger = winston.createLogger({ }); ``` -Duplication of logs could happen if @opentelemetry/winston-transport is added as a transport in Winston logger and @opentelemetry/instrumentation-winston is also enabled with disableLogSending config as false. +> [!IMPORTANT] +> Logs will be duplicated if `@opentelemetry/winston-transport` is added as a transport in `winston` and `@opentelemetry/instrumentation-winston` is configured with `disableLogSending: false`. ### Supported versions diff --git a/plugins/node/opentelemetry-instrumentation-winston/README.md b/plugins/node/opentelemetry-instrumentation-winston/README.md index 1c551fd587..341226f283 100644 --- a/plugins/node/opentelemetry-instrumentation-winston/README.md +++ b/plugins/node/opentelemetry-instrumentation-winston/README.md @@ -138,7 +138,8 @@ const logger = winston.createLogger({ }); ``` -Duplication of logs could happen if @opentelemetry/winston-transport is added as a transport in Winston logger and @opentelemetry/instrumentation-winston is also enabled with disableLogSending config as false. +> [!IMPORTANT] +> Logs will be duplicated if `@opentelemetry/winston-transport` is added as a transport in `winston` and `@opentelemetry/instrumentation-winston` is configured with `disableLogSending: false`. ## Semantic Conventions