@opentelemetry/winston-transport
OpenTelemetry Transport for winston
Last updated a month ago by GitHub Actions .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @opentelemetry/winston-transport 
SYNC missed versions from official npm registry.

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');
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()
  ]
});

Log Levels and Severity Mapping

By default, @opentelemetry/winston-transport maps standard Winston log levels (npm, syslog, cli, and OpenTelemetry native levels) to OpenTelemetry SeverityNumber.

OpenTelemetry Log Levels

You can use the exported otelLogLevels map to configure Winston with native OpenTelemetry log levels:

const { OpenTelemetryTransportV3, otelLogLevels } = require('@opentelemetry/winston-transport');
const winston = require('winston');

const logger = winston.createLogger({
  levels: otelLogLevels, // { fatal: 0, error: 1, warn: 2, info: 3, debug: 4, trace: 5 }
  level: 'info',
  transports: [
    new winston.transports.Console(),
    new OpenTelemetryTransportV3()
  ]
});

Custom Severity Mapping

For custom Winston log levels, you can supply a custom severityMapping:

const { SeverityNumber } = require('@opentelemetry/api');
const { OpenTelemetryTransportV3 } = require('@opentelemetry/winston-transport');
const winston = require('winston');

const logger = winston.createLogger({
  levels: { emergency: 0, alert: 1, notice: 2 },
  level: 'notice',
  transports: [
    new OpenTelemetryTransportV3({
      severityMapping: {
        emergency: SeverityNumber.FATAL,
        alert: SeverityNumber.ERROR,
        notice: SeverityNumber.INFO,
      }
    })
  ]
});

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

Useful links

License

Apache 2.0 - See LICENSE for more information.

Current Tags

  • 0.35.0                                ...           latest (a month ago)

39 Versions

  • 0.35.0                                ...           a month ago
  • 0.34.0                                ...           a month ago
  • 0.33.0                                ...           2 months ago
  • 0.32.0                                ...           3 months ago
  • 0.31.0                                ...           4 months ago
  • 0.30.0                                ...           5 months ago
  • 0.29.0                                ...           6 months ago
  • 0.28.0                                ...           6 months ago
  • 0.27.0                                ...           7 months ago
  • 0.26.0                                ...           7 months ago
  • 0.25.0                                ...           7 months ago
  • 0.24.0                                ...           8 months ago
  • 0.23.0                                ...           9 months ago
  • 0.22.0                                ...           9 months ago
  • 0.21.0                                ...           10 months ago
  • 0.20.0                                ...           10 months ago
  • 0.19.0                                ...           a year ago
  • 0.18.0                                ...           a year ago
  • 0.17.0                                ...           a year ago
  • 0.16.2                                ...           a year ago
  • 0.16.1                                ...           a year ago
  • 0.16.0                                ...           a year ago
  • 0.15.0                                ...           a year ago
  • 0.14.1                                ...           a year ago
  • 0.14.0                                ...           a year ago
  • 0.13.0                                ...           a year ago
  • 0.12.0                                ...           2 years ago
  • 0.11.0                                ...           2 years ago
  • 0.10.1                                ...           2 years ago
  • 0.10.0                                ...           2 years ago
  • 0.9.0                                ...           2 years ago
  • 0.8.0                                ...           2 years ago
  • 0.7.0                                ...           2 years ago
  • 0.6.0                                ...           2 years ago
  • 0.5.0                                ...           2 years ago
  • 0.4.0                                ...           2 years ago
  • 0.3.0                                ...           3 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
Downloads
Total 36
Today 4
This Week 18
This Month 31
Last Day 3
Last Week 1
Last Month 3
Dev Dependencies (3)

© 2010 - cnpmjs.org x YWFE | Home | YWFE