diff --git a/packages/auto-instrumentations-node/README.md b/packages/auto-instrumentations-node/README.md index 356c21c101..b7da0a441d 100644 --- a/packages/auto-instrumentations-node/README.md +++ b/packages/auto-instrumentations-node/README.md @@ -50,7 +50,7 @@ export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="https://your-endpoint" export OTEL_EXPORTER_OTLP_HEADERS="x-api-key=your-api-key" export OTEL_EXPORTER_OTLP_TRACES_HEADERS="x-api-key=your-api-key" export OTEL_RESOURCE_ATTRIBUTES="service.namespace=my-namespace" -export OTEL_NODE_RESOURCE_DETECTORS="env,host,os,serviceinstance" +export OTEL_NODE_RESOURCE_DETECTORS="host,os,serviceinstance,env" export OTEL_SERVICE_NAME="client" export NODE_OPTIONS="--require @opentelemetry/auto-instrumentations-node/register" node app.js @@ -74,9 +74,15 @@ By default, all SDK resource detectors are used, but you can use the environment For example, to enable only the `env`, `host` detectors: ```shell -export OTEL_NODE_RESOURCE_DETECTORS="env,host" +export OTEL_NODE_RESOURCE_DETECTORS="host,env" ``` +NOTE: The order set on `OTEL_NODE_RESOURCE_DETECTORS` will be respected and the detectors will be executed in order. +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: + +- `OTEL_NODE_RESOURCE_DETECTORS="serviceinstance,env"` will have the `service.instance.id` as `custom-name` +- `OTEL_NODE_RESOURCE_DETECTORS="env,serviceinstance"` will have the `service.instance.id` as a random UUID + By default, all [Supported Instrumentations](#supported-instrumentations) are enabled, unless they are annotated with "default disabled". You can use the environment variable `OTEL_NODE_ENABLED_INSTRUMENTATIONS` to enable only certain instrumentations, including "default disabled" ones OR the environment variable `OTEL_NODE_DISABLED_INSTRUMENTATIONS` to disable only certain instrumentations, diff --git a/packages/auto-instrumentations-node/src/utils.ts b/packages/auto-instrumentations-node/src/utils.ts index cda71e00f9..8d99113eb4 100644 --- a/packages/auto-instrumentations-node/src/utils.ts +++ b/packages/auto-instrumentations-node/src/utils.ts @@ -298,7 +298,6 @@ export function getResourceDetectorsFromEnv(): Array { ResourceDetector | ResourceDetector[] >([ [RESOURCE_DETECTOR_CONTAINER, containerDetector], - [RESOURCE_DETECTOR_ENVIRONMENT, envDetector], [RESOURCE_DETECTOR_HOST, hostDetector], [RESOURCE_DETECTOR_OS, osDetector], [RESOURCE_DETECTOR_SERVICE_INSTANCE_ID, serviceInstanceIdDetector], @@ -319,6 +318,7 @@ export function getResourceDetectorsFromEnv(): Array { RESOURCE_DETECTOR_AZURE, [azureAppServiceDetector, azureFunctionsDetector, azureVmDetector], ], + [RESOURCE_DETECTOR_ENVIRONMENT, envDetector], ]); const resourceDetectorsFromEnv =