Skip to content

Commit 85ca5f1

Browse files
authored
docs(@opentelemetry/instrumentation-winston): Add extra details about @opentelemetry/winston-transport scenarios (#2302)
1 parent 626ecc5 commit 85ca5f1

File tree

2 files changed

+40
-0
lines changed
  • packages/winston-transport
  • plugins/node/opentelemetry-instrumentation-winston

2 files changed

+40
-0
lines changed

packages/winston-transport/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ const logger = winston.createLogger({
4949
});
5050
```
5151

52+
> [!IMPORTANT]
53+
> Logs will be duplicated if `@opentelemetry/winston-transport` is added as a transport in `winston` and `@opentelemetry/instrumentation-winston` is configured with `disableLogSending: false`.
54+
5255
### Supported versions
5356

5457
- [`winston`](https://www.npmjs.com/package/winston) versions `>=3.0.0 <4`

plugins/node/opentelemetry-instrumentation-winston/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,43 @@ logHook: (span, record) => {
104104

105105
Log injection can be disabled with the `disableLogCorrelation: true` option.
106106

107+
### Using OpenTelemetryTransportV3 without instrumentation
108+
109+
[@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
110+
OpenTelemetry Logs SDK. It can be used directly when configuring a Winston logger.
111+
For example:
112+
113+
```js
114+
const logsAPI = require('@opentelemetry/api-logs');
115+
const {
116+
LoggerProvider,
117+
SimpleLogRecordProcessor,
118+
ConsoleLogRecordExporter,
119+
} = require('@opentelemetry/sdk-logs');
120+
const { OpenTelemetryTransportV3 } = require('@opentelemetry/winston-transport');
121+
const winston = require('winston');
122+
123+
124+
// To start a logger, you first need to initialize the Logger provider.
125+
const loggerProvider = new LoggerProvider();
126+
// Add a processor to export log record
127+
loggerProvider.addLogRecordProcessor(
128+
new SimpleLogRecordProcessor(new ConsoleLogRecordExporter())
129+
);
130+
logsAPI.logs.setGlobalLoggerProvider(loggerProvider);
131+
132+
const logger = winston.createLogger({
133+
level: 'info',
134+
transports: [
135+
new winston.transports.Console(),
136+
new OpenTelemetryTransportV3()
137+
]
138+
});
139+
```
140+
141+
> [!IMPORTANT]
142+
> Logs will be duplicated if `@opentelemetry/winston-transport` is added as a transport in `winston` and `@opentelemetry/instrumentation-winston` is configured with `disableLogSending: false`.
143+
107144
## Semantic Conventions
108145

109146
This package does not currently generate any attributes from semantic conventions.

0 commit comments

Comments
 (0)