Skip to content

Commit dfb841f

Browse files
authored
docs(otel-node): add docs drafts (#136)
1 parent 99e951e commit dfb841f

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Introduction
2+
3+
This is the Elastic OpenTelemetry Distribution for Node.js (the "Distro"). It is
4+
a Node.js package that provides:
5+
- easy way to instrument your application with OpenTelemetry
6+
- configuration defaults for best usage
7+
8+
Use the Distro to start the OpenTelemetry SDK with your Node.js application to automatically
9+
capture tracing data, performance metrics, and logs. Traces, metrics, and logs are sent
10+
to any OTLP collector you choose. Use an [Elastic Observability](https://www.elastic.co/observability)
11+
deployment -- hosted in Elastic's cloud or on-premises -- to monitor your applications, create alerts,
12+
and quickly identify root causes of service issues.
13+
14+
15+
# Getting Started
16+
17+
This getting started guide will show how to use this Distro to instrument your Node.js application and send OpenTelemetry data to an Elastic Observability deployment. Note, however, that as an OpenTelemetry SDK, it supports sending data to any OTLP endpoint, e.g. an [OpenTelemetry Collector](https://opentelemetry.io/docs/collector/).
18+
19+
An Elastic Observability deployment includes an OTLP endpoint to receive data. That data is processed and stored in Elasticsearch, and Kibana provides a web interface to visualize and analyze the date. If you do not already have
20+
a deployment to use, follow [this Quick Start guide](https://www.elastic.co/blog/getting-started-with-elastic-cloud)
21+
to create a free trial on Elastic's cloud. From this deployment you will need
22+
the APM **`serverUrl`** and a configured **`apmAgentKey`** to use for configuring the SDK distribution.
23+
24+
## Installation
25+
26+
```sh
27+
npm install --save @elastic/opentelemetry-node
28+
```
29+
30+
## Initialization
31+
32+
It’s important that the agent is started before you require **any** other modules
33+
in your Node.js application - i.e. before express, http, etc.
34+
35+
The preferred way to get the SDK started is by using the `--require`
36+
Node.js [CLI option](https://nodejs.org/api/cli.html#-r---require-module).
37+
38+
```sh
39+
node --require @elastic/opentelemetry-node app.js
40+
```
41+
42+
## Configuration
43+
44+
By default the SDK will send telemetry data via OpenTelemetry's protocol (OTLP)
45+
to the configured endpoint (by default it sends to <http://localhost:4317>). The
46+
endpoint configuration can be changed by setting the following environment vars:
47+
48+
- `OTEL_EXPORTER_OTLP_ENDPOINT`: full URL of the endpoint where to send the data.
49+
- `OTEL_EXPORTER_OTLP_HEADERS`: coma separated list of `key=value` pairs which will
50+
be added to the headers of every request.
51+
52+
53+
As an example if you want to send telemetry data to your Elastic's APM deployment you
54+
may start the application like this
55+
56+
```sh
57+
export OTEL_EXPORTER_OTLP_ENDPOINT="https://apm-server-url.co"
58+
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=ApiKey VnVhQ2ZHY0JDZGJr..."
59+
node -r @elastic/opentelemetry-node/start.js my-app.js
60+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Metrics
2+
3+
## Enabled by default
4+
5+
In this distribution metrics are enabled by default and sent to the endpoint
6+
configured by you. If you wish to disable metrics you can by setting the env
7+
variable `ELASTIC_OTEL_METRICS_DISABLED` to the string `true`.
8+
9+
```sh
10+
export ELASTIC_APM_SERVER_URL="https://apm-server-host.co"
11+
export ELASTIC_APM_SECRET_TOKEN="secret_token"
12+
export OTEL_EXPORTER_OTLP_ENDPOINT="${ELASTIC_APM_SERVER_URL}"
13+
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer ${ELASTIC_APM_SECRET_TOKEN}"
14+
export ELASTIC_OTEL_METRICS_DISABLED=true
15+
node -r @elastic/opentelemetry-node/start.js my-app.js
16+
```
17+
18+
## Advanced Configuration
19+
20+
You can tune how often metrics data is exported to the endpoint and the max time
21+
to export data you can use the env vars already defined in [the spec](https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#periodic-exporting-metricreader).
22+
23+
## Host metrics
24+
25+
Elastic OpenTelemetry Node.js Distribution also gathers metrics from the host
26+
machine with `@opentelemetry/host-metrics` pacakge.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Supported Technologies
2+
3+
## Elastic and Opentelemetry protocol(OTLP)
4+
5+
Since version 7.14, Elastic [supports OTLP natively](https://www.elastic.co/blog/native-opentelemetry-support-in-elastic-observability).
6+
7+
## Node.js versions
8+
9+
The Elastic OpenTelemety Node.js Distribution supports Node.js v14 and later.
10+
This follows from the [OpenTelemetry JS supported runtimes](https://github.com/open-telemetry/opentelemetry-js#supported-runtimes).
11+
12+
## Instrumentations
13+
14+
| Name | Short description | Reference |
15+
| `@opentelemetry/instrumentation-http` | Instruments Node.js `http` module for all supported versions |[README](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-http#readme) |
16+
| `@opentelemetry/instrumentation-express` | Instruments `express` package for version range `^4.0.0` | [README](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-express#readme) |
17+
| `@opentelemetry/instrumentation-fastify` | Instruments `fastify` package for version range `>=3 <5` | [README](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-fastify#readme) |
18+
| `@opentelemetry/instrumentation-ioredis` | Instruments `ioredis` package for version range `>=2 <6` | [README](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-ioredis#readme) |
19+
| `@opentelemetry/instrumentation-pg` | Instruments `pg` package for version range `>=8 <9` | [README](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-pg#readme) |
20+
| `@opentelemetry/instrumentation-mongodb` | Instruments `mongodb` package for version range `>=3.3 <7` | [README](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mongodb#readme) |
21+
| `@opentelemetry/instrumentation-bunyan` | Instruments `bunyan` package for version range `^1.0.0` | [README](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-bunyan#readme) |
22+
| `@opentelemetry/instrumentation-winston` | Instruments `winston` package for version range `>1 <4` | [README](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-winston#readme) |
23+
| `@opentelemetry/instrumentation-tedious` | Instruments `tedious` package for version range `>=1.11.0 <=15` | [README](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-tedious#readme) |
24+
| `@opentelemetry/instrumentation-undici` | Instruments `undici` package for version range `>=5.12.0` | [README](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-undici#readme) |
25+
26+
## ECMAScript Modules (ESM)
27+
28+
This distro includes *limited and experimental* support for instrumenting [ECMAScript module imports](https://nodejs.org/api/esm.html#modules-ecmascript-modules), i.e. modules that are loaded via `import ...` statements and `import('...')` (dynamic import).
29+
30+
<!-- TODO: add this to the above paragraph once we have an esm.md doc:
31+
See the [ECMAScript module support](./esm.md) document for details.
32+
-->
33+
34+
Limitations:
35+
- For Node.js `>=20.6.0 || >=18.19.0`, support for hooking `import`s is automatically enabled. For earlier versions of Node.js, you must manually enable the `import`-hook via the `--experimental-loader=@elastic/opentelemetry-node/hook.mjs` option, e.g.: `node --experimental-loader=@elastic/opentelemetry-node/hook.mjs --require=@elastic/opentelemetry-node app.js`.
36+
- Currently only a subset of instrumentations support ESM: `express`, `ioredis`, `koa`, `pg`, `pino`. See [this OpenTelemetry JS tracking issue](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1942) for progress.
37+
-

0 commit comments

Comments
 (0)