Skip to content

Commit 97d9ef0

Browse files
authored
fix(auto-instrumentation-node): resource detector from env should be the last detector (#3363)
1 parent 6437f2a commit 97d9ef0

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

packages/auto-instrumentations-node/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="https://your-endpoint"
5050
export OTEL_EXPORTER_OTLP_HEADERS="x-api-key=your-api-key"
5151
export OTEL_EXPORTER_OTLP_TRACES_HEADERS="x-api-key=your-api-key"
5252
export OTEL_RESOURCE_ATTRIBUTES="service.namespace=my-namespace"
53-
export OTEL_NODE_RESOURCE_DETECTORS="env,host,os,serviceinstance"
53+
export OTEL_NODE_RESOURCE_DETECTORS="host,os,serviceinstance,env"
5454
export OTEL_SERVICE_NAME="client"
5555
export NODE_OPTIONS="--require @opentelemetry/auto-instrumentations-node/register"
5656
node app.js
@@ -74,9 +74,15 @@ By default, all SDK resource detectors are used, but you can use the environment
7474
For example, to enable only the `env`, `host` detectors:
7575

7676
```shell
77-
export OTEL_NODE_RESOURCE_DETECTORS="env,host"
77+
export OTEL_NODE_RESOURCE_DETECTORS="host,env"
7878
```
7979

80+
NOTE: The order set on `OTEL_NODE_RESOURCE_DETECTORS` will be respected and the detectors will be executed in order.
81+
For example, if you have `OTEL_RESOURCE_ATTRIBUTES="service.instance.id=custom-name"`, but also `serviceinstance` and `env` on `OTEL_NODE_RESOURCE_DETECTORS`, it can have 2 scenarios:
82+
83+
- `OTEL_NODE_RESOURCE_DETECTORS="serviceinstance,env"` will have the `service.instance.id` as `custom-name`
84+
- `OTEL_NODE_RESOURCE_DETECTORS="env,serviceinstance"` will have the `service.instance.id` as a random UUID
85+
8086
By default, all [Supported Instrumentations](#supported-instrumentations) are enabled, unless they are annotated with "default disabled".
8187
You can use the environment variable `OTEL_NODE_ENABLED_INSTRUMENTATIONS` to enable only certain instrumentations, including "default disabled" ones
8288
OR the environment variable `OTEL_NODE_DISABLED_INSTRUMENTATIONS` to disable only certain instrumentations,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ export function getResourceDetectorsFromEnv(): Array<ResourceDetector> {
298298
ResourceDetector | ResourceDetector[]
299299
>([
300300
[RESOURCE_DETECTOR_CONTAINER, containerDetector],
301-
[RESOURCE_DETECTOR_ENVIRONMENT, envDetector],
302301
[RESOURCE_DETECTOR_HOST, hostDetector],
303302
[RESOURCE_DETECTOR_OS, osDetector],
304303
[RESOURCE_DETECTOR_SERVICE_INSTANCE_ID, serviceInstanceIdDetector],
@@ -319,6 +318,7 @@ export function getResourceDetectorsFromEnv(): Array<ResourceDetector> {
319318
RESOURCE_DETECTOR_AZURE,
320319
[azureAppServiceDetector, azureFunctionsDetector, azureVmDetector],
321320
],
321+
[RESOURCE_DETECTOR_ENVIRONMENT, envDetector],
322322
]);
323323

324324
const resourceDetectorsFromEnv =

0 commit comments

Comments
 (0)