-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: README refresh and docs update #157
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
This document contains informal notes to help developers of the Elastic APM | ||
Node.js agent. Developers should feel free to aggressively weed out obsolete | ||
notes. For structured developer and contributing *rules and guidelines*, see | ||
[CONTRIBUTING.md](./CONTRIBUTING.md). | ||
|
||
|
||
### mockotlpserver OTLP endpoint | ||
|
||
For local development, it can be useful to have an OTLP endpoint that is local, | ||
and can show the exact details of data being sent by the OTel SDK. The | ||
[mockotlpserver package](./packages/mockotlpserver/) in this repository | ||
provides a CLI tool for this. | ||
|
||
```sh | ||
git clone https://github.com/elastic/elastic-otel-node.git | ||
cd elastic-otel-node/ | ||
npm ci | ||
cd packages/mockotlpserver | ||
npm start -- --help # mockotlpserver CLI options | ||
npm start | ||
``` | ||
|
||
This starts a service listening on the default OTLP/gRPC and OTLP/HTTP ports. | ||
It will print received OTLP request data. By default it shows a raw print of | ||
the protobuf request, e.g.: | ||
|
||
``` | ||
ExportTraceServiceRequest { | ||
resourceSpans: [ | ||
ResourceSpans { | ||
scopeSpans: [ | ||
ScopeSpans { | ||
spans: [ | ||
Span { | ||
attributes: [ | ||
KeyValue { key: 'http.url', value: AnyValue { stringValue: 'http://localhost:3000/' } }, | ||
... | ||
name: 'GET', | ||
kind: 2, | ||
... | ||
``` | ||
|
||
and a "summary" compact representation of the request, e.g.: | ||
|
||
``` | ||
------ trace 802356 (2 spans) ------ | ||
span f06b1a "GET" (15.5ms, SPAN_KIND_CLIENT, GET http://localhost:3000/ -> 200) | ||
+9ms `- span 226bf7 "GET" (4.2ms, SPAN_KIND_SERVER, GET http://localhost:3000/ -> 200) | ||
``` | ||
|
||
Try it with: | ||
|
||
```sh | ||
cd elastic-otel-node/examples | ||
node -r @elastic/opentelemetry-node simple-http-request.js | ||
``` | ||
|
||
See [the mockotlpserver README](./packages/mockotlpserver#readme) for more details. | ||
|
||
|
||
# Logging tips | ||
|
||
## logging | ||
|
||
`OTEL_LOG_LEVEL=verbose` will turn on the most verbose-level logging in the SDK, | ||
including enabling the core OpenTelemetry `diag` logger messages. | ||
|
||
This distro's logging is currently in the JSON format used by the | ||
[`luggite`](https://github.com/trentm/node-luggite) library. It be somewhat | ||
pretty-formatted via the [`pino-pretty` tool](https://github.com/pinojs/pino-pretty): | ||
|
||
OTEL_LOG_LEVEL=verbose node myapp.js | pino-pretty | ||
|
||
One of the important libs in the SDK is [require-in-the-middle](https://github.com/elastic/require-in-the-middle) | ||
for intercepting `require(...)` statements for monkey-patching. You can get | ||
debug output from it via: | ||
|
||
DEBUG=require-in-the-middle | ||
|
||
And don't forget the node core [`NODE_DEBUG` and `NODE_DEBUG_NATIVE`](https://nodejs.org/api/all.html#cli_node_debug_module) | ||
environment variables: | ||
|
||
NODE_DEBUG=* | ||
NODE_DEBUG_NATIVE=* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,73 @@ | ||
# Elastic OpenTelemetry Node.js Distribution | ||
# Elastic OpenTelemetry Distribution for Node.js | ||
|
||
This is the Elastic OpenTelemetry Node.js Distribution. It is a light wrapper | ||
around the OpenTelemetry Node SDK that makes it easier to get started using | ||
OpenTelemetry in your Node.js applications, especially if you are using [Elastic | ||
Observability](https://www.elastic.co/observability) as your observability | ||
solution. | ||
This is the Elastic OpenTelemetry Distribution for Node.js (the "Distro"). | ||
It is a light wrapper around the OpenTelemetry Node SDK that makes it easier to | ||
get started using OpenTelemetry in your Node.js applications, especially if you | ||
are using [Elastic Observability](https://www.elastic.co/observability) as your | ||
observability solution. | ||
|
||
# Current status | ||
|
||
Pre-alpha | ||
|
||
# Install | ||
|
||
Eventually this will be `npm install @elastic/opentelemetry-node`. | ||
However, while still in early development, this package is not yet published | ||
to npm, so you'll need to access it via git: | ||
|
||
git clone https://github.com/elastic/elastic-otel-node.git | ||
cd elastic-otel-node/ | ||
npm ci | ||
|
||
and then install the package sub-directory: | ||
# Current status | ||
|
||
npm install .../elastic-otel-node/packages/opentelemetry-node | ||
The current release is **alpha**, and not yet recommended for production use. | ||
We welcome your feedback! You can reach us either on the [issue tracker](https://github.com/elastic/elastic-otel-node/issues) | ||
or on [Elastic's Discuss forum](https://discuss.elastic.co/tags/c/observability/apm/58/nodejs). | ||
|
||
(TODO: update ^^ once published to npm.) | ||
Some limitations / notes: | ||
- 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). | ||
|
||
|
||
# Usage | ||
|
||
To start the SDK, it must be loaded before any of your application code. The | ||
recommended way to do that is via Node.js's [`-r, --require` | ||
option](https://nodejs.org/api/all.html#all_cli_-r---require-module): | ||
|
||
node -r @elastic/opentelemetry-node my-app.js | ||
|
||
TODO: Link to coming user guide for related topics: ES module support, configuration reference, starting the SDK via | ||
|
||
|
||
# Configuring your telemetry endpoint | ||
|
||
By default the SDK will send telemetry data via OpenTelemetry's protocol (OTLP) | ||
to the configured endpoint (by default it sends to <http://localhost:4317>): | ||
|
||
OTEL_EXPORTER_OTLP_ENDPOINT=... \ | ||
OTEL_EXPORTER_OTLP_HEADERS=... \ | ||
node -r @elastic/opentelemetry-node my-app.js | ||
|
||
You can send to any OTLP endpoint, for example: an [OTel Collector](https://opentelemetry.io/docs/collector/), | ||
or directly to an Elastic Observability deployment. Since version 7.14, Elastic | ||
[supports OTLP natively](https://www.elastic.co/blog/native-opentelemetry-support-in-elastic-observability). | ||
|
||
# 1. install | ||
npm install --save @elastic/opentelemetry-node | ||
|
||
### Elastic Observability endpoint | ||
# 2. configure via OTEL_ envvars, for example: | ||
export OTEL_EXPORTER_OTLP_ENDPOINT=https://{your-otlp-endpoint.example.com} | ||
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer {your-Elastic-secret-token}" | ||
export OTEL_SERVICE_NAME=my-service | ||
|
||
First, you will need an Elastic APM deployment. See: https://www.elastic.co/guide/en/apm/guide/current/apm-quick-start.html | ||
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). | ||
Then configure your | ||
# 3. start | ||
node -r @elastic/opentelemetry-node my-service.js | ||
|
||
```sh | ||
export OTEL_EXPORTER_OTLP_ENDPOINT="${ELASTIC_APM_SERVER_URL}" | ||
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer ${ELASTIC_APM_SECRET_TOKEN}" | ||
node -r @elastic/opentelemetry-node my-app.js | ||
``` | ||
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))) | ||
used by your service, and send trace, metrics, and logs telemetry data (using | ||
OTLP) to your configured observability backend. | ||
|
||
Or if using an API key, then: | ||
The Distro can be configured via `OTEL_*` environment variables, per the | ||
[OpenTelemetry Environment Variable spec](https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/). | ||
|
||
```sh | ||
export OTEL_EXPORTER_OTLP_ENDPOINT="${ELASTIC_APM_SERVER_URL}" | ||
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=ApiKey ${ELASTIC_APM_API_KEY}" | ||
node -r @elastic/opentelemetry-node my-app.js | ||
``` | ||
See the [Getting Started guide](./docs/getting-started.md) for more details. | ||
|
||
|
||
### mockotlpserver endpoint | ||
# Documentation | ||
|
||
TODO: move this out to dev docs | ||
- [Getting Started](./docs/getting-started.md) | ||
- [Supported Technologies](./docs/supported-technologies.md) | ||
- [Metrics](./docs/metrics.md) | ||
|
||
If you don't yet have an OTLP endpoint setup and just want to see the SDK | ||
working, you can run a *mock* OTLP server locally with the `mockotlpserver` | ||
utility in this repository: | ||
|
||
```sh | ||
git clone https://github.com/elastic/elastic-otel-node.git | ||
cd elastic-otel-node/ | ||
npm ci | ||
cd packages/mockotlpserver | ||
npm start | ||
``` | ||
# Why this distribution? | ||
|
||
Now running an application with this SDK will send to the mock endpoint, which | ||
prints out any received telemetry data, for example: | ||
As mentioned above, this Distro is a wrapper around the [OpenTelemetry Node | ||
SDK (`@opentelemetry/sdk-node`)](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-sdk-node). So why the separate package? | ||
A few reasons: | ||
|
||
```sh | ||
cd elastic-otel-node/examples | ||
node -r @elastic/opentelemetry-node simple-http-request.js | ||
``` | ||
- With this separate package we hope to experiment with making it easier to get | ||
started with OpenTelemetry instrumentation in Node.js services. For example, | ||
`@elastic/opentelemetry-node` includes a number of OTel packages as dependencies, | ||
so the user only needs to install/update a single package -- at least for the | ||
default use case. This is similar to the OTel | ||
`@opentelemetry/auto-instrumentations-node` package. | ||
|
||
See [the mockotlpserver README](../mockotlpserver#readme) for more details. | ||
- Having a separate package will sometimes allow us to iterate more quickly with | ||
changes in SDK behavior. However, our plan is to upstream any improvements to | ||
the OpenTelemetry JS repositories. | ||
|
||
- Should it be necessary, having a separate package would allow us to more | ||
quickly release a fix for a particular issue required by a customer of ours. | ||
|
||
- Providing an eventual easy migration path for customers of our current | ||
non-OpenTelemetry-based [Node.js APM agent](https://github.com/elastic/apm-agent-nodejs) | ||
to this SDK may be made easier by having our own package entry point. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we are using the generic term
oltp endpoint
but next line we refer to elastic secret token which is more concrete to our stack. I wonder if we should add a note here telling APM server is an OTLP endpoint alsoThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll change the example here to this:
If using an Elastic Observability deployment
to which to send telemetry data, the
OTEL_EXPORTER_*
settings will looksomething like: