@opentelemetry/winston-transport
TypeScript icon, indicating that this package has built-in type declarations

0.10.0 • Public • Published

OpenTelemetry transport for winston

NPM Published Version Apache License

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.
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.

Supported versions

Useful links

License

Apache 2.0 - See LICENSE for more information.

/@opentelemetry/winston-transport/

    Package Sidebar

    Install

    npm i @opentelemetry/winston-transport

    Weekly Downloads

    131,604

    Version

    0.10.0

    License

    Apache-2.0

    Unpacked Size

    31.2 kB

    Total Files

    15

    Last publish

    Collaborators

    • bogdandrutu
    • dyladan
    • pichlermarc