Skip to content

Commit a558044

Browse files
authored
feat(auto-instrumentations-node)!: disable @opentelemetry/instrumentation-fs by default (#2467)
1 parent 0341e89 commit a558044

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

metapackages/auto-instrumentations-node/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ For example, to enable only the `env`, `host` detectors:
7777
export OTEL_NODE_RESOURCE_DETECTORS="env,host"
7878
```
7979

80-
By default, all [Supported Instrumentations](#supported-instrumentations) are enabled.
81-
You can use the environment variable `OTEL_NODE_ENABLED_INSTRUMENTATIONS` to enable only certain instrumentations,
80+
By default, all [Supported Instrumentations](#supported-instrumentations) are enabled, unless they are annotated with "default disabled".
81+
You can use the environment variable `OTEL_NODE_ENABLED_INSTRUMENTATIONS` to enable only certain instrumentations, including "default disabled" ones
8282
OR the environment variable `OTEL_NODE_DISABLED_INSTRUMENTATIONS` to disable only certain instrumentations,
8383
by providing a comma-separated list of the instrumentation package names without the `@opentelemetry/instrumentation-` prefix.
8484

@@ -91,10 +91,10 @@ instrumentations:
9191
export OTEL_NODE_ENABLED_INSTRUMENTATIONS="http,nestjs-core"
9292
```
9393

94-
To disable only [@opentelemetry/instrumentation-fs](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-fs):
94+
To disable only [@opentelemetry/instrumentation-net](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-net):
9595

9696
```shell
97-
export OTEL_NODE_DISABLED_INSTRUMENTATIONS="fs"
97+
export OTEL_NODE_DISABLED_INSTRUMENTATIONS="net"
9898
```
9999

100100
If both environment variables are set, `OTEL_NODE_ENABLED_INSTRUMENTATIONS` is applied first, and then `OTEL_NODE_DISABLED_INSTRUMENTATIONS` is applied to that list.
@@ -170,6 +170,7 @@ registerInstrumentations({
170170
- [@opentelemetry/instrumentation-dns](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-dns)
171171
- [@opentelemetry/instrumentation-express](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-express)
172172
- [@opentelemetry/instrumentation-fastify](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-fastify)
173+
- [@opentelemetry/instrumentation-fs](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-fs) (default disabled)
173174
- [@opentelemetry/instrumentation-generic-pool](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-generic-pool)
174175
- [@opentelemetry/instrumentation-graphql](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-graphql)
175176
- [@opentelemetry/instrumentation-grpc](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-grpc)

metapackages/auto-instrumentations-node/src/utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ const InstrumentationMap = {
136136
'@opentelemetry/instrumentation-winston': WinstonInstrumentation,
137137
};
138138

139+
const defaultExcludedInstrumentations = ['@opentelemetry/instrumentation-fs'];
140+
139141
// Config types inferred automatically from the first argument of the constructor
140142
type ConfigArg<T> = T extends new (...args: infer U) => unknown ? U[0] : never;
141143
export type InstrumentationConfigMap = {
@@ -208,10 +210,14 @@ function getInstrumentationsFromEnv(envVar: string): string[] {
208210

209211
/**
210212
* Returns the list of instrumentations that are enabled based on the environment variable.
213+
* If the environment variable is unset, returns all instrumentation that are enabled by default.
211214
*/
212215
function getEnabledInstrumentationsFromEnv() {
213216
if (!process.env.OTEL_NODE_ENABLED_INSTRUMENTATIONS) {
214-
return Object.keys(InstrumentationMap);
217+
// all keys in the InstrumentationMap except for everything that is not enabled by default.
218+
return Object.keys(InstrumentationMap).filter(
219+
key => !defaultExcludedInstrumentations.includes(key)
220+
);
215221
}
216222

217223
const instrumentationsFromEnv = getInstrumentationsFromEnv(

metapackages/auto-instrumentations-node/test/utils.test.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ import { getResourceDetectorsFromEnv } from '../src/utils';
2323

2424
describe('utils', () => {
2525
describe('getNodeAutoInstrumentations', () => {
26-
it('should include all installed instrumentations', () => {
26+
it('should include all default instrumentations', () => {
2727
const instrumentations = getNodeAutoInstrumentations();
2828
const installedInstrumentations = Object.keys(
2929
require('../package.json').dependencies
3030
).filter(depName => {
31-
return depName.startsWith('@opentelemetry/instrumentation-');
31+
return (
32+
depName.startsWith('@opentelemetry/instrumentation-') &&
33+
depName !== '@opentelemetry/instrumentation-fs'
34+
);
3235
});
3336

3437
assert.deepStrictEqual(
@@ -89,6 +92,20 @@ describe('utils', () => {
8992
}
9093
});
9194

95+
it('should allow enabling non-default instrumentations via OTEL_NODE_ENABLED_INSTRUMENTATIONS environment variable', () => {
96+
process.env.OTEL_NODE_ENABLED_INSTRUMENTATIONS = 'fs'; // separator with and without whitespaces should be allowed
97+
try {
98+
const instrumentations = getNodeAutoInstrumentations();
99+
100+
assert.deepStrictEqual(
101+
new Set(instrumentations.map(i => i.instrumentationName)),
102+
new Set(['@opentelemetry/instrumentation-fs'])
103+
);
104+
} finally {
105+
delete process.env.OTEL_NODE_ENABLED_INSTRUMENTATIONS;
106+
}
107+
});
108+
92109
it('should include all instrumentations except those disabled via OTEL_NODE_DISABLED_INSTRUMENTATIONS environment variable', () => {
93110
process.env.OTEL_NODE_DISABLED_INSTRUMENTATIONS =
94111
'fs,aws-sdk, aws-lambda'; // separator with and without whitespaces should be allowed

0 commit comments

Comments
 (0)