From 85ca5f184640df4f5f3629b01d93ab0f392633aa Mon Sep 17 00:00:00 2001 From: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com> Date: Fri, 28 Jun 2024 16:25:29 -0700 Subject: [PATCH] docs(@opentelemetry/instrumentation-winston): Add extra details about @opentelemetry/winston-transport scenarios (#2302) --- packages/winston-transport/README.md | 3 ++ .../README.md | 37 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/packages/winston-transport/README.md b/packages/winston-transport/README.md index 73b360ad95..8da57f9634 100644 --- a/packages/winston-transport/README.md +++ b/packages/winston-transport/README.md @@ -49,6 +49,9 @@ const logger = winston.createLogger({ }); ``` +> [!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 - [`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..341226f283 100644 --- a/plugins/node/opentelemetry-instrumentation-winston/README.md +++ b/plugins/node/opentelemetry-instrumentation-winston/README.md @@ -104,6 +104,43 @@ 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() + ] +}); +``` + +> [!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 This package does not currently generate any attributes from semantic conventions.