@opentelemetry/resource-detector-azure 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -34,7 +34,8 @@ class AzureAppServiceDetector {
34
34
  detect() {
35
35
  let attributes = {};
36
36
  const websiteSiteName = process.env[types_1.WEBSITE_SITE_NAME];
37
- if (websiteSiteName) {
37
+ const isAzureFunction = !!process.env[types_1.FUNCTIONS_VERSION];
38
+ if (websiteSiteName && !isAzureFunction) {
38
39
  attributes = Object.assign(Object.assign({}, attributes), { [semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: websiteSiteName });
39
40
  attributes = Object.assign(Object.assign({}, attributes), { [semantic_conventions_1.SemanticResourceAttributes.CLOUD_PROVIDER]: semantic_conventions_1.CloudProviderValues.AZURE });
40
41
  attributes = Object.assign(Object.assign({}, attributes), { [semantic_conventions_1.SemanticResourceAttributes.CLOUD_PLATFORM]: semantic_conventions_1.CloudPlatformValues.AZURE_APP_SERVICE });
@@ -1 +1 @@
1
- {"version":3,"file":"AzureAppServiceDetector.js","sourceRoot":"","sources":["../../../src/detectors/AzureAppServiceDetector.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,wDAA6E;AAC7E,oCAWkB;AAClB,8EAI6C;AAE7C,MAAM,8BAA8B,GAAG;IACrC,CAAC,iDAA0B,CAAC,YAAY,CAAC,EAAE,mBAAW;IACtD,CAAC,iDAA0B,CAAC,sBAAsB,CAAC,EAAE,yBAAiB;IACtE,CAAC,iDAA0B,CAAC,OAAO,CAAC,EAAE,wBAAgB;IACtD,CAAC,iDAA0B,CAAC,mBAAmB,CAAC,EAAE,2BAAmB;IACrE,CAAC,kDAA0C,CAAC,EAAE,8BAAsB;CACrE,CAAC;AAEF;;;GAGG;AACH,MAAM,uBAAuB;IAC3B,MAAM;QACJ,IAAI,UAAU,GAAG,EAAE,CAAC;QACpB,MAAM,eAAe,GAAG,OAAO,CAAC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C,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;SACjD;QAED,IAAI,CAAC,cAAc,IAAI,CAAC,gBAAgB,EAAE;YACxC,OAAO,SAAS,CAAC;SAClB;QAED,OAAO,kBAAkB,cAAc,mBAAmB,oBAAoB,kCAAkC,eAAe,EAAE,CAAC;IACpI,CAAC;CACF;AAEY,QAAA,uBAAuB,GAAG,IAAI,uBAAuB,EAAE,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { DetectorSync, IResource, Resource } from '@opentelemetry/resources';\nimport {\n AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE,\n REGION_NAME,\n WEBSITE_HOME_STAMPNAME,\n WEBSITE_HOSTNAME,\n WEBSITE_INSTANCE_ID,\n WEBSITE_OWNER_NAME,\n WEBSITE_RESOURCE_GROUP,\n WEBSITE_SITE_NAME,\n WEBSITE_SLOT_NAME,\n CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE,\n} from '../types';\nimport {\n CloudProviderValues,\n CloudPlatformValues,\n SemanticResourceAttributes,\n} from '@opentelemetry/semantic-conventions';\n\nconst APP_SERVICE_ATTRIBUTE_ENV_VARS = {\n [SemanticResourceAttributes.CLOUD_REGION]: REGION_NAME,\n [SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: WEBSITE_SLOT_NAME,\n [SemanticResourceAttributes.HOST_ID]: WEBSITE_HOSTNAME,\n [SemanticResourceAttributes.SERVICE_INSTANCE_ID]: WEBSITE_INSTANCE_ID,\n [AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE]: WEBSITE_HOME_STAMPNAME,\n};\n\n/**\n * The AzureAppServiceDetector can be used to detect if a process is running in an Azure App Service\n * @returns a {@link Resource} populated with data about the environment or an empty Resource if detection fails.\n */\nclass AzureAppServiceDetector implements DetectorSync {\n detect(): IResource {\n let attributes = {};\n const websiteSiteName = process.env[WEBSITE_SITE_NAME];\n if (websiteSiteName) {\n attributes = {\n ...attributes,\n [SemanticResourceAttributes.SERVICE_NAME]: websiteSiteName,\n };\n attributes = {\n ...attributes,\n [SemanticResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AZURE,\n };\n attributes = {\n ...attributes,\n [SemanticResourceAttributes.CLOUD_PLATFORM]:\n CloudPlatformValues.AZURE_APP_SERVICE,\n };\n\n const azureResourceUri = this.getAzureResourceUri(websiteSiteName);\n if (azureResourceUri) {\n attributes = {\n ...attributes,\n ...{ [CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE]: azureResourceUri },\n };\n }\n\n for (const [key, value] of Object.entries(\n APP_SERVICE_ATTRIBUTE_ENV_VARS\n )) {\n const envVar = process.env[value];\n if (envVar) {\n attributes = { ...attributes, ...{ [key]: envVar } };\n }\n }\n }\n return new Resource(attributes);\n }\n\n private getAzureResourceUri(websiteSiteName: string): string | undefined {\n const websiteResourceGroup = process.env[WEBSITE_RESOURCE_GROUP];\n const websiteOwnerName = process.env[WEBSITE_OWNER_NAME];\n\n let subscriptionId = websiteOwnerName;\n if (websiteOwnerName && websiteOwnerName.indexOf('+') !== -1) {\n subscriptionId = websiteOwnerName.split('+')[0];\n }\n\n if (!subscriptionId && !websiteOwnerName) {\n return undefined;\n }\n\n return `/subscriptions/${subscriptionId}/resourceGroups/${websiteResourceGroup}/providers/Microsoft.Web/sites/${websiteSiteName}`;\n }\n}\n\nexport const azureAppServiceDetector = new AzureAppServiceDetector();\n"]}
1
+ {"version":3,"file":"AzureAppServiceDetector.js","sourceRoot":"","sources":["../../../src/detectors/AzureAppServiceDetector.ts"],"names":[],"mapp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AAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBAClC,IAAI,MAAM,EAAE;oBACV,UAAU,mCAAQ,UAAU,GAAK,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,CAAE,CAAC;iBACtD;aACF;SACF;QACD,OAAO,IAAI,oBAAQ,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC;IAEO,mBAAmB,CAAC,eAAuB;QACjD,MAAM,oBAAoB,GAAG,OAAO,CAAC,GAAG,CAAC,8BAAsB,CAAC,CAAC;QACjE,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,0BAAkB,CAAC,CAAC;QAEzD,IAAI,cAAc,GAAG,gBAAgB,CAAC;QACtC,IAAI,gBAAgB,IAAI,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE;YAC5D,cAAc,GAAG,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;SACjD;QAED,IAAI,CAAC,cAAc,IAAI,CAAC,gBAAgB,EAAE;YACxC,OAAO,SAAS,CAAC;SAClB;QAED,OAAO,kBAAkB,cAAc,mBAAmB,oBAAoB,kCAAkC,eAAe,EAAE,CAAC;IACpI,CAAC;CACF;AAEY,QAAA,uBAAuB,GAAG,IAAI,uBAAuB,EAAE,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { DetectorSync, IResource, Resource } from '@opentelemetry/resources';\nimport {\n AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE,\n REGION_NAME,\n WEBSITE_HOME_STAMPNAME,\n WEBSITE_HOSTNAME,\n WEBSITE_INSTANCE_ID,\n WEBSITE_OWNER_NAME,\n WEBSITE_RESOURCE_GROUP,\n WEBSITE_SITE_NAME,\n WEBSITE_SLOT_NAME,\n CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE,\n FUNCTIONS_VERSION,\n} from '../types';\nimport {\n CloudProviderValues,\n CloudPlatformValues,\n SemanticResourceAttributes,\n} from '@opentelemetry/semantic-conventions';\n\nconst APP_SERVICE_ATTRIBUTE_ENV_VARS = {\n [SemanticResourceAttributes.CLOUD_REGION]: REGION_NAME,\n [SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: WEBSITE_SLOT_NAME,\n [SemanticResourceAttributes.HOST_ID]: WEBSITE_HOSTNAME,\n [SemanticResourceAttributes.SERVICE_INSTANCE_ID]: WEBSITE_INSTANCE_ID,\n [AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE]: WEBSITE_HOME_STAMPNAME,\n};\n\n/**\n * The AzureAppServiceDetector can be used to detect if a process is running in an Azure App Service\n * @returns a {@link Resource} populated with data about the environment or an empty Resource if detection fails.\n */\nclass AzureAppServiceDetector implements DetectorSync {\n detect(): IResource {\n let attributes = {};\n const websiteSiteName = process.env[WEBSITE_SITE_NAME];\n const isAzureFunction = !!process.env[FUNCTIONS_VERSION];\n if (websiteSiteName && !isAzureFunction) {\n attributes = {\n ...attributes,\n [SemanticResourceAttributes.SERVICE_NAME]: websiteSiteName,\n };\n attributes = {\n ...attributes,\n [SemanticResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AZURE,\n };\n attributes = {\n ...attributes,\n [SemanticResourceAttributes.CLOUD_PLATFORM]:\n CloudPlatformValues.AZURE_APP_SERVICE,\n };\n\n const azureResourceUri = this.getAzureResourceUri(websiteSiteName);\n if (azureResourceUri) {\n attributes = {\n ...attributes,\n ...{ [CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE]: azureResourceUri },\n };\n }\n\n for (const [key, value] of Object.entries(\n APP_SERVICE_ATTRIBUTE_ENV_VARS\n )) {\n const envVar = process.env[value];\n if (envVar) {\n attributes = { ...attributes, ...{ [key]: envVar } };\n }\n }\n }\n return new Resource(attributes);\n }\n\n private getAzureResourceUri(websiteSiteName: string): string | undefined {\n const websiteResourceGroup = process.env[WEBSITE_RESOURCE_GROUP];\n const websiteOwnerName = process.env[WEBSITE_OWNER_NAME];\n\n let subscriptionId = websiteOwnerName;\n if (websiteOwnerName && websiteOwnerName.indexOf('+') !== -1) {\n subscriptionId = websiteOwnerName.split('+')[0];\n }\n\n if (!subscriptionId && !websiteOwnerName) {\n return undefined;\n }\n\n return `/subscriptions/${subscriptionId}/resourceGroups/${websiteResourceGroup}/providers/Microsoft.Web/sites/${websiteSiteName}`;\n }\n}\n\nexport const azureAppServiceDetector = new AzureAppServiceDetector();\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentelemetry/resource-detector-azure",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "OpenTelemetry SDK resource detector for Azure",
5
5
  "main": "build/src/index.js",
6
6
  "types": "build/src/index.d.ts",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "devDependencies": {
34
34
  "@opentelemetry/api": "^1.0.0",
35
- "@opentelemetry/contrib-test-utils": "^0.35.0",
35
+ "@opentelemetry/contrib-test-utils": "^0.36.0",
36
36
  "@types/mocha": "8.2.3",
37
37
  "@types/node": "18.6.5",
38
38
  "@types/sinon": "10.0.18",
@@ -48,5 +48,5 @@
48
48
  "@opentelemetry/semantic-conventions": "^1.0.0"
49
49
  },
50
50
  "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/detectors/node/opentelemetry-resource-detector-azure#readme",
51
- "gitHead": "c7e7000b7bf79b0b107c448b403c2613a9b9e2c1"
51
+ "gitHead": "32204a362d9dffd4cd69a1300e1f7d245df9df52"
52
52
  }