Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@opentelemetry/node

Package Overview
Dependencies
Maintainers
2
Versions
153
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/node

OpenTelemetry Node SDK provides automatic telemetry (tracing, metrics, etc) for Node.js applications

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
30K
increased by2.21%
Maintainers
2
Weekly downloads
 
Created
Source

OpenTelemetry Node

Gitter chat dependencies devDependencies Apache License

This module provides automated instrumentation and tracing for Node.js applications.

For manual instrumentation see the @opentelemetry/tracing package.

How does automated instrumentation work?

This package exposes a NodeTracer that will automatically hook into the module loader of Node.js.

For this to work, please make sure that NodeTracer is initialized before any other module of your application, (like http or express) is loaded.

OpenTelemetry comes with a growing number of instrumentation plugins for well know modules (see supported modules) and an API to create custom plugins (see the plugin developer guide).

Whenever a module is loaded NodeTracer will check if a matching instrumentation plugin has been installed.

Please note: This module does not bundle any plugins. They need to be installed separately.

If the respective plugin was found, it will be used to patch the original module to add instrumentation code. This is done by wrapping all tracing-relevant functions.

This instrumentation code will automatically

  • extract a trace-context identifier from inbound requests to allow distributed tracing (if applicable)
  • make sure that this current trace-context is propagated while the transaction traverses an application (see @opentelemetry/opentelemetry-scope-base for an in-depth explanation)
  • add this trace-context identifier to outbound requests to allow continuing the distributed trace on the next hop (if applicable)
  • create and end spans

In short, this means that this module will use provided plugins to automatically instrument your application to produce spans and provide end-to-end tracing by just adding a few lines of code.

Creating custom spans on top of auto-instrumentation

Additionally to automated instrumentation, NodeTracer exposes the same API as @opentelemetry/tracing, allowing creating custom spans if needed.

Installation

npm install --save @opentelemetry/core
npm install --save @opentelemetry/node

# Install instrumentation plugins
npm install --save @opentelemetry/plugin-http
npm install --save @opentelemetry/plugin-grpc
npm install --save @opentelemetry/plugin-https

Usage

The following code will configure the NodeTracer to instrument http using @opentelemetry/plugin-http.

const opentelemetry = require('@opentelemetry/core');
const { NodeTracer } = require('@opentelemetry/node');

// Create and configure NodeTracer
const tracer = new NodeTracer({
  plugins: {
    http: {
      enabled: true,
      // You may use a package name or absolute path to the file.
      path: '@opentelemetry/plugin-http',
      // http plugin options
    }
  }
});

// Initialize the tracer
opentelemetry.initGlobalTracer(tracer);

// Your application code - http will automatically be instrumented if
// @opentelemetry/plugin-http is present
const http = require('http');

To enable instrumentation for all supported modules, create an instance of NodeTracer without providing any plugin configuration to the constructor.

const opentelemetry = require('@opentelemetry/core');
const { NodeTracer } = require('@opentelemetry/node');

// Create and initialize NodeTracer
const tracer = new NodeTracer();

// Initialize the tracer
opentelemetry.initGlobalTracer(tracer);

// Your application code
// ...

Examples

See how to automatically instrument http and gRPC using node-sdk.

License

Apache 2.0 - See LICENSE for more information.

Keywords

FAQs

Package last updated on 08 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc