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 🙏

© 2024 – Pkg Stats / Ryan Hefner

otel-agent-nodejs

v1.0.5

Published

This package provides a reusable OpenTelemetry agent for Node.js applications. It simplifies the process of setting up distributed tracing and metrics collection by allowing developers to quickly integrate OpenTelemetry into their projects with minimal co

Downloads

39,661

Readme

Node.js OpenTelemetry Agent

otel-agent-nodejs is a reusable OpenTelemetry agent for Node.js applications, designed to simplify the setup of distributed tracing and metrics collection. This package allows developers to quickly integrate OpenTelemetry into their projects with minimal configuration.

Features

  • Automatic Instrumentation: Instruments popular Node.js libraries such as HTTP, Express, and more, without requiring changes to your application code.
  • Trace and Metrics Export: Captures both traces and metrics and exports them using the OTLP (OpenTelemetry Protocol) in Protobuf format.
  • Easy Integration: Simply add the package to your Dockerfile, configure NODE_OPTIONS, and set environment variables.
  • Customizable: Allows specification of custom OTLP endpoints and other OpenTelemetry configurations via environment variables.

Installation

You can install the otel-agent-nodejs package via NPM:

npm install otel-agent-nodejs

Usage

To use the OpenTelemetry agent in your Node.js application, follow these steps:

1. Update Your Dockerfile

Add the following lines to your Dockerfile to install and configure the OpenTelemetry agent:

FROM node:20

WORKDIR /app

COPY package*.json ./
RUN npm install

# Install the OpenTelemetry agent
RUN npm install otel-agent-nodejs

COPY . .

# Set NODE_OPTIONS to preload the agent before the application starts
ENV NODE_OPTIONS="--require otel-agent-nodejs"

EXPOSE 3000

CMD ["node", "index.js"]

2. Configure Environment Variables

In your docker-compose.yml or directly in the environment where your application runs, configure the necessary environment variables:

services:
  app:
    build: .
    ports:
      - "3000:3000"
    environment:
      - OTEL_SERVICE_NAME=nodejs-otel-agent
      - OTEL_TRACES_EXPORTER=otlp
      - OTEL_METRICS_EXPORTER=otlp
      - OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://otel-collector:4318/v1/traces
      - OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=http://otel-collector:4318/v1/metrics

3. Run Your Application

Build and run your Docker container as usual. The OpenTelemetry agent will automatically start and instrument your application:

docker-compose up --build

Customization

You can customize the behavior of the OpenTelemetry agent by setting additional environment variables:

  • OTEL_SERVICE_NAME: This variable sets the name of your service in the OpenTelemetry traces. It's crucial for identifying which service generated which traces.
  • OTEL_TRACES_EXPORTER: Specifies the exporter to be used for sending trace data. Here, it's set to otlp (OpenTelemetry Protocol).
  • OTEL_METRICS_EXPORTER: Specifies the exporter for sending metrics data, also set to otlp.
  • OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: Defines the endpoint where the OpenTelemetry collector is running. This is where the traces are sent.
  • OTEL_EXPORTER_OTLP_METRICS_ENDPOINT: Defines the endpoint where the OpenTelemetry collector is running. This is where the metrics are sent.

Example Project

For a complete example project that uses otel-agent-nodejs, refer to the example repository on GitHub.

Contributing

Contributions are welcome! Please open an issue or submit a pull request if you have any improvements or new features you'd like to see.

License

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