2.0.1 • Published 5 months ago

@opentelemetry/sdk-trace-node v2.0.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
5 months ago

OpenTelemetry Node SDK

NPM Published Version Apache License

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

For manual instrumentation see the @opentelemetry/sdk-trace-base package.

Note: Much of OpenTelemetry JS documentation is written assuming the compiled application is run as CommonJS. For more details on ECMAScript Modules vs CommonJS, refer to esm-support.

How auto instrumentation works

This package exposes a NodeTracerProvider. For loading instrumentations please use registerInstrumentations function from opentelemetry-instrumentation

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

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

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 context document in @opentelemetry/api 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

Creating custom spans on top of auto-instrumentation

Additionally to automated instrumentation, NodeTracerProvider exposes the same API as @opentelemetry/sdk-trace-base, allowing creating custom spans if needed.

Installation

npm install --save @opentelemetry/api
npm install --save @opentelemetry/sdk-trace-node

# Install instrumentation plugins
npm install --save @opentelemetry/instrumentation-http
# and for example one additional
npm install --save @opentelemetry/instrumentation-graphql

Usage

The following code will configure the NodeTracerProvider to instrument http (and any other installed supported modules) using @opentelemetry/plugin-http.

const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');

// Create and configure NodeTracerProvider
const provider = new NodeTracerProvider();

// Initialize the provider
provider.register();

// register and load instrumentation and old plugins - old plugins will be loaded automatically as previously
// but instrumentations needs to be added
registerInstrumentations({
});

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

Instrumentation configuration

In the following example:

  • the express instrumentation is enabled
  • the http instrumentation has a custom config for a requestHook
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http');
const { ExpressInstrumentation } = require('@opentelemetry/instrumentation-express');

const provider = new NodeTracerProvider();
provider.register();

// register and load instrumentation and old plugins - old plugins will be loaded automatically as previously
// but instrumentations needs to be added
registerInstrumentations({
  instrumentations: [
    new ExpressInstrumentation(),
    new HttpInstrumentation({
        requestHook: (span, request) => {
          span.setAttribute("custom request hook attribute", "request");
        },
    }),
  ],
});

Examples

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

Useful links

License

Apache 2.0 - See LICENSE for more information.

lib-tracingnotnodeagentlog-util-win-otel-final@middleware.io/mw-node-apmsalesforce-opentelemetry@wesjet/utils@chanzuckerberg/edu-platform-observabilitygodspeed-noderenovate@everything-registry/sub-chunk-690@turnly/observabilitytaskherowrapperopentelemetrysubito-libsupergraph-demo-opentelemetry@bondsports/telemetry@routr/processor@routr/registry@routr/rtprelay@routr/sdk@routr/simpleauth@routr/simpledata@routr/common@routr/connect@routr/dispatcher@routr/echo@routr/location@routr/pgdata@pothos-examples/open-telemetry@prairielearn/opentelemetryiudexjsexpert-libkettle-corehumanloopinfrastack-interview-fs-bsinfrastack-interview-fs-mkiherokuhelios-opentelemetry-sdklightstep-opentelemetry-launcher-nodelight-flow-js-sdkmalabilogzio-nodejslog-winston-elk-util@wesjet/function.js@wesjetpkg/utils@wundergraph/sdk@tykevision/agent@teleflow/application-generic@tinybudgie/opentelemetry@tramvai/module-opentelemetry@tezos-dappetizer/utils@transcend-io/pulumi@trigger.dev/core@uoa/lambda-tracing@vizydrop/tracer@usepreflight/next@usepreflight/trace@zalastax/nolb-_opentall-backend-commonaliaydin-opentelemetry@zion-market/utilsactive-traceraspecto-malabiapplicationinsightsaperture-sdkappium-otel-plugin@google-cloud/synthetics-sdk-api@cisco-telescope/auto-instrumentations-node@cisco-telescope/cisco-sdk-node@dynatrace/opentelemetry-core@golemio/core@azure/ai-projects@ckatzorke/renovate@aztec/telemetry-client@azure/monitor-opentelemetry@gyizerhq/loopback4_tracing@acaad/core@hammerbot/instrumentation@aiondigital/opentelemetry@agentpaid/ap-node-client@agentico/mcp-server@ebay/flow-telemetry@adweave/logger@edirect/trace@akinon/next@codecov/node-codecov-opentelemetry@codefresh-io/cf-telemetry@aisynapze/traces-typescript-sdk@continual/sdk@contentlayer-temp/utils@contentlayer/utils@contentlayer2/utils@coozzy/tracing@cornie-js/backend-monitoring@cran/lib.node.telemetry@collabland/open-telemetry@alerty/core@coze-loop/ai@cozeloop/ai@coog/otel-node-tracer
2.0.1

5 months ago

2.0.0

7 months ago

1.29.0

11 months ago

1.30.0

10 months ago

1.30.1

9 months ago

2.0.0-rc.1

7 months ago

1.28.0

11 months ago

2.0.0-dev.1

8 months ago

2.0.0-dev.0

8 months ago

1.27.0

12 months ago

1.26.0

1 year ago

1.25.0

1 year ago

1.25.1

1 year ago

1.24.1

1 year ago

1.24.0

1 year ago

1.23.0

2 years ago

1.22.0

2 years ago

1.21.0

2 years ago

1.20.0

2 years ago

1.19.0

2 years ago

1.18.1

2 years ago

1.18.0

2 years ago

1.16.0

2 years ago

1.15.0

2 years ago

1.17.1

2 years ago

1.17.0

2 years ago

1.15.2

2 years ago

1.15.1

2 years ago

1.14.0

2 years ago

1.13.0

2 years ago

1.12.0

3 years ago

1.11.0

3 years ago

1.10.1

3 years ago

1.10.0

3 years ago

1.9.1

3 years ago

1.9.0

3 years ago

1.8.0

3 years ago

1.7.0

3 years ago

1.6.0

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.26.0

4 years ago

0.25.1-alpha.23

4 years ago

0.25.1-alpha.16

4 years ago

0.25.1-alpha.12

4 years ago

0.25.1-alpha.13

4 years ago

0.25.1-alpha.7

4 years ago

0.25.1-alpha.1

4 years ago

0.25.1-alpha.2

4 years ago

0.25.1-alpha.4

4 years ago

0.25.0

4 years ago

0.25.1-alpha.21

4 years ago

0.24.1-alpha.20

4 years ago

0.24.1-alpha.18

4 years ago

0.24.1-alpha.14

4 years ago

0.24.1-alpha.7

4 years ago

0.24.1-alpha.9

4 years ago

0.24.1-alpha.8

4 years ago

0.24.1-alpha.5

4 years ago

0.24.1-alpha.4

4 years ago