Skip to content
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

chore(otel-node): disable fastify instrumentation and update docs #616

Merged
merged 5 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/opentelemetry-node/docs/supported-technologies.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@ requires:
| `@opentelemetry/instrumentation-undici` | `undici` version range `>=5.12.0` | [README](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-undici#readme) |
| `@opentelemetry/instrumentation-winston` | `winston` version range `>1 <4` | [README](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-winston#readme) |

### Disabled instrumentations

This Distro takes the upstream package `@opentelemetry/auto-instrumentations-node` as a baseline for technology support. This means additions or removals in its instrumentation list will be revised and usually applied here. As for now the list includes a couple of instrumentations that are disabled by default:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested alternative:

The following instrumentations are included in EDOT Node.js, but *disabled by default*:

- `@opentelemetry/instrumentation-fs` (Disabled upstream in [open-telemetry/opentelemetry-js-contrib#2467](https://github.com/open-telemetry/opentelemetry-js-contrib/pull/2467).)
- `@opentelemetry/instrumentation-fastify` (Deprecated upstream and slated for removal. See [open-telemetry/opentelemetry-js-contrib#2652](https://github.com/open-telemetry/opentelemetry-js-contrib/pull/2652))

To enable these instrumentations, use the `OTEL_NODE_ENABLED_INSTRUMENTATIONS` environment variable, as documented [here in the OpenTelemetry documentation](https://opentelemetry.io/docs/zero-code/js/configuration/#excluding-instrumentation-libraries). Make sure you list all the instrumentations
you need for your service since only the ones in that list will be enabled. For example:

... the example code as you have it ...

EDOT Node.js uses the upstream [`@opentelemetry/auto-instrumentations-node` package's set of instrumentations](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/metapackages/auto-instrumentations-node/README.md#supported-instrumentations) as a guide for instrumentations to include, exclude, or disable by default. This is to maximize compatibility between usage of EDOT Node.js and the vanilla OpenTelemetry JS SDK.
  • I think we are meant to move away from "the Distro" to using "EDOT Node.js"
  • My re-ordering here was to put the "here is how it works and how to configure it" info first, and then finish with the justification/reasoning information.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. I'm going to change it in the next commit


- `@opentelemetry/instrumentation-fs`: Disabled in [opentelemetry-js-contrib/pull/2467](https://github.com/open-telemetry/opentelemetry-js-contrib/pull/2467).
- `@opentelemetry/instrumentation-fastify`: Disabled in [opentelemetry-js-contrib/pull/2652](https://github.com/open-telemetry/opentelemetry-js-contrib/pull/2652).

If you want to enable these instrumentations you should make use of the environment var `OTEL_NODE_ENABLED_INSTRUMENTATIONS` defined
in [zero-code instrumentation docs](https://opentelemetry.io/docs/zero-code/js/configuration/). Make sure you put all the instrumentations
you need for your service since only the ones in that list will be enabled.

```bash
export OTEL_EXPORTER_OTLP_ENDPOINT=https://my-deployment.apm.us-west1.gcp.cloud.es.io
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer P....l"
export OTEL_NODE_ENABLED_INSTRUMENTATIONS="fs,http,fastify" # only the ones in the list would be enabled
node --import @elastic/opentelemetry-node my-service.js
```

## Native Instrumentations

"Native" instrumentation refers to OpenTelemetry instrumentation that is built into a library. When a library includes native OTel instrumentation, it will provide telemetry data to providers registered by a running OTel SDK. Native instrumentations of note are listed in the table below. To benefit from these instrumentations you only need to (a) use the library and (b) start the EDOT Node.js SDK:
Expand Down
11 changes: 8 additions & 3 deletions packages/opentelemetry-node/lib/instrumentations.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ const INSTRUMENTATIONS = {
};
/* eslint-enable prettier/prettier */

const EXCLUDED_INSTRUMENTATIONS = new Set([
'@opentelemetry/instrumentation-fastify',
'@opentelemetry/instrumentation-fs',
]);

/**
* Reads a string in the format `value1,value2` and parses
* it into an array. This is the format specified for comma separated
Expand Down Expand Up @@ -288,9 +293,9 @@ function getInstrumentations(opts = {}) {

if (enabledFromEnv) {
instrConfig = {...instrConfig, enabled: true};
} else if (name === '@opentelemetry/instrumentation-fs') {
// if `fs` not present in envvar instrumentation is disabled
// unless an explicit config says the opposite
} else if (EXCLUDED_INSTRUMENTATIONS.has(name)) {
// if excluded instrumentations not present in envvar the instrumentation
// is disabled unless an explicit config says the opposite
// ref: https://github.com/open-telemetry/opentelemetry-js-contrib/pull/2467
instrConfig = {enabled: false, ...instrConfig};
}
Expand Down
43 changes: 42 additions & 1 deletion packages/opentelemetry-node/test/instr-fastify.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const {
/** @type {import('./testutils').TestFixture[]} */
const testFixtures = [
{
name: 'use-fastify',
name: 'use-fastify (default disabled)',
args: ['./fixtures/use-fastify.js'],
cwd: __dirname,
env: {
Expand All @@ -40,6 +40,47 @@ const testFixtures = [
node: '>=20.0.0',
},
// verbose: true,
checkTelemetry: (t, col) => {
// We expect spans like this
// ------ trace 9042af (3 spans) ------
// span 5894e1 "GET" (6.8ms, SPAN_KIND_CLIENT, GET http://localhost:3000/ping -> 200)
// +3ms `- span c793a1 "GET /ping" (2.7ms, SPAN_KIND_SERVER, GET http://localhost:3000/ping -> 200)
// ------ trace 8f3ed8 (3 spans) ------
// span 6e0fc9 "GET" (1.6ms, SPAN_KIND_CLIENT, GET http://localhost:3000/hi/Bob -> 200)
// +1ms `- span 40c4a8 "GET /hi/:name" (0.3ms, SPAN_KIND_SERVER, GET http://localhost:3000/hi/Bob -> 200)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is misleading. The expected server spans do NOT have the route info.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove it

const spans = filterOutDnsNetSpans(col.sortedSpans);

t.equal(spans.length, 4);
t.ok(
spans.every(
(s) =>
s.scope.name === '@opentelemetry/instrumentation-http'
)
);
t.ok(spans.every((s) => s.name === 'GET'));
t.equal(
spans.filter((s) => s.kind === 'SPAN_KIND_CLIENT').length,
2
);
t.equal(
spans.filter((s) => s.kind === 'SPAN_KIND_SERVER').length,
2
);
},
},
{
name: 'use-fastify (enabled via env var)',
args: ['./fixtures/use-fastify.js'],
cwd: __dirname,
env: {
NODE_OPTIONS: '--require=@elastic/opentelemetry-node',
OTEL_NODE_ENABLED_INSTRUMENTATIONS: 'http,fastify',
},
versionRanges: {
// Ref: https://fastify.dev/docs/latest/Guides/Migration-Guide-V5/#long-term-support-cycle
node: '>=20.0.0',
},
// verbose: true,
checkTelemetry: (t, col) => {
// We expect spans like this
// ------ trace 9042af (3 spans) ------
Expand Down
Loading