Gathering detailed insights and metrics for @opentelemetry/instrumentation-winston
Gathering detailed insights and metrics for @opentelemetry/instrumentation-winston
Gathering detailed insights and metrics for @opentelemetry/instrumentation-winston
Gathering detailed insights and metrics for @opentelemetry/instrumentation-winston
OpenTelemetry instrumentation for JavaScript modules
npm install @opentelemetry/instrumentation-winston
Typescript
Module System
Min. Node Version
Node Version
NPM Version
81.7
Supply Chain
98.5
Quality
87.1
Maintenance
100
Vulnerability
99.6
License
instrumentation-pg: v0.51.0
Published on 28 Jan 2025
instrumentation-mysql2: v0.45.1
Published on 28 Jan 2025
instrumentation-cucumber: v0.14.0
Published on 28 Jan 2025
auto-instrumentations-node: v0.56.0
Published on 28 Jan 2025
instrumentation-fastify: v0.44.1
Published on 20 Jan 2025
instrumentation-aws-lambda: v0.50.2
Published on 20 Jan 2025
TypeScript (97.92%)
JavaScript (2.08%)
Shell (0.01%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
66,969,794
Last Day
204,612
Last Week
1,266,896
Last Month
4,986,928
Last Year
43,085,226
745 Stars
2,217 Commits
549 Forks
17 Watching
16 Branches
459 Contributors
Minified
Minified + Gzipped
Latest Version
0.44.0
Package Id
@opentelemetry/instrumentation-winston@0.44.0
Unpacked Size
62.87 kB
Size
13.73 kB
File Count
18
NPM Version
lerna/6.6.2/node@v18.20.5+x64 (linux)
Node Version
18.20.5
Publised On
18 Dec 2024
Cumulative downloads
Total Downloads
Last day
9.2%
204,612
Compared to previous day
Last week
6.5%
1,266,896
Compared to previous week
Last month
34.7%
4,986,928
Compared to previous month
Last year
128.9%
43,085,226
Compared to previous year
1
This module provides automatic instrumentation of the winston
module to inject trace-context into Winston log records (log correlation) and to send Winston logging to the OpenTelemetry Logging SDK (log sending). It may be loaded using the @opentelemetry/sdk-trace-node
package and is included in the @opentelemetry/auto-instrumentations-node
bundle.
If total installation size is not constrained, it is recommended to use the @opentelemetry/auto-instrumentations-node
bundle with @opentelemetry/sdk-node for the most seamless instrumentation experience.
Compatible with OpenTelemetry JS API and SDK 1.0+
.
1npm install --save @opentelemetry/instrumentation-winston
winston
versions >=1.0.0 <4
Log sending: winston
versions >=3.0.0 <4
1const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node'); 2const logsAPI = require('@opentelemetry/api-logs'); 3const { 4 LoggerProvider, 5 SimpleLogRecordProcessor, 6 ConsoleLogRecordExporter, 7} = require('@opentelemetry/sdk-logs'); 8const { WinstonInstrumentation } = require('@opentelemetry/instrumentation-winston'); 9const { registerInstrumentations } = require('@opentelemetry/instrumentation'); 10 11const tracerProvider = new NodeTracerProvider(); 12tracerProvider.register(); 13 14// To start a logger, you first need to initialize the Logger provider. 15const loggerProvider = new LoggerProvider(); 16// Add a processor to export log record 17loggerProvider.addLogRecordProcessor( 18 new SimpleLogRecordProcessor(new ConsoleLogRecordExporter()) 19); 20logsAPI.logs.setGlobalLoggerProvider(loggerProvider); 21 22registerInstrumentations({ 23 instrumentations: [ 24 new WinstonInstrumentation({ 25 // See below for Winston instrumentation options. 26 }), 27 ], 28}); 29 30const winston = require('winston'); 31const logger = winston.createLogger({ 32 transports: [new winston.transports.Console()], 33}) 34logger.info('foobar'); 35// {"message":"foobar","trace_id":"e21c7a95fff34e04f77c7bd518779621","span_id":"b7589a981fde09f4","trace_flags":"01", ...}
Option | Type | Description |
---|---|---|
disableLogSending | boolean | Whether to disable log sending. Default false . |
logSeverity | SeverityNumber | Control severity level for log sending. Default SeverityNumber.UNSPECIFIED , it will use Winston Logger's current level when unspecified. |
disableLogCorrelation | boolean | Whether to disable log correlation. Default false . |
logHook | LogHookFunction | An option hook to inject additional context to a log record after trace-context has been added. This requires disableLogCorrelation to be false. |
Winston Logger will automatically send log records to the OpenTelemetry Logs SDK if not explicitly disabled in config and @opentelemetry/winston-transport npm package is installed in the project. The OpenTelemetry SDK can be configured to handle those records, for example, sending them on to an OpenTelemetry collector for log archiving and processing. The example above shows a minimal configuration that emits OpenTelemetry log records to the console for debugging.
If the OpenTelemetry SDK is not configured with a Logger provider, then this will be a no-op.
Log sending can be disabled with the disableLogSending: true
option. Log sending is only available for Winston version 3 and later.
1npm install --save @opentelemetry/winston-transport
Winston logger calls in the context of a tracing span will have fields identifying the span added to the log record. This allows correlating log records with tracing data. The added fields are (spec):
trace_id
span_id
trace_flags
After adding these fields, the optional logHook
is called to allow injecting additional fields. For example:
1logHook: (span, record) => { 2 record['resource.service.name'] = provider.resource.attributes['service.name']; 3}
Log injection can be disabled with the disableLogCorrelation: true
option.
@opentelemetry/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:
1const logsAPI = require('@opentelemetry/api-logs'); 2const { 3 LoggerProvider, 4 SimpleLogRecordProcessor, 5 ConsoleLogRecordExporter, 6} = require('@opentelemetry/sdk-logs'); 7const { OpenTelemetryTransportV3 } = require('@opentelemetry/winston-transport'); 8const winston = require('winston'); 9 10 11// To start a logger, you first need to initialize the Logger provider. 12const loggerProvider = new LoggerProvider(); 13// Add a processor to export log record 14loggerProvider.addLogRecordProcessor( 15 new SimpleLogRecordProcessor(new ConsoleLogRecordExporter()) 16); 17logsAPI.logs.setGlobalLoggerProvider(loggerProvider); 18 19const logger = winston.createLogger({ 20 level: 'info', 21 transports: [ 22 new winston.transports.Console(), 23 new OpenTelemetryTransportV3() 24 ] 25});
[!IMPORTANT] Logs will be duplicated if
@opentelemetry/winston-transport
is added as a transport inwinston
and@opentelemetry/instrumentation-winston
is configured withdisableLogSending: false
.
This package does not currently generate any attributes from semantic conventions.
Apache 2.0 - See LICENSE for more information.
No vulnerabilities found.
Reason
all changesets reviewed
Reason
no dangerous workflow patterns detected
Reason
30 commit(s) and 14 issue activity found in the last 90 days -- score normalized to 10
Reason
license file detected
Details
Reason
no binaries found in the repo
Reason
security policy file detected
Details
Reason
SAST tool is run on all commits
Details
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
project is not fuzzed
Details
Reason
22 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More