From af2f3f1e5a2608900fcea721f08b2e541a17927c Mon Sep 17 00:00:00 2001 From: Marylia Gutierrez Date: Mon, 29 Apr 2024 04:08:11 -0400 Subject: [PATCH] feat(auto-instrumentation-node): add azure detector (#2101) The Azure detectors were not being added to the list of possible detectors. All other cloud providers were possible values, so this commit adds the missing detectors for Azure. Signed-off-by: maryliag Co-authored-by: Amir Blum --- metapackages/auto-instrumentations-node/README.md | 1 + metapackages/auto-instrumentations-node/package.json | 1 + metapackages/auto-instrumentations-node/src/utils.ts | 12 +++++++++++- .../auto-instrumentations-node/test/utils.test.ts | 4 ++-- package-lock.json | 2 ++ 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/metapackages/auto-instrumentations-node/README.md b/metapackages/auto-instrumentations-node/README.md index dccf55a266..ba31c44d9a 100644 --- a/metapackages/auto-instrumentations-node/README.md +++ b/metapackages/auto-instrumentations-node/README.md @@ -65,6 +65,7 @@ By default, all SDK resource detectors are used, but you can use the environment - `container` - `alibaba` - `aws` +- `azure` - `gcp` - `all` - enable all resource detectors - `none` - disable resource detection diff --git a/metapackages/auto-instrumentations-node/package.json b/metapackages/auto-instrumentations-node/package.json index 47ee58c6b3..7704e11d66 100644 --- a/metapackages/auto-instrumentations-node/package.json +++ b/metapackages/auto-instrumentations-node/package.json @@ -89,6 +89,7 @@ "@opentelemetry/instrumentation-winston": "^0.37.0", "@opentelemetry/resource-detector-alibaba-cloud": "^0.28.9", "@opentelemetry/resource-detector-aws": "^1.4.2", + "@opentelemetry/resource-detector-azure": "^0.2.6", "@opentelemetry/resource-detector-container": "^0.3.9", "@opentelemetry/resource-detector-gcp": "^0.29.9", "@opentelemetry/resources": "^1.12.0", diff --git a/metapackages/auto-instrumentations-node/src/utils.ts b/metapackages/auto-instrumentations-node/src/utils.ts index 67cfa900c8..de7d0c7026 100644 --- a/metapackages/auto-instrumentations-node/src/utils.ts +++ b/metapackages/auto-instrumentations-node/src/utils.ts @@ -73,6 +73,11 @@ import { osDetectorSync, processDetectorSync, } from '@opentelemetry/resources'; +import { + azureAppServiceDetector, + azureFunctionsDetector, + azureVmDetector, +} from '@opentelemetry/resource-detector-azure'; const RESOURCE_DETECTOR_CONTAINER = 'container'; const RESOURCE_DETECTOR_ENVIRONMENT = 'env'; @@ -81,6 +86,7 @@ const RESOURCE_DETECTOR_OS = 'os'; const RESOURCE_DETECTOR_PROCESS = 'process'; const RESOURCE_DETECTOR_ALIBABA = 'alibaba'; const RESOURCE_DETECTOR_AWS = 'aws'; +const RESOURCE_DETECTOR_AZURE = 'azure'; const RESOURCE_DETECTOR_GCP = 'gcp'; const InstrumentationMap = { @@ -196,7 +202,7 @@ function getEnabledInstrumentationsFromEnv() { export function getResourceDetectorsFromEnv(): Array { const resourceDetectors = new Map< string, - Detector | DetectorSync | Detector[] + Detector | DetectorSync | Detector[] | DetectorSync[] >([ [RESOURCE_DETECTOR_CONTAINER, containerDetector], [RESOURCE_DETECTOR_ENVIRONMENT, envDetectorSync], @@ -215,6 +221,10 @@ export function getResourceDetectorsFromEnv(): Array { awsLambdaDetector, ], ], + [ + RESOURCE_DETECTOR_AZURE, + [azureAppServiceDetector, azureFunctionsDetector, azureVmDetector], + ], ]); const resourceDetectorsFromEnv = diff --git a/metapackages/auto-instrumentations-node/test/utils.test.ts b/metapackages/auto-instrumentations-node/test/utils.test.ts index 3a04c01569..29fae3cef2 100644 --- a/metapackages/auto-instrumentations-node/test/utils.test.ts +++ b/metapackages/auto-instrumentations-node/test/utils.test.ts @@ -114,13 +114,13 @@ describe('utils', () => { describe('getResourceDetectorsFromEnv', () => { it('should return all resource detectors by default', () => { - assert.equal(getResourceDetectorsFromEnv().length, 12); + assert.equal(getResourceDetectorsFromEnv().length, 15); }); it('should return all resource detectors when OTEL_NODE_RESOURCE_DETECTORS contains "all"', () => { process.env.OTEL_NODE_RESOURCE_DETECTORS = 'all'; - assert.equal(getResourceDetectorsFromEnv().length, 12); + assert.equal(getResourceDetectorsFromEnv().length, 15); delete process.env.OTEL_NODE_RESOURCE_DETECTORS; }); diff --git a/package-lock.json b/package-lock.json index 89f33d1864..ec53fe1355 100644 --- a/package-lock.json +++ b/package-lock.json @@ -324,6 +324,7 @@ "@opentelemetry/instrumentation-winston": "^0.37.0", "@opentelemetry/resource-detector-alibaba-cloud": "^0.28.9", "@opentelemetry/resource-detector-aws": "^1.4.2", + "@opentelemetry/resource-detector-azure": "^0.2.6", "@opentelemetry/resource-detector-container": "^0.3.9", "@opentelemetry/resource-detector-gcp": "^0.29.9", "@opentelemetry/resources": "^1.12.0", @@ -45514,6 +45515,7 @@ "@opentelemetry/instrumentation-winston": "^0.37.0", "@opentelemetry/resource-detector-alibaba-cloud": "^0.28.9", "@opentelemetry/resource-detector-aws": "^1.4.2", + "@opentelemetry/resource-detector-azure": "^0.2.6", "@opentelemetry/resource-detector-container": "^0.3.9", "@opentelemetry/resource-detector-gcp": "^0.29.9", "@opentelemetry/resources": "^1.12.0",