# @opentelemetry/instrumentation-console

> OpenTelemetry instrumentation for Node.js `console`

Latest version **0.4.0** (published 2026-08-31) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @opentelemetry/instrumentation-console
pnpm add @opentelemetry/instrumentation-console
yarn add @opentelemetry/instrumentation-console
bun add @opentelemetry/instrumentation-console
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2026-08-31 |
| First published | 2026-07-03 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | ^18.19.0 \|\| >=20.6.0 |
| Dependencies | 2 |
| Unpacked size | 33 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 924 |
| Author | OpenTelemetry Authors |
| Maintainers | dyladan, pichlermarc, overbalance, npmjs-account, trentm, martinkuba |
| Keywords | console, instrumentation, logging, nodejs, opentelemetry, tracing |

## Links

- npm: https://www.npmjs.com/package/@opentelemetry/instrumentation-console
- Repository: https://github.com/open-telemetry/opentelemetry-js-contrib
- Homepage: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-console#readme
- Issues: https://github.com/open-telemetry/opentelemetry-js-contrib/issues
- npm.io page: https://npm.io/package/@opentelemetry/instrumentation-console

## Dependencies (2)

- [@opentelemetry/api-logs](https://npm.io/package/@opentelemetry/api-logs.md) ^0.222.0
- [@opentelemetry/instrumentation](https://npm.io/package/@opentelemetry/instrumentation.md) ^0.222.0

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 0.4.0 (latest) — 2026-08-31
- 0.3.0 — 2026-07-23
- 0.2.0 — 2026-07-03

## README

# OpenTelemetry Instrumentation for Node.js Console

[![NPM Published Version][npm-img]][npm-url]
[![Apache License][license-image]][license-image]

This module provides automatic instrumentation for the Node.js [`console`](https://nodejs.org/api/console.html) module, generating OpenTelemetry LogRecords for console method calls (`console.log`, `console.error`, `console.warn`, etc.).

## Installation

```bash
npm install @opentelemetry/instrumentation-console
```

## Supported Versions

- Node.js `^18.19.0 || >=20.6.0`

## Usage

```javascript
const { NodeSDK } = require('@opentelemetry/sdk-node');
const { ConsoleInstrumentation } = require('@opentelemetry/instrumentation-console');

const sdk = new NodeSDK({
  instrumentations: [new ConsoleInstrumentation()],
});
sdk.start();

// Now console calls will generate LogRecords
console.log('Hello, world!');    // severity: INFO
console.warn('Watch out!');      // severity: WARN
console.error('Something bad');  // severity: ERROR
```

## Console Methods Instrumented

| Console Method   | Severity Number | Severity Text |
| ---------------- | --------------- | ------------- |
| `console.trace`  | TRACE           | trace         |
| `console.debug`  | DEBUG           | debug         |
| `console.log`    | INFO            | info          |
| `console.info`   | INFO            | info          |
| `console.warn`   | WARN            | warn          |
| `console.error`  | ERROR           | error         |
| `console.dir`    | INFO            | info          |

## Configuration

| Option                  | Type                  | Default | Description                                                        |
| ----------------------- | --------------------- | ------- | ------------------------------------------------------------------ |
| `logSeverity`           | `SeverityNumber`      | —       | Minimum severity level; only logs at or above this level are sent  |

## Trace Context Correlation

When a console method is called within an active span context, the emitted
LogRecord is associated with that context. The OpenTelemetry Logs SDK uses this
to populate the LogRecord's `spanContext` (trace ID, span ID, and trace flags),
so exported log records can be correlated with their originating trace.

## Important: Infinite Loop Prevention

This instrumentation requires `@opentelemetry/api >= 1.9.1`. Starting from that version, the `DiagConsoleLogger` saves references to the original `console` methods at module load time, so internal OTel diagnostic logging bypasses the instrumentation and avoids infinite loops.

Additionally, this instrumentation includes a re-entrancy guard to prevent loops from exporters that write to the console (e.g., `ConsoleLogRecordExporter`).

> **Note:** Avoid using `ConsoleLogRecordExporter` or `ConsoleSpanExporter` together with this instrumentation in production. Use network-based exporters (e.g., OTLP) instead.

## 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][discussions-url]

## License

Apache 2.0 - See [LICENSE][license-url] for more information.

[discussions-url]: https://github.com/open-telemetry/opentelemetry-js/discussions
[license-url]: https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/LICENSE
[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat
[npm-url]: https://www.npmjs.com/package/@opentelemetry/instrumentation-console
[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Finstrumentation-console.svg

---
_Source: https://npm.io/package/@opentelemetry/instrumentation-console · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
