From 9761a9160c862b9f8a35c00afc26217973e4462a Mon Sep 17 00:00:00 2001 From: Abhinav Mathur Date: Mon, 10 Jun 2024 07:10:54 -0400 Subject: [PATCH 1/3] fix: ContainerId not detected post version 0.2.2 (#2270) * ?? only checks for null and undefined * added unit test to cover the fix * added unit test to cover the fix * lint fixes * lint fixes - line too long --- .../src/detectors/ContainerDetector.ts | 2 +- .../test/ContainerDetector.test.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/detectors/node/opentelemetry-resource-detector-container/src/detectors/ContainerDetector.ts b/detectors/node/opentelemetry-resource-detector-container/src/detectors/ContainerDetector.ts index 73b26f9ed4..78bffb7572 100644 --- a/detectors/node/opentelemetry-resource-detector-container/src/detectors/ContainerDetector.ts +++ b/detectors/node/opentelemetry-resource-detector-container/src/detectors/ContainerDetector.ts @@ -108,7 +108,7 @@ export class ContainerDetector implements Detector { private async _getContainerId(): Promise { try { return ( - (await this._getContainerIdV1()) ?? (await this._getContainerIdV2()) + (await this._getContainerIdV1()) || (await this._getContainerIdV2()) ); } catch (e) { if (e instanceof Error) { diff --git a/detectors/node/opentelemetry-resource-detector-container/test/ContainerDetector.test.ts b/detectors/node/opentelemetry-resource-detector-container/test/ContainerDetector.test.ts index 8ee03d1f36..71fbf1c5de 100644 --- a/detectors/node/opentelemetry-resource-detector-container/test/ContainerDetector.test.ts +++ b/detectors/node/opentelemetry-resource-detector-container/test/ContainerDetector.test.ts @@ -94,6 +94,16 @@ describe('ContainerDetector', () => { assert.ok(resource); }); + it('should return a correctCgroupV2Data resource with v1Detector returns empty string ', async () => { + readStub = sinon.stub(ContainerDetector, 'readFileAsync' as any); + sinon.stub(containerDetector, '_getContainerIdV1' as any).resolves(''); + sinon + .stub(containerDetector, '_getContainerIdV2' as any) + .resolves(correctCgroupV2Data); + const containerId = await containerDetector['_getContainerId'](); + assert.strictEqual(containerId, correctCgroupV2Data); + }); + it('should return a resource without attribute container.id when cgroup file does not contain valid Container ID', async () => { readStub = sinon .stub(ContainerDetector, 'readFileAsync' as any) From cac5cc9e9b45497bb15c9e0a6b267332bf95ce48 Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Mon, 10 Jun 2024 14:57:10 +0200 Subject: [PATCH 2/3] chore(deps): update dependency @rollup/plugin-commonjs to v26 (#2264) --- package-lock.json | 179 ++++++------------ .../package.json | 2 +- 2 files changed, 54 insertions(+), 127 deletions(-) diff --git a/package-lock.json b/package-lock.json index 83cf4149f9..943618e2c9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9403,20 +9403,20 @@ } }, "node_modules/@rollup/plugin-commonjs": { - "version": "25.0.7", - "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-25.0.7.tgz", - "integrity": "sha512-nEvcR+LRjEjsaSsc4x3XZfCCvZIaSMenZu/OiwOKGN2UhQpAYI7ru7czFvyWbErlpoGjnSX3D5Ch5FcMA3kRWQ==", + "version": "26.0.1", + "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-26.0.1.tgz", + "integrity": "sha512-UnsKoZK6/aGIH6AdkptXhNvhaqftcjq3zZdT+LY5Ftms6JR06nADcDsYp5hTU9E2lbJUEOhdlY5J4DNTneM+jQ==", "dev": true, "dependencies": { "@rollup/pluginutils": "^5.0.1", "commondir": "^1.0.1", "estree-walker": "^2.0.2", - "glob": "^8.0.3", + "glob": "^10.4.1", "is-reference": "1.2.1", "magic-string": "^0.30.3" }, "engines": { - "node": ">=14.0.0" + "node": ">=16.0.0 || 14 >= 14.17" }, "peerDependencies": { "rollup": "^2.68.0||^3.0.0||^4.0.0" @@ -9427,46 +9427,6 @@ } } }, - "node_modules/@rollup/plugin-commonjs/node_modules/brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", - "dev": true, - "dependencies": { - "balanced-match": "^1.0.0" - } - }, - "node_modules/@rollup/plugin-commonjs/node_modules/glob": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", - "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", - "dev": true, - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^5.0.1", - "once": "^1.3.0" - }, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/@rollup/plugin-commonjs/node_modules/minimatch": { - "version": "5.1.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", - "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", - "dev": true, - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/@rollup/plugin-node-resolve": { "version": "15.2.3", "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.2.3.tgz", @@ -18960,22 +18920,22 @@ "dev": true }, "node_modules/glob": { - "version": "10.3.10", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.10.tgz", - "integrity": "sha512-fa46+tv1Ak0UPK1TOy/pZrIybNNt4HCv7SDzwyfiOZkvZLEbjsZkJBPtDHVshZjbecAoAGSC20MjLDG/qr679g==", + "version": "10.4.1", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.1.tgz", + "integrity": "sha512-2jelhlq3E4ho74ZyVLN03oKdAZVUa6UDZzFLVH1H7dnoax+y9qyaq8zBkfDIggjniU19z0wU18y16jMB2eyVIw==", "dev": true, "dependencies": { "foreground-child": "^3.1.0", - "jackspeak": "^2.3.5", - "minimatch": "^9.0.1", - "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0", - "path-scurry": "^1.10.1" + "jackspeak": "^3.1.2", + "minimatch": "^9.0.4", + "minipass": "^7.1.2", + "path-scurry": "^1.11.1" }, "bin": { "glob": "dist/esm/bin.mjs" }, "engines": { - "node": ">=16 || 14 >=14.17" + "node": ">=16 || 14 >=14.18" }, "funding": { "url": "https://github.com/sponsors/isaacs" @@ -20991,9 +20951,9 @@ } }, "node_modules/jackspeak": { - "version": "2.3.6", - "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-2.3.6.tgz", - "integrity": "sha512-N3yCS/NegsOBokc8GAdM8UcmfsKiSS8cipheD/nivzr700H+nsMOxJjQnvwOcRYVuFkdH0wGUvW2WbXGmrZGbQ==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.4.0.tgz", + "integrity": "sha512-JVYhQnN59LVPFCEcVa2C3CrEKYacvjRfqIQl+h8oi91aLYQVWRYbxjPcv1bUiUy/kLmQaANrYfNMCO3kuEDHfw==", "dev": true, "dependencies": { "@isaacs/cliui": "^8.0.2" @@ -24549,9 +24509,9 @@ "dev": true }, "node_modules/minimatch": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", - "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", + "version": "9.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.4.tgz", + "integrity": "sha512-KqWh+VchfxcMNRAJjj2tnsSJdNbHsVgnkBhTNrW7AjVo6OvLtxw8zfT9oLw1JSohlFzJ8jCoTgaoXvJ+kHt6fw==", "dev": true, "dependencies": { "brace-expansion": "^2.0.1" @@ -24595,9 +24555,9 @@ } }, "node_modules/minipass": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.0.4.tgz", - "integrity": "sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==", + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", + "integrity": "sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==", "dev": true, "engines": { "node": ">=16 || 14 >=14.17" @@ -28720,16 +28680,16 @@ "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" }, "node_modules/path-scurry": { - "version": "1.10.1", - "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.10.1.tgz", - "integrity": "sha512-MkhCqzzBEpPvxxQ71Md0b1Kk51W01lrYvlMzSUaIzNsODdd7mqhiimSZlr+VegAz5Z6Vzt9Xg2ttE//XBhH3EQ==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.11.1.tgz", + "integrity": "sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==", "dev": true, "dependencies": { - "lru-cache": "^9.1.1 || ^10.0.0", + "lru-cache": "^10.2.0", "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0" }, "engines": { - "node": ">=16 || 14 >=14.17" + "node": ">=16 || 14 >=14.18" }, "funding": { "url": "https://github.com/sponsors/isaacs" @@ -39051,7 +39011,7 @@ "@babel/core": "7.22.17", "@jsdevtools/coverage-istanbul-loader": "3.0.5", "@opentelemetry/api": "^1.3.0", - "@rollup/plugin-commonjs": "^25.0.7", + "@rollup/plugin-commonjs": "^26.0.0", "@rollup/plugin-node-resolve": "^15.2.3", "@types/chai": "^4.3.10", "@types/mocha": "8.2.3", @@ -46739,7 +46699,7 @@ "@opentelemetry/sdk-trace-base": "^1.0.0", "@opentelemetry/sdk-trace-web": "^1.15.0", "@opentelemetry/semantic-conventions": "^1.22.0", - "@rollup/plugin-commonjs": "^25.0.7", + "@rollup/plugin-commonjs": "^26.0.0", "@rollup/plugin-node-resolve": "^15.2.3", "@types/chai": "^4.3.10", "@types/mocha": "8.2.3", @@ -48895,50 +48855,17 @@ "requires": {} }, "@rollup/plugin-commonjs": { - "version": "25.0.7", - "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-25.0.7.tgz", - "integrity": "sha512-nEvcR+LRjEjsaSsc4x3XZfCCvZIaSMenZu/OiwOKGN2UhQpAYI7ru7czFvyWbErlpoGjnSX3D5Ch5FcMA3kRWQ==", + "version": "26.0.1", + "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-26.0.1.tgz", + "integrity": "sha512-UnsKoZK6/aGIH6AdkptXhNvhaqftcjq3zZdT+LY5Ftms6JR06nADcDsYp5hTU9E2lbJUEOhdlY5J4DNTneM+jQ==", "dev": true, "requires": { "@rollup/pluginutils": "^5.0.1", "commondir": "^1.0.1", "estree-walker": "^2.0.2", - "glob": "^8.0.3", + "glob": "^10.4.1", "is-reference": "1.2.1", "magic-string": "^0.30.3" - }, - "dependencies": { - "brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", - "dev": true, - "requires": { - "balanced-match": "^1.0.0" - } - }, - "glob": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", - "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", - "dev": true, - "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^5.0.1", - "once": "^1.3.0" - } - }, - "minimatch": { - "version": "5.1.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", - "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", - "dev": true, - "requires": { - "brace-expansion": "^2.0.1" - } - } } }, "@rollup/plugin-node-resolve": { @@ -56547,16 +56474,16 @@ } }, "glob": { - "version": "10.3.10", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.10.tgz", - "integrity": "sha512-fa46+tv1Ak0UPK1TOy/pZrIybNNt4HCv7SDzwyfiOZkvZLEbjsZkJBPtDHVshZjbecAoAGSC20MjLDG/qr679g==", + "version": "10.4.1", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.1.tgz", + "integrity": "sha512-2jelhlq3E4ho74ZyVLN03oKdAZVUa6UDZzFLVH1H7dnoax+y9qyaq8zBkfDIggjniU19z0wU18y16jMB2eyVIw==", "dev": true, "requires": { "foreground-child": "^3.1.0", - "jackspeak": "^2.3.5", - "minimatch": "^9.0.1", - "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0", - "path-scurry": "^1.10.1" + "jackspeak": "^3.1.2", + "minimatch": "^9.0.4", + "minipass": "^7.1.2", + "path-scurry": "^1.11.1" }, "dependencies": { "foreground-child": { @@ -58059,9 +57986,9 @@ } }, "jackspeak": { - "version": "2.3.6", - "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-2.3.6.tgz", - "integrity": "sha512-N3yCS/NegsOBokc8GAdM8UcmfsKiSS8cipheD/nivzr700H+nsMOxJjQnvwOcRYVuFkdH0wGUvW2WbXGmrZGbQ==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.4.0.tgz", + "integrity": "sha512-JVYhQnN59LVPFCEcVa2C3CrEKYacvjRfqIQl+h8oi91aLYQVWRYbxjPcv1bUiUy/kLmQaANrYfNMCO3kuEDHfw==", "dev": true, "requires": { "@isaacs/cliui": "^8.0.2", @@ -60905,9 +60832,9 @@ "dev": true }, "minimatch": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", - "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", + "version": "9.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.4.tgz", + "integrity": "sha512-KqWh+VchfxcMNRAJjj2tnsSJdNbHsVgnkBhTNrW7AjVo6OvLtxw8zfT9oLw1JSohlFzJ8jCoTgaoXvJ+kHt6fw==", "dev": true, "requires": { "brace-expansion": "^2.0.1" @@ -60941,9 +60868,9 @@ } }, "minipass": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.0.4.tgz", - "integrity": "sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==", + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", + "integrity": "sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==", "dev": true }, "minipass-collect": { @@ -64260,12 +64187,12 @@ "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" }, "path-scurry": { - "version": "1.10.1", - "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.10.1.tgz", - "integrity": "sha512-MkhCqzzBEpPvxxQ71Md0b1Kk51W01lrYvlMzSUaIzNsODdd7mqhiimSZlr+VegAz5Z6Vzt9Xg2ttE//XBhH3EQ==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.11.1.tgz", + "integrity": "sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==", "dev": true, "requires": { - "lru-cache": "^9.1.1 || ^10.0.0", + "lru-cache": "^10.2.0", "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0" }, "dependencies": { diff --git a/plugins/web/opentelemetry-instrumentation-document-load/package.json b/plugins/web/opentelemetry-instrumentation-document-load/package.json index 48c9831ce3..ebab74aea6 100644 --- a/plugins/web/opentelemetry-instrumentation-document-load/package.json +++ b/plugins/web/opentelemetry-instrumentation-document-load/package.json @@ -54,7 +54,7 @@ "@babel/core": "7.22.17", "@jsdevtools/coverage-istanbul-loader": "3.0.5", "@opentelemetry/api": "^1.3.0", - "@rollup/plugin-commonjs": "^25.0.7", + "@rollup/plugin-commonjs": "^26.0.0", "@rollup/plugin-node-resolve": "^15.2.3", "@types/chai": "^4.3.10", "@types/mocha": "8.2.3", From 93776fad10fb46ba4ba2bfe31a4825ec0929fd50 Mon Sep 17 00:00:00 2001 From: Jackson Weber <47067795+JacksonWeber@users.noreply.github.com> Date: Mon, 10 Jun 2024 05:58:08 -0700 Subject: [PATCH 3/3] fix(azure-functions-resource-detector): Update Azure Functions Detector to Consider WEBSITE_SKU (#2251) * fix: Update the functions detector check to include SKU. * Resolve PR comments. --------- Co-authored-by: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com> Co-authored-by: Marc Pichler --- .../src/detectors/AzureAppServiceDetector.ts | 6 ++--- .../src/detectors/AzureFunctionsDetector.ts | 7 +++--- .../src/types.ts | 1 + .../src/utils.ts | 14 ++++++++++- .../detectors/AzureFunctionsDetector.test.ts | 24 +++++++++++++++++++ 5 files changed, 43 insertions(+), 9 deletions(-) diff --git a/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureAppServiceDetector.ts b/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureAppServiceDetector.ts index 72b2fc8ac1..09c66ea7ca 100644 --- a/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureAppServiceDetector.ts +++ b/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureAppServiceDetector.ts @@ -24,7 +24,6 @@ import { WEBSITE_SITE_NAME, WEBSITE_SLOT_NAME, CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE, - FUNCTIONS_VERSION, } from '../types'; import { SEMRESATTRS_CLOUD_REGION, @@ -37,7 +36,7 @@ import { CLOUDPROVIDERVALUES_AZURE, CLOUDPLATFORMVALUES_AZURE_APP_SERVICE, } from '@opentelemetry/semantic-conventions'; -import { getAzureResourceUri } from '../utils'; +import { getAzureResourceUri, isAzureFunction } from '../utils'; const APP_SERVICE_ATTRIBUTE_ENV_VARS = { [SEMRESATTRS_CLOUD_REGION]: REGION_NAME, @@ -55,8 +54,7 @@ class AzureAppServiceDetector implements DetectorSync { detect(): IResource { let attributes = {}; const websiteSiteName = process.env[WEBSITE_SITE_NAME]; - const isAzureFunction = !!process.env[FUNCTIONS_VERSION]; - if (websiteSiteName && !isAzureFunction) { + if (websiteSiteName && !isAzureFunction()) { attributes = { ...attributes, [SEMRESATTRS_SERVICE_NAME]: websiteSiteName, diff --git a/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureFunctionsDetector.ts b/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureFunctionsDetector.ts index 74cd9e3054..acd214bea0 100644 --- a/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureFunctionsDetector.ts +++ b/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureFunctionsDetector.ts @@ -29,13 +29,12 @@ import { } from '@opentelemetry/semantic-conventions'; import { WEBSITE_SITE_NAME, - FUNCTIONS_VERSION, WEBSITE_INSTANCE_ID, FUNCTIONS_MEM_LIMIT, REGION_NAME, CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE, } from '../types'; -import { getAzureResourceUri } from '../utils'; +import { getAzureResourceUri, isAzureFunction } from '../utils'; const AZURE_FUNCTIONS_ATTRIBUTE_ENV_VARS = { [SEMRESATTRS_SERVICE_NAME]: WEBSITE_SITE_NAME, @@ -51,13 +50,13 @@ class AzureFunctionsDetector implements DetectorSync { detect(): IResource { let attributes = {}; const serviceName = process.env[WEBSITE_SITE_NAME]; - const functionVersion = process.env[FUNCTIONS_VERSION]; /** * Checks that we are operating within an Azure Function using the function version since WEBSITE_SITE_NAME * will exist in Azure App Service as well and detectors should be mutually exclusive. + * If the function version is not present, we check for the website sku to determine if it is a function. */ - if (serviceName && functionVersion) { + if (serviceName && isAzureFunction()) { const functionInstance = process.env[WEBSITE_INSTANCE_ID]; const functionMemLimit = process.env[FUNCTIONS_MEM_LIMIT]; diff --git a/detectors/node/opentelemetry-resource-detector-azure/src/types.ts b/detectors/node/opentelemetry-resource-detector-azure/src/types.ts index 645b4b7073..965bbba4ad 100644 --- a/detectors/node/opentelemetry-resource-detector-azure/src/types.ts +++ b/detectors/node/opentelemetry-resource-detector-azure/src/types.ts @@ -25,6 +25,7 @@ export const WEBSITE_OWNER_NAME = 'WEBSITE_OWNER_NAME'; export const WEBSITE_RESOURCE_GROUP = 'WEBSITE_RESOURCE_GROUP'; export const WEBSITE_SITE_NAME = 'WEBSITE_SITE_NAME'; export const WEBSITE_SLOT_NAME = 'WEBSITE_SLOT_NAME'; +export const WEBSITE_SKU = 'WEBSITE_SKU'; export const FUNCTIONS_VERSION = 'FUNCTIONS_EXTENSION_VERSION'; export const FUNCTIONS_MEM_LIMIT = 'WEBSITE_MEMORY_LIMIT_MB'; diff --git a/detectors/node/opentelemetry-resource-detector-azure/src/utils.ts b/detectors/node/opentelemetry-resource-detector-azure/src/utils.ts index 2b12431bdd..ceb548de27 100644 --- a/detectors/node/opentelemetry-resource-detector-azure/src/utils.ts +++ b/detectors/node/opentelemetry-resource-detector-azure/src/utils.ts @@ -14,7 +14,12 @@ * limitations under the License. */ -import { WEBSITE_OWNER_NAME, WEBSITE_RESOURCE_GROUP } from './types'; +import { + FUNCTIONS_VERSION, + WEBSITE_OWNER_NAME, + WEBSITE_RESOURCE_GROUP, + WEBSITE_SKU, +} from './types'; export function getAzureResourceUri( websiteSiteName: string @@ -33,3 +38,10 @@ export function getAzureResourceUri( return `/subscriptions/${subscriptionId}/resourceGroups/${websiteResourceGroup}/providers/Microsoft.Web/sites/${websiteSiteName}`; } + +export function isAzureFunction(): boolean { + return !!( + process.env[FUNCTIONS_VERSION] || + process.env[WEBSITE_SKU] === 'FlexConsumption' + ); +} diff --git a/detectors/node/opentelemetry-resource-detector-azure/test/detectors/AzureFunctionsDetector.test.ts b/detectors/node/opentelemetry-resource-detector-azure/test/detectors/AzureFunctionsDetector.test.ts index 1effe3a996..4c5710958c 100644 --- a/detectors/node/opentelemetry-resource-detector-azure/test/detectors/AzureFunctionsDetector.test.ts +++ b/detectors/node/opentelemetry-resource-detector-azure/test/detectors/AzureFunctionsDetector.test.ts @@ -102,3 +102,27 @@ describe('AzureFunctionsDetector', () => { ); }); }); + +it('should detect azure functions if websiteSku is defined as FlexConsumption', () => { + assert.ok(!process.env.WEBSITE_SKU && !process.env.FUNCTIONS_VERSION); + process.env.WEBSITE_SITE_NAME = 'test-service'; + process.env.REGION_NAME = 'test-region'; + process.env.WEBSITE_INSTANCE_ID = 'test-instance-id'; + process.env.WEBSITE_SKU = 'FlexConsumption'; + process.env.WEBSITE_MEMORY_LIMIT_MB = '1000'; + process.env.WEBSITE_OWNER_NAME = 'test-owner-name'; + process.env.WEBSITE_RESOURCE_GROUP = 'test-resource-group'; + + const resource = detectResourcesSync({ + detectors: [azureFunctionsDetector, azureAppServiceDetector], + }); + assert.ok(resource); + const attributes = resource.attributes; + assert.strictEqual(attributes[SEMRESATTRS_SERVICE_NAME], 'test-service'); + assert.strictEqual(attributes[SEMRESATTRS_CLOUD_PROVIDER], 'azure'); + + // Should not detect app service values + assert.strictEqual(attributes[SEMRESATTRS_SERVICE_INSTANCE_ID], undefined); + assert.strictEqual(attributes[SEMRESATTRS_PROCESS_PID], process.pid); + delete process.env.WEBSITE_SKU; +});