|
1 |
| -# Elastic OpenTelemetry Node.js Distribution |
| 1 | +# Elastic OpenTelemetry Distribution for Node.js |
2 | 2 |
|
3 |
| -This is the Elastic OpenTelemetry Node.js Distribution. It is a light wrapper |
4 |
| -around the OpenTelemetry Node SDK that makes it easier to get started using |
5 |
| -OpenTelemetry in your Node.js applications, especially if you are using [Elastic |
6 |
| -Observability](https://www.elastic.co/observability) as your observability |
7 |
| -solution. |
| 3 | +This is the Elastic OpenTelemetry Distribution for Node.js (the "Distro"). |
| 4 | +It is a light wrapper around the OpenTelemetry Node SDK that makes it easier to |
| 5 | +get started using OpenTelemetry in your Node.js applications, especially if you |
| 6 | +are using [Elastic Observability](https://www.elastic.co/observability) as your |
| 7 | +observability solution. |
8 | 8 |
|
9 |
| -# Current status |
10 |
| - |
11 |
| -Pre-alpha |
12 |
| - |
13 |
| -# Install |
14 | 9 |
|
15 |
| -Eventually this will be `npm install @elastic/opentelemetry-node`. |
16 |
| -However, while still in early development, this package is not yet published |
17 |
| -to npm, so you'll need to access it via git: |
18 |
| - |
19 |
| - git clone https://github.com/elastic/elastic-otel-node.git |
20 |
| - cd elastic-otel-node/ |
21 |
| - npm ci |
22 |
| - |
23 |
| -and then install the package sub-directory: |
| 10 | +# Current status |
24 | 11 |
|
25 |
| - npm install .../elastic-otel-node/packages/opentelemetry-node |
| 12 | +The current release is **alpha**, and not yet recommended for production use. |
| 13 | +We welcome your feedback! You can reach us either on the [issue tracker](https://github.com/elastic/elastic-otel-node/issues) |
| 14 | +or on [Elastic's Discuss forum](https://discuss.elastic.co/tags/c/observability/apm/58/nodejs). |
26 | 15 |
|
27 |
| -(TODO: update ^^ once published to npm.) |
| 16 | +Some limitations / notes: |
| 17 | +- We expect to support most every instrumentation included in [`@opentelemetry/auto-instrumentations-node`](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/metapackages/auto-instrumentations-node#supported-instrumentations). However, currently only a subset is supported. See [the supported instrumentations here](./docs/supported-technologies.md#instrumentations). |
28 | 18 |
|
29 | 19 |
|
30 | 20 | # Usage
|
31 | 21 |
|
32 |
| -To start the SDK, it must be loaded before any of your application code. The |
33 |
| -recommended way to do that is via Node.js's [`-r, --require` |
34 |
| -option](https://nodejs.org/api/all.html#all_cli_-r---require-module): |
35 |
| - |
36 |
| - node -r @elastic/opentelemetry-node my-app.js |
37 |
| - |
38 |
| -TODO: Link to coming user guide for related topics: ES module support, configuration reference, starting the SDK via |
39 |
| - |
40 |
| - |
41 |
| -# Configuring your telemetry endpoint |
42 |
| - |
43 |
| -By default the SDK will send telemetry data via OpenTelemetry's protocol (OTLP) |
44 |
| -to the configured endpoint (by default it sends to <http://localhost:4317>): |
45 |
| - |
46 |
| - OTEL_EXPORTER_OTLP_ENDPOINT=... \ |
47 |
| - OTEL_EXPORTER_OTLP_HEADERS=... \ |
48 |
| - node -r @elastic/opentelemetry-node my-app.js |
49 |
| - |
50 |
| -You can send to any OTLP endpoint, for example: an [OTel Collector](https://opentelemetry.io/docs/collector/), |
51 |
| -or directly to an Elastic Observability deployment. Since version 7.14, Elastic |
52 |
| -[supports OTLP natively](https://www.elastic.co/blog/native-opentelemetry-support-in-elastic-observability). |
| 22 | +```sh |
| 23 | +# 1. install |
| 24 | +npm install --save @elastic/opentelemetry-node |
53 | 25 |
|
| 26 | +# 2. configure via OTEL_ envvars, for example: |
| 27 | +export OTEL_EXPORTER_OTLP_ENDPOINT=https://{your-otlp-endpoint.example.com} |
| 28 | +export OTEL_EXPORTER_OTLP_HEADERS="Authorization={authorization-information}" |
| 29 | +export OTEL_SERVICE_NAME=my-service |
54 | 30 |
|
55 |
| -### Elastic Observability endpoint |
| 31 | +# 3. start |
| 32 | +node -r @elastic/opentelemetry-node my-service.js |
| 33 | +``` |
56 | 34 |
|
57 |
| -First, you will need an Elastic APM deployment. See: https://www.elastic.co/guide/en/apm/guide/current/apm-quick-start.html |
58 |
| -You will need two pieces of information: the APM **server URL** (this is the OTLP endpoint) and your APM **secret code** (or **API key** if using API keys). |
59 |
| -Then configure your |
| 35 | +If using an [Elastic Observability deployment](./docs/getting-started.md#elastic-observability-setup) |
| 36 | +to which to send telemetry data, the `OTEL_EXPORTER_*` settings will look |
| 37 | +something like: |
60 | 38 |
|
61 | 39 | ```sh
|
62 |
| -export OTEL_EXPORTER_OTLP_ENDPOINT="${ELASTIC_APM_SERVER_URL}" |
63 |
| -export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer ${ELASTIC_APM_SECRET_TOKEN}" |
64 |
| -node -r @elastic/opentelemetry-node my-app.js |
| 40 | +export OTEL_EXPORTER_OTLP_ENDPOINT=https://{deployment-name}.apm.{cloud-region}.cloud.es.io |
| 41 | +export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer {deployment-secret-token}" |
65 | 42 | ```
|
66 | 43 |
|
67 |
| -Or if using an API key, then: |
| 44 | +The Distro will automatically instrument popular modules (see [supported instrumentations](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/metapackages/auto-instrumentations-node#supported-instrumentations))) |
| 45 | +used by your service, and send trace, metrics, and logs telemetry data (using |
| 46 | +OTLP) to your configured observability backend. |
68 | 47 |
|
69 |
| -```sh |
70 |
| -export OTEL_EXPORTER_OTLP_ENDPOINT="${ELASTIC_APM_SERVER_URL}" |
71 |
| -export OTEL_EXPORTER_OTLP_HEADERS="Authorization=ApiKey ${ELASTIC_APM_API_KEY}" |
72 |
| -node -r @elastic/opentelemetry-node my-app.js |
73 |
| -``` |
| 48 | +The Distro can be configured via `OTEL_*` environment variables, per the |
| 49 | +[OpenTelemetry Environment Variable spec](https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/). |
74 | 50 |
|
| 51 | +See the [Getting Started guide](./docs/getting-started.md) for more details. |
75 | 52 |
|
76 |
| -### mockotlpserver endpoint |
77 | 53 |
|
78 |
| -TODO: move this out to dev docs |
| 54 | +# Documentation |
79 | 55 |
|
80 |
| -If you don't yet have an OTLP endpoint setup and just want to see the SDK |
81 |
| -working, you can run a *mock* OTLP server locally with the `mockotlpserver` |
82 |
| -utility in this repository: |
| 56 | +- [Getting Started](./docs/getting-started.md) |
| 57 | +- [Supported Technologies](./docs/supported-technologies.md) |
| 58 | +- [Metrics](./docs/metrics.md) |
83 | 59 |
|
84 |
| -```sh |
85 |
| -git clone https://github.com/elastic/elastic-otel-node.git |
86 |
| -cd elastic-otel-node/ |
87 |
| -npm ci |
88 |
| -cd packages/mockotlpserver |
89 |
| -npm start |
90 |
| -``` |
91 | 60 |
|
92 |
| -Now running an application with this SDK will send to the mock endpoint, which |
93 |
| -prints out any received telemetry data, for example: |
| 61 | +# Why this distribution? |
94 | 62 |
|
95 |
| -```sh |
96 |
| -cd elastic-otel-node/examples |
97 |
| -node -r @elastic/opentelemetry-node simple-http-request.js |
98 |
| -``` |
| 63 | +As mentioned above, this Distro is a wrapper around the [OpenTelemetry Node |
| 64 | +SDK (`@opentelemetry/sdk-node`)](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-sdk-node). So why the separate package? |
| 65 | +A few reasons: |
| 66 | + |
| 67 | +- With this separate package we hope to experiment with making it easier to get |
| 68 | + started with OpenTelemetry instrumentation in Node.js services. For example, |
| 69 | + `@elastic/opentelemetry-node` includes a number of OTel packages as dependencies, |
| 70 | + so the user only needs to install/update a single package -- at least for the |
| 71 | + default use case. This is similar to the OTel |
| 72 | + `@opentelemetry/auto-instrumentations-node` package. |
99 | 73 |
|
100 |
| -See [the mockotlpserver README](../mockotlpserver#readme) for more details. |
| 74 | +- Having a separate package will sometimes allow us to iterate more quickly with |
| 75 | + changes in SDK behavior. However, our plan is to upstream any improvements to |
| 76 | + the OpenTelemetry JS repositories. |
101 | 77 |
|
| 78 | +- Should it be necessary, having a separate package would allow us to more |
| 79 | + quickly release a fix for a particular issue required by a customer of ours. |
102 | 80 |
|
| 81 | +- Providing an eventual easy migration path for customers of our current |
| 82 | + non-OpenTelemetry-based [Node.js APM agent](https://github.com/elastic/apm-agent-nodejs) |
| 83 | + to this SDK may be made easier by having our own package entry point. |
103 | 84 |
|
0 commit comments