OpenTelemetry transport for winston
This module provides a Transport for winston module to send Winston logging to the OpenTelemetry Logging SDK.
Compatible with OpenTelemetry JS API and SDK 1.0+.
Installation
npm install --save @opentelemetry/winston-transport
Usage
This 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. If using
@opentelemetry/instrumenation-winston
package there is no need to instantiate the transport as the instrumentation will take care of that.
For example:
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.
// And add a processor to export log record.
const loggerProvider = new LoggerProvider({
processors: [
new SimpleLogRecordProcessor({ exporter: new ConsoleLogRecordExporter() })
],
});
logsAPI.logs.setGlobalLoggerProvider(loggerProvider);
const logger = winston.createLogger({
level: 'info',
transports: [
new winston.transports.Console(),
new OpenTelemetryTransportV3()
]
});
Logs will be duplicated if
@opentelemetry/winston-transportis added as a transport inwinstonand@opentelemetry/instrumentation-winstonis configured withdisableLogSending: false.
Error handling
Error instances assigned to the conventional error or err fields are
emitted through the OpenTelemetry Logs API exception field. Instances assigned
to other metadata fields, including errors nested in arrays or objects, are
converted to structured attributes containing their name, message, stack,
and other own properties. Circular references in serialized error metadata are
represented as [Circular].
Supported versions
winstonversions>=3.0.0 <4
Useful links
- For more information on OpenTelemetry, visit: https://opentelemetry.io/
- For more about OpenTelemetry JavaScript: https://github.com/open-telemetry/opentelemetry-js
- For help or feedback on this project, join us in GitHub Discussions
License
Apache 2.0 - See LICENSE for more information.