npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@voiceowl/otel-node-lib

v1.0.4

Published

Reusable OpenTelemetry library for Node.js microservices with Datadog integration

Readme

Voiceowl OpenTelemetry Library for Node.js

NPM Version License

The @voiceowl/otel-node-lib package provides a reusable OpenTelemetry library for Node.js microservices, designed for seamless integration with observability platforms like Datadog. It simplifies the process of instrumenting your application for distributed tracing, metrics, and logging.

Features

  • Zero-config setup: Get started quickly with a single initialization function.
  • Automatic instrumentation: Automatically instruments popular Node.js libraries (e.g., Express, HTTP, DNS).
  • Distributed tracing: Trace requests across multiple services to identify performance bottlenecks.
  • Custom metrics: Capture application-specific metrics to monitor key performance indicators (KPIs).
  • Structured logging: Enrich your logs with trace and span IDs for easy correlation.
  • Express middleware: Provides middleware for request tracing, error handling, and request ID generation.

Installation

Install the package using npm:

npm install @voiceowl/otel-node-lib

Quick Start

The quickSetup function provides a simple way to initialize tracing, metrics, and logging with minimal configuration.

// src/index.ts
import { quickSetup } from '@voiceowl/otel-node-lib';

const { sdk, logger, metrics } = quickSetup({
  serviceName: 'my-awesome-service',
  otelCollectorUrl: 'http://localhost:4318', // OTLP/HTTP endpoint
});

// Your application logic here...

// Example of logging with trace context
logger.info('User logged in successfully', { userId: '123' });

// Example of a custom metric
const requestCounter = metrics.getCounter('http.requests.total');
requestCounter.add(1, { route: '/login' });

// Gracefully shut down the SDK on exit
process.on('SIGTERM', () => {
  sdk.shutdown()
    .then(() => console.log('Tracing terminated'))
    .catch((error) => console.error('Error terminating tracing', error))
    .finally(() => process.exit(0));
});

Usage

Tracing

The initializeTracing function initializes the OpenTelemetry SDK for distributed tracing.

import { initializeTracing, shutdownTracing } from '@voiceowl/otel-node-lib';

const sdk = initializeTracing({
  serviceName: 'my-service',
  otelCollectorUrl: 'http://localhost:4318',
});

// Gracefully shut down the SDK on exit
process.on('SIGTERM', () => {
  shutdownTracing()
    .then(() => console.log('Tracing terminated'))
    .catch((error) => console.error('Error terminating tracing', error))
    .finally(() => process.exit(0));
});

Metrics

The metricsProvider object provides access to the Meter API for creating and recording custom metrics.

import { metricsProvider } from '@voiceowl/otel-node-lib';

const meter = metricsProvider.getMeter('my-app');

const requestCounter = meter.createCounter('http.requests.total');
requestCounter.add(1, { route: '/users' });

const activeUsersGauge = meter.createObservableGauge('active.users');
activeUsersGauge.addCallback((result) => {
  // Fetch the number of active users from your application
  const activeUsers = getActiveUsers();
  result.observe(activeUsers);
});

Logging

The Logger class provides a simple interface for structured logging with trace context injection.

import { Logger, withTracing } from '@voiceowl/otel-node-lib';

const logger = new Logger('my-service');

// Logs with trace and span IDs
logger.info('User created successfully', { userId: '456' });
logger.error('Failed to process payment', { error: 'Insufficient funds' });

// Manually wrap a function with a new span
async function processOrder() {
  return withTracing('processOrder', async (span) => {
    // Your business logic here
    span.setAttribute('orderId', '789');
    logger.info('Processing order...');
  });
}

Middleware (for Express.js)

The library includes middleware for Express.js applications to simplify request tracing and error handling.

import express from 'express';
import { tracingMiddleware, errorTracingMiddleware, requestIdMiddleware } from '@voiceowl/otel-node-lib';

const app = express();

// Add request ID to all incoming requests
app.use(requestIdMiddleware());

// Enable tracing for all routes
app.use(tracingMiddleware({ serviceName: 'my-express-app' }));

app.get('/', (req, res) => {
  res.send('Hello World!');
});

// Add the error tracing middleware after all your routes
app.use(errorTracingMiddleware());

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Configuration

The initializeTracing and quickSetup functions accept a configuration object with the following options:

| Option | Type | Description | Default | | ------------------ | -------- | ------------------------------------------------------------------------------------------------------- | ------------------------------ | | serviceName | string | Required. The name of your service or application. | - | | otelCollectorUrl | string | The URL of your OpenTelemetry Collector (OTLP/HTTP or OTLP/gRPC). | http://localhost:4318 | | logLevel | LogLevel | The minimum log level to capture. | LogLevel.INFO | | instrumentations | any[] | An array of additional OpenTelemetry instrumentations to register. | [getNodeAutoInstrumentations()] |

Contributing

Contributions are welcome! Please open an issue or submit a pull request on our GitHub repository.

License

This project is licensed under the MIT License. See the LICENSE file for details.