opentelemetry-js/packages/opentelemetry-node
Daniel Dyla 18c6aa4f19 Named Tracers / Tracer Registry (#582)
* feat: spike of named tracer registry

* chore: mysql/mongo tracer registry support

* fix: lint

* chore: add getTracer back

* chore: change default tracer name to empty string

* fix: lint

* chore: update examples for registry

* chore(tracer-registry): make name required

* chore: lint

* chore: update examples for required tracer name

* chore: remove unused tracer delegate

* chore: remove references to basic tracer

* chore: remove references to NodeTracer

* chore: update xhr for tracer registry

* chore: update tracer names to match package names

* chore: add version script to all packages

* chore: update plugins to use version script

* chore: add jsdoc to noop tracer registry

* chore: update ioredis for tracer registry

* chore: update pg pool for tracer registry

* fix: lint

* chore: fix tests

* chore: lint

* chore: lint

Co-authored-by: Mayur Kale <mayurkale@google.com>
2020-01-09 08:29:38 -08:00
..
src Named Tracers / Tracer Registry (#582) 2020-01-09 08:29:38 -08:00
test Named Tracers / Tracer Registry (#582) 2020-01-09 08:29:38 -08:00
.gitignore Refactor: Consistent package naming and structure (#413) 2019-10-08 22:01:47 +02:00
.npmignore Refactor: Consistent package naming and structure (#413) 2019-10-08 22:01:47 +02:00
LICENSE Refactor: Consistent package naming and structure (#413) 2019-10-08 22:01:47 +02:00
README.md Named Tracers / Tracer Registry (#582) 2020-01-09 08:29:38 -08:00
package.json chore: 0.3.2 (patch) release proposal (#659) 2020-01-03 12:27:10 -08:00
tsconfig.json Refactor: Consistent package naming and structure (#413) 2019-10-08 22:01:47 +02:00
tslint.json Refactor: Consistent package naming and structure (#413) 2019-10-08 22:01:47 +02:00

README.md

OpenTelemetry Node

Gitter chat NPM Published Version 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 NodeTracerRegistry that will automatically hook into the module loader of Node.js.

For this to work, please make sure that NodeTracerRegistry 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 NodeTracerRegistry 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, NodeTracerRegistry 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 NodeTracerRegistry to instrument http using @opentelemetry/plugin-http.

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

// Create and configure NodeTracerRegistry
const registry = new NodeTracerRegistry({
  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 registry
opentelemetry.initGlobalTracerRegistry(registry);

// 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 NodeTracerRegistry without providing any plugin configuration to the constructor.

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

// Create and initialize NodeTracerRegistry
const registry = new NodeTracerRegistry();

// Initialize the registry
opentelemetry.initGlobalTracerRegistry(registry);

// Your application code
// ...

Examples

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

License

Apache 2.0 - See LICENSE for more information.