|
3 | 3 | [![NPM Published Version][npm-img]][npm-url]
|
4 | 4 | [![Apache License][license-image]][license-url]
|
5 | 5 |
|
6 |
| -This module provides a simple way to initialize multiple Node instrumentations. |
| 6 | +## About |
| 7 | + |
| 8 | +This module provides a way to auto instrument any Node application to capture telemetry from a number of popular libraries and frameworks. |
| 9 | +You can export the telemetry data in a variety of formats. Exporters, samplers, and more can be configured via [environment variables][env-var-url]. |
| 10 | +The net result is the ability to gather telemetry data from a Node application without any code changes. |
| 11 | + |
| 12 | +This module also provides a simple way to manually initialize multiple Node instrumentations for use with the OpenTelemetry SDK. |
7 | 13 |
|
8 | 14 | Compatible with OpenTelemetry JS API and SDK `1.0+`.
|
9 | 15 |
|
10 | 16 | ## Installation
|
11 | 17 |
|
12 | 18 | ```bash
|
| 19 | +npm install --save @opentelemetry/api |
13 | 20 | npm install --save @opentelemetry/auto-instrumentations-node
|
14 | 21 | ```
|
15 | 22 |
|
16 |
| -## Usage |
| 23 | +## Usage: Auto Instrumentation |
| 24 | + |
| 25 | +This module includes auto instrumentation for all supported instrumentations and [all available data exporters][exporter-url]. |
| 26 | +It provides a completely automatic, out-of-the-box experience. |
| 27 | +Please see the [Supported Instrumentations](#supported-instrumentations) section for more information. |
| 28 | + |
| 29 | +Enable auto instrumentation by requiring this module using the [--require flag][require-url]: |
| 30 | + |
| 31 | +```shell |
| 32 | +node --require '@opentelemetry/auto-instrumentations-node/register' app.js |
| 33 | +``` |
| 34 | + |
| 35 | +If your Node application is encapsulated in a complex run script, you can also set it via an environment variable before running Node. |
| 36 | + |
| 37 | +```shell |
| 38 | +env NODE_OPTIONS="--require @opentelemetry/auto-instrumentations-node/register" |
| 39 | +``` |
| 40 | + |
| 41 | +The module is highly configurable using environment variables. |
| 42 | +Many aspects of the auto instrumentation's behavior can be configured for your needs, such as resource detectors, exporter choice, exporter configuration, trace context propagation headers, and much more. |
| 43 | +Instrumentation configuration is not yet supported through environment variables. Users that require instrumentation configuration must initialize OpenTelemetry programmatically. |
| 44 | + |
| 45 | +```shell |
| 46 | +export OTEL_TRACES_EXPORTER="otlp" |
| 47 | +export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf" |
| 48 | +export OTEL_EXPORTER_OTLP_COMPRESSION="gzip" |
| 49 | +export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="https://your-endpoint" |
| 50 | +export OTEL_EXPORTER_OTLP_HEADERS="x-api-key=your-api-key" |
| 51 | +export OTEL_EXPORTER_OTLP_TRACES_HEADERS="x-api-key=your-api-key" |
| 52 | +export OTEL_RESOURCE_ATTRIBUTES="service.namespace=my-namespace" |
| 53 | +export OTEL_NODE_RESOURCE_DETECTORS="env,host,os" |
| 54 | +export OTEL_SERVICE_NAME="client" |
| 55 | +export NODE_OPTIONS="--require @opentelemetry/auto-instrumentations-node/register" |
| 56 | +node app.js |
| 57 | +``` |
| 58 | + |
| 59 | +By default, all SDK resource detectors are used, but you can use the environment variable OTEL_NODE_RESOURCE_DETECTORS to enable only certain detectors, or completely disable them: |
| 60 | + |
| 61 | +- `env` |
| 62 | +- `host` |
| 63 | +- `os` |
| 64 | +- `process` |
| 65 | +- `container` |
| 66 | +- `alibaba` |
| 67 | +- `aws` |
| 68 | +- `gcp` |
| 69 | +- `all` - enable all resource detectors |
| 70 | +- `none` - disable resource detection |
| 71 | + |
| 72 | +For example, to enable only the `env`, `host` detectors: |
| 73 | + |
| 74 | +```shell |
| 75 | +export OTEL_NODE_RESOURCE_DETECTORS="env,host" |
| 76 | +``` |
| 77 | + |
| 78 | +To enable logging for troubleshooting, set the log level by setting the `OTEL_LOG_LEVEL` environment variable to one of the following: |
| 79 | + |
| 80 | +- `none` |
| 81 | +- `error` |
| 82 | +- `warn` |
| 83 | +- `info` |
| 84 | +- `debug` |
| 85 | +- `verbose` |
| 86 | +- `all` |
| 87 | + |
| 88 | +The default level is `info`. |
| 89 | + |
| 90 | +Notes: |
| 91 | + |
| 92 | +- In a production environment, it is recommended to set `OTEL_LOG_LEVEL`to `info`. |
| 93 | +- Logs are always sent to console, no matter the environment, or debug level. |
| 94 | +- Debug logs are extremely verbose. Enable debug logging only when needed. Debug logging negatively impacts the performance of your application. |
| 95 | + |
| 96 | +## Usage: Instrumentation Initialization |
17 | 97 |
|
18 | 98 | OpenTelemetry Meta Packages for Node automatically loads instrumentations for Node builtin modules and common packages.
|
19 | 99 |
|
@@ -100,3 +180,6 @@ APACHE 2.0 - See [LICENSE][license-url] for more information.
|
100 | 180 | [license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat
|
101 | 181 | [npm-url]: https://www.npmjs.com/package/@opentelemetry/auto-instrumentations-node
|
102 | 182 | [npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fauto-instrumentations-node.svg
|
| 183 | +[env-var-url]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#general-sdk-configuration |
| 184 | +[exporter-url]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#otlp-exporter |
| 185 | +[require-url]: https://nodejs.org/api/cli.html#-r---require-module |
0 commit comments