{"name":"@opentelemetry/instrumentation-winston","version":"0.54.0","keywords":["instrumentation","logging","nodejs","opentelemetry","profiling","tracing","winston"],"author":{"name":"OpenTelemetry Authors"},"license":"Apache-2.0","_id":"@opentelemetry/instrumentation-winston@0.54.0","maintainers":[{"name":"dyladan","email":"dyladan@gmail.com"},{"name":"pichlermarc","email":"marc.pichler@dynatrace.com"}],"homepage":"https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-winston#readme","bugs":{"url":"https://github.com/open-telemetry/opentelemetry-js-contrib/issues"},"dist":{"shasum":"d6a2b0e117548017f673013580feaaf8399a18e4","tarball":"http://registry-npm.ywwl.com/@opentelemetry/instrumentation-winston/download/@opentelemetry/instrumentation-winston-0.54.0.tgz","fileCount":18,"integrity":"sha512-RH8HVPXrSYgozn+D3SANXcDxt3Xcd8If85JWmGRTns45Hu8YfXA3DEVonA8YfVg4zvvEJbGg+RFbCddAX/6LaA==","signatures":[{"sig":"MEUCIDeFd6yM433anQuVFxqRSfW5xrO3q1cRdocCkfo3tpjcAiEAnm3Y29k2R/zomtyQZwVu4w/lZPXYbx+KWa5+2rYLajs=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@opentelemetry%2finstrumentation-winston@0.54.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":65216,"size":14014,"noattachment":false,"key":"/@opentelemetry/instrumentation-winston/-/@opentelemetry/instrumentation-winston-0.54.0.tgz"},"main":"build/src/index.js","types":"build/src/index.d.ts","engines":{"node":"^18.19.0 || >=20.6.0"},"gitHead":"c84212cca7f010b80747cccb9942474e0459df6e","scripts":{"test":"nyc --no-clean mocha 'test/**/*.test.ts'","clean":"rimraf build/*","compile":"tsc -p .","lint:readme":"node ../../scripts/lint-readme.js","prepublishOnly":"npm run compile","version:update":"node ../../scripts/version-update.js","test-all-versions":"tav","compile:with-dependencies":"nx run-many -t compile -p @opentelemetry/instrumentation-winston"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:d2b630ac-62c8-49af-9072-42a7a11fdb6b"}},"repository":{"url":"git+https://github.com/open-telemetry/opentelemetry-js-contrib.git","type":"git","directory":"packages/instrumentation-winston"},"_npmVersion":"lerna/9.0.3/node@v24.12.0+x64 (linux)","description":"OpenTelemetry instrumentation for `winston` logger","directories":{},"_nodeVersion":"24.12.0","dependencies":{"@opentelemetry/api-logs":"^0.210.0","@opentelemetry/instrumentation":"^0.210.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"winston":"3.3.3","winston2":"npm:winston@2.4.7","@opentelemetry/api":"^1.3.0","@types/triple-beam":"^1.3.2","@opentelemetry/sdk-trace-base":"^2.0.0","@opentelemetry/sdk-trace-node":"^2.0.0","@opentelemetry/winston-transport":"^0.20.0","@opentelemetry/context-async-hooks":"^2.0.0"},"peerDependencies":{"@opentelemetry/api":"^1.3.0"},"_npmOperationalInternal":{"tmp":"tmp/instrumentation-winston_0.54.0_1768472708308_0.1379825122893854","host":"s3://npm-registry-packages-npm-production"},"readme":"# OpenTelemetry instrumentation for winston\n\n[![NPM Published Version][npm-img]][npm-url]\n[![Apache License][license-image]][license-image]\n\nThis module provides automatic instrumentation of the [`winston`](https://www.npmjs.com/package/winston) module to inject trace-context into Winston log records (log correlation) and to send Winston logging to the OpenTelemetry Logging SDK (log sending).\n\nIf total installation size is not constrained, it is recommended to use the [`@opentelemetry/auto-instrumentations-node`](https://www.npmjs.com/package/@opentelemetry/auto-instrumentations-node) bundle with [@opentelemetry/sdk-node](https://www.npmjs.com/package/@opentelemetry/sdk-node) for the most seamless instrumentation experience.\n\nCompatible with OpenTelemetry JS API and SDK `1.0+`.\n\n## Installation\n\n```bash\nnpm install --save @opentelemetry/instrumentation-winston\n```\n\n### Supported Versions\n\n- [`winston`](https://www.npmjs.com/package/winston) versions `>=1.0.0 <4`\n\nLog sending: [`winston`](https://www.npmjs.com/package/winston) versions `>=3.0.0 <4`\n\n## Usage\n\n```js\nconst { SimpleSpanProcessor, ConsoleSpanExporter } = require('@opentelemetry/sdk-trace');\nconst { SimpleLogRecordProcessor, ConsoleLogRecordExporter } = require('@opentelemetry/sdk-logs');\nconst { NodeSDK } = require('@opentelemetry/sdk-node');\nconst { WinstonInstrumentation } = require('@opentelemetry/instrumentation-winston');\n\nconst sdk = new NodeSDK({\n  spanProcessors: [\n    new SimpleSpanProcessor(new ConsoleSpanExporter()),\n  ],\n  logRecordProcessors: [\n    new SimpleLogRecordProcessor({ exporter: new ConsoleLogRecordExporter() }),\n  ],\n  instrumentations: [\n    new WinstonInstrumentation({\n      // See below for Winston instrumentation options.\n    }),\n  ]\n});\nsdk.start();\nprocess.once('beforeExit', async () => { await sdk.shutdown(); });\n\nconst winston = require('winston');\nconst logger = winston.createLogger({\n  transports: [new winston.transports.Console()],\n})\nlogger.info('foobar');\n// {\"message\":\"foobar\",\"trace_id\":\"e21c7a95fff34e04f77c7bd518779621\",\"span_id\":\"b7589a981fde09f4\",\"trace_flags\":\"01\", ...}\n```\n\n### Winston instrumentation options\n\n| Option                  | Type              | Description                                                                                                                                                |\n|-------------------------|-------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `disableLogSending`     | `boolean`         | Whether to disable [log sending](#log-sending). Default `false`.                                                                                           |\n| `logSeverity`           | `SeverityNumber`  | Control severity level for [log sending](#log-sending). Default `SeverityNumber.UNSPECIFIED`, it will use Winston Logger's current level when unspecified. |\n| `disableLogCorrelation` | `boolean`         | Whether to disable [log correlation](#log-correlation). Default `false`.                                                                                   |\n| `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.         |\n\n### Log sending\n\nWinston 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.\n\nWhen a Winston log call is made in an active span, the instrumentation preserves\nthat context for log sending even if Winston processes the transport\nasynchronously. The OpenTelemetry LogRecord uses its native trace context fields;\nthe `trace_id`, `span_id`, and `trace_flags` fields added for log correlation are\nnot duplicated as LogRecord attributes.\n\nIf the OpenTelemetry SDK is not configured with a Logger provider, then this will be a no-op.\n\nLog sending can be disabled with the `disableLogSending: true` option. Log sending is only available for Winston version 3 and later.\n\n```bash\nnpm install --save @opentelemetry/winston-transport\n```\n\n### Log correlation\n\nWinston logger calls in the context of a tracing span will have fields\nidentifying the span added to the log record. This allows\n[correlating](https://opentelemetry.io/docs/specs/otel/logs/#log-correlation)\nlog records with tracing data. The added fields are\n([spec](https://opentelemetry.io/docs/specs/otel/compatibility/logging_trace_context/)):\n\n- `trace_id`\n- `span_id`\n- `trace_flags`\n\nAfter adding these fields, the optional `logHook` is called to allow injecting additional fields. For example:\n\n```js\nlogHook: (span, record) => {\n  record['resource.service.name'] = provider.resource.attributes['service.name'];\n}\n```\n\nLog injection can be disabled with the `disableLogCorrelation: true` option.\n\n### Using OpenTelemetryTransportV3 without instrumentation\n\n[@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\nOpenTelemetry Logs SDK. It can be used directly when configuring a Winston logger.\nFor example:\n\n```js\nconst { SimpleSpanProcessor, ConsoleSpanExporter } = require('@opentelemetry/sdk-trace');\nconst { SimpleLogRecordProcessor, ConsoleLogRecordExporter } = require('@opentelemetry/sdk-logs');\nconst { NodeSDK } = require('@opentelemetry/sdk-node');\nconst { OpenTelemetryTransportV3 } = require('@opentelemetry/winston-transport');\nconst winston = require('winston');\n\nconst sdk = new NodeSDK({\n  spanProcessors: [\n    new SimpleSpanProcessor(new ConsoleSpanExporter()),\n  ],\n  logRecordProcessors: [\n    new SimpleLogRecordProcessor({ exporter: new ConsoleLogRecordExporter() }),\n  ],\n});\nsdk.start();\nprocess.once('beforeExit', async () => { await sdk.shutdown(); });\n\nconst logger = winston.createLogger({\n  level: 'info',\n  transports: [\n    new winston.transports.Console(),\n    new OpenTelemetryTransportV3()\n  ]\n});\n```\n\n> [!IMPORTANT]\n> Logs will be **duplicated** if `OpenTelemetryTransportV3` is explicitly added as a Winston logger transport **and** `@opentelemetry/instrumentation-winston` is active with the [Log sending](#log-sending) feature (the default). If you are both using `OpenTelemetryTransportV3` and instrumentation-winston, be sure to either disable instrumentation-winston completely, or disable its Log sending feature (`disableLogSending: false`). For example:\n>\n> ```js\n> const { WinstonInstrumentation } = require('@opentelemetry/instrumentation-winston');\n>\n> const sdk = new NodeSDK({\n>   instrumentations: [\n>     new WinstonInstrumentation({ disableLogSending: true })\n>   ]\n> });\n> // ...\n>\n> const { OpenTelemetryTransportV3 } = require('@opentelemetry/winston-transport');\n> // Winston import must be after the WinstonInstrumentation creation\n> const winston = require('winston');\n>\n> // ...\n> const logger = winston.createLogger(...);\n> ```\n\n## Semantic Conventions\n\nThis package does not currently generate any attributes from semantic conventions.\n\n## Useful links\n\n- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>\n- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>\n- For help or feedback on this project, join us in [GitHub Discussions][discussions-url]\n\n## License\n\nApache 2.0 - See [LICENSE][license-url] for more information.\n\n[discussions-url]: https://github.com/open-telemetry/opentelemetry-js/discussions\n[license-url]: https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/LICENSE\n[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat\n[npm-url]: https://www.npmjs.com/package/@opentelemetry/instrumentation-winston\n[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Finstrumentation-winston.svg\n","publish_time":1768472708448,"_cnpm_publish_time":1768472708448,"dist-tags":{"latest":"0.70.0"}}