@opentelemetry/resource-detector-azure 0.6.1 → 0.8.0

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.
package/README.md CHANGED
@@ -18,7 +18,7 @@ npm install --save @opentelemetry/resource-detector-azure
18
18
  ```typescript
19
19
  import { detectResources } from '@opentelemetry/resources';
20
20
  import { azureAppServiceDetector } from '@opentelemetry/resource-detector-azure';
21
- const resource = detectResourcesSync({
21
+ const resource = detectResources({
22
22
  detectors: [azureAppServiceDetector],
23
23
  });
24
24
 
@@ -1,10 +1,10 @@
1
- import { DetectorSync, IResource } from '@opentelemetry/resources';
1
+ import { ResourceDetector, DetectedResource } from '@opentelemetry/resources';
2
2
  /**
3
3
  * The AzureAppServiceDetector can be used to detect if a process is running in an Azure App Service
4
4
  * @returns a {@link Resource} populated with data about the environment or an empty Resource if detection fails.
5
5
  */
6
- declare class AzureAppServiceDetector implements DetectorSync {
7
- detect(): IResource;
6
+ declare class AzureAppServiceDetector implements ResourceDetector {
7
+ detect(): DetectedResource;
8
8
  }
9
9
  export declare const azureAppServiceDetector: AzureAppServiceDetector;
10
10
  export {};
@@ -13,59 +13,53 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- var __assign = (this && this.__assign) || function () {
17
- __assign = Object.assign || function(t) {
18
- for (var s, i = 1, n = arguments.length; i < n; i++) {
19
- s = arguments[i];
20
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
- t[p] = s[p];
22
- }
23
- return t;
24
- };
25
- return __assign.apply(this, arguments);
26
- };
27
- var _a;
28
- import { Resource } from '@opentelemetry/resources';
29
16
  import { AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE, REGION_NAME, WEBSITE_HOME_STAMPNAME, WEBSITE_HOSTNAME, WEBSITE_INSTANCE_ID, WEBSITE_SITE_NAME, WEBSITE_SLOT_NAME, CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE, } from '../types';
30
17
  import { SEMRESATTRS_CLOUD_REGION, SEMRESATTRS_DEPLOYMENT_ENVIRONMENT, SEMRESATTRS_HOST_ID, SEMRESATTRS_SERVICE_INSTANCE_ID, SEMRESATTRS_SERVICE_NAME, SEMRESATTRS_CLOUD_PROVIDER, SEMRESATTRS_CLOUD_PLATFORM, CLOUDPROVIDERVALUES_AZURE, CLOUDPLATFORMVALUES_AZURE_APP_SERVICE, } from '@opentelemetry/semantic-conventions';
31
18
  import { getAzureResourceUri, isAzureFunction } from '../utils';
32
- var APP_SERVICE_ATTRIBUTE_ENV_VARS = (_a = {},
33
- _a[SEMRESATTRS_CLOUD_REGION] = REGION_NAME,
34
- _a[SEMRESATTRS_DEPLOYMENT_ENVIRONMENT] = WEBSITE_SLOT_NAME,
35
- _a[SEMRESATTRS_HOST_ID] = WEBSITE_HOSTNAME,
36
- _a[SEMRESATTRS_SERVICE_INSTANCE_ID] = WEBSITE_INSTANCE_ID,
37
- _a[AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE] = WEBSITE_HOME_STAMPNAME,
38
- _a);
19
+ const APP_SERVICE_ATTRIBUTE_ENV_VARS = {
20
+ [SEMRESATTRS_CLOUD_REGION]: REGION_NAME,
21
+ [SEMRESATTRS_DEPLOYMENT_ENVIRONMENT]: WEBSITE_SLOT_NAME,
22
+ [SEMRESATTRS_HOST_ID]: WEBSITE_HOSTNAME,
23
+ [SEMRESATTRS_SERVICE_INSTANCE_ID]: WEBSITE_INSTANCE_ID,
24
+ [AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE]: WEBSITE_HOME_STAMPNAME,
25
+ };
39
26
  /**
40
27
  * The AzureAppServiceDetector can be used to detect if a process is running in an Azure App Service
41
28
  * @returns a {@link Resource} populated with data about the environment or an empty Resource if detection fails.
42
29
  */
43
- var AzureAppServiceDetector = /** @class */ (function () {
44
- function AzureAppServiceDetector() {
45
- }
46
- AzureAppServiceDetector.prototype.detect = function () {
47
- var _a, _b, _c, _d, _e;
48
- var attributes = {};
49
- var websiteSiteName = process.env[WEBSITE_SITE_NAME];
30
+ class AzureAppServiceDetector {
31
+ detect() {
32
+ let attributes = {};
33
+ const websiteSiteName = process.env[WEBSITE_SITE_NAME];
50
34
  if (websiteSiteName && !isAzureFunction()) {
51
- attributes = __assign(__assign({}, attributes), (_a = {}, _a[SEMRESATTRS_SERVICE_NAME] = websiteSiteName, _a));
52
- attributes = __assign(__assign({}, attributes), (_b = {}, _b[SEMRESATTRS_CLOUD_PROVIDER] = CLOUDPROVIDERVALUES_AZURE, _b));
53
- attributes = __assign(__assign({}, attributes), (_c = {}, _c[SEMRESATTRS_CLOUD_PLATFORM] = CLOUDPLATFORMVALUES_AZURE_APP_SERVICE, _c));
54
- var azureResourceUri = getAzureResourceUri(websiteSiteName);
35
+ attributes = {
36
+ ...attributes,
37
+ [SEMRESATTRS_SERVICE_NAME]: websiteSiteName,
38
+ };
39
+ attributes = {
40
+ ...attributes,
41
+ [SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AZURE,
42
+ };
43
+ attributes = {
44
+ ...attributes,
45
+ [SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AZURE_APP_SERVICE,
46
+ };
47
+ const azureResourceUri = getAzureResourceUri(websiteSiteName);
55
48
  if (azureResourceUri) {
56
- attributes = __assign(__assign({}, attributes), (_d = {}, _d[CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE] = azureResourceUri, _d));
49
+ attributes = {
50
+ ...attributes,
51
+ ...{ [CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE]: azureResourceUri },
52
+ };
57
53
  }
58
- for (var _i = 0, _f = Object.entries(APP_SERVICE_ATTRIBUTE_ENV_VARS); _i < _f.length; _i++) {
59
- var _g = _f[_i], key = _g[0], value = _g[1];
60
- var envVar = process.env[value];
54
+ for (const [key, value] of Object.entries(APP_SERVICE_ATTRIBUTE_ENV_VARS)) {
55
+ const envVar = process.env[value];
61
56
  if (envVar) {
62
- attributes = __assign(__assign({}, attributes), (_e = {}, _e[key] = envVar, _e));
57
+ attributes = { ...attributes, ...{ [key]: envVar } };
63
58
  }
64
59
  }
65
60
  }
66
- return new Resource(attributes);
67
- };
68
- return AzureAppServiceDetector;
69
- }());
70
- export var azureAppServiceDetector = new AzureAppServiceDetector();
61
+ return { attributes };
62
+ }
63
+ }
64
+ export const azureAppServiceDetector = new AzureAppServiceDetector();
71
65
  //# sourceMappingURL=AzureAppServiceDetector.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AzureAppServiceDetector.js","sourceRoot":"","sources":["../../../src/detectors/AzureAppServiceDetector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;AAEH,OAAO,EAA2B,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EACL,0CAA0C,EAC1C,WAAW,EACX,sBAAsB,EACtB,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,oCAAoC,GACrC,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,wBAAwB,EACxB,kCAAkC,EAClC,mBAAmB,EACnB,+BAA+B,EAC/B,wBAAwB,EACxB,0BAA0B,EAC1B,0BAA0B,EAC1B,yBAAyB,EACzB,qCAAqC,GACtC,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhE,IAAM,8BAA8B;IAClC,GAAC,wBAAwB,IAAG,WAAW;IACvC,GAAC,kCAAkC,IAAG,iBAAiB;IACvD,GAAC,mBAAmB,IAAG,gBAAgB;IACvC,GAAC,+BAA+B,IAAG,mBAAmB;IACtD,GAAC,0CAA0C,IAAG,sBAAsB;OACrE,CAAC;AAEF;;;GAGG;AACH;IAAA;IAqCA,CAAC;IApCC,wCAAM,GAAN;;QACE,IAAI,UAAU,GAAG,EAAE,CAAC;QACpB,IAAM,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QACvD,IAAI,eAAe,IAAI,CAAC,eAAe,EAAE,EAAE;YACzC,UAAU,yBACL,UAAU,gBACZ,wBAAwB,IAAG,eAAe,MAC5C,CAAC;YACF,UAAU,yBACL,UAAU,gBACZ,0BAA0B,IAAG,yBAAyB,MACxD,CAAC;YACF,UAAU,yBACL,UAAU,gBACZ,0BAA0B,IAAG,qCAAqC,MACpE,CAAC;YAEF,IAAM,gBAAgB,GAAG,mBAAmB,CAAC,eAAe,CAAC,CAAC;YAC9D,IAAI,gBAAgB,EAAE;gBACpB,UAAU,yBACL,UAAU,aACR,GAAC,oCAAoC,IAAG,gBAAgB,MAC9D,CAAC;aACH;YAED,KAA2B,UAE1B,EAF0B,KAAA,MAAM,CAAC,OAAO,CACvC,8BAA8B,CAC/B,EAF0B,cAE1B,EAF0B,IAE1B,EAAE;gBAFQ,IAAA,WAAY,EAAX,GAAG,QAAA,EAAE,KAAK,QAAA;gBAGpB,IAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBAClC,IAAI,MAAM,EAAE;oBACV,UAAU,yBAAQ,UAAU,aAAO,GAAC,GAAG,IAAG,MAAM,MAAI,CAAC;iBACtD;aACF;SACF;QACD,OAAO,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC;IACH,8BAAC;AAAD,CAAC,AArCD,IAqCC;AAED,MAAM,CAAC,IAAM,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_SITE_NAME,\n WEBSITE_SLOT_NAME,\n CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE,\n} from '../types';\nimport {\n SEMRESATTRS_CLOUD_REGION,\n SEMRESATTRS_DEPLOYMENT_ENVIRONMENT,\n SEMRESATTRS_HOST_ID,\n SEMRESATTRS_SERVICE_INSTANCE_ID,\n SEMRESATTRS_SERVICE_NAME,\n SEMRESATTRS_CLOUD_PROVIDER,\n SEMRESATTRS_CLOUD_PLATFORM,\n CLOUDPROVIDERVALUES_AZURE,\n CLOUDPLATFORMVALUES_AZURE_APP_SERVICE,\n} from '@opentelemetry/semantic-conventions';\nimport { getAzureResourceUri, isAzureFunction } from '../utils';\n\nconst APP_SERVICE_ATTRIBUTE_ENV_VARS = {\n [SEMRESATTRS_CLOUD_REGION]: REGION_NAME,\n [SEMRESATTRS_DEPLOYMENT_ENVIRONMENT]: WEBSITE_SLOT_NAME,\n [SEMRESATTRS_HOST_ID]: WEBSITE_HOSTNAME,\n [SEMRESATTRS_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 && !isAzureFunction()) {\n attributes = {\n ...attributes,\n [SEMRESATTRS_SERVICE_NAME]: websiteSiteName,\n };\n attributes = {\n ...attributes,\n [SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AZURE,\n };\n attributes = {\n ...attributes,\n [SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AZURE_APP_SERVICE,\n };\n\n const azureResourceUri = 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\nexport const azureAppServiceDetector = new AzureAppServiceDetector();\n"]}
1
+ {"version":3,"file":"AzureAppServiceDetector.js","sourceRoot":"","sources":["../../../src/detectors/AzureAppServiceDetector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EACL,0CAA0C,EAC1C,WAAW,EACX,sBAAsB,EACtB,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,oCAAoC,GACrC,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,wBAAwB,EACxB,kCAAkC,EAClC,mBAAmB,EACnB,+BAA+B,EAC/B,wBAAwB,EACxB,0BAA0B,EAC1B,0BAA0B,EAC1B,yBAAyB,EACzB,qCAAqC,GACtC,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhE,MAAM,8BAA8B,GAAG;IACrC,CAAC,wBAAwB,CAAC,EAAE,WAAW;IACvC,CAAC,kCAAkC,CAAC,EAAE,iBAAiB;IACvD,CAAC,mBAAmB,CAAC,EAAE,gBAAgB;IACvC,CAAC,+BAA+B,CAAC,EAAE,mBAAmB;IACtD,CAAC,0CAA0C,CAAC,EAAE,sBAAsB;CACrE,CAAC;AAEF;;;GAGG;AACH,MAAM,uBAAuB;IAC3B,MAAM;QACJ,IAAI,UAAU,GAAG,EAAE,CAAC;QACpB,MAAM,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QACvD,IAAI,eAAe,IAAI,CAAC,eAAe,EAAE,EAAE;YACzC,UAAU,GAAG;gBACX,GAAG,UAAU;gBACb,CAAC,wBAAwB,CAAC,EAAE,eAAe;aAC5C,CAAC;YACF,UAAU,GAAG;gBACX,GAAG,UAAU;gBACb,CAAC,0BAA0B,CAAC,EAAE,yBAAyB;aACxD,CAAC;YACF,UAAU,GAAG;gBACX,GAAG,UAAU;gBACb,CAAC,0BAA0B,CAAC,EAAE,qCAAqC;aACpE,CAAC;YAEF,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,eAAe,CAAC,CAAC;YAC9D,IAAI,gBAAgB,EAAE;gBACpB,UAAU,GAAG;oBACX,GAAG,UAAU;oBACb,GAAG,EAAE,CAAC,oCAAoC,CAAC,EAAE,gBAAgB,EAAE;iBAChE,CAAC;aACH;YAED,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CACvC,8BAA8B,CAC/B,EAAE;gBACD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBAClC,IAAI,MAAM,EAAE;oBACV,UAAU,GAAG,EAAE,GAAG,UAAU,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;iBACtD;aACF;SACF;QACD,OAAO,EAAE,UAAU,EAAE,CAAC;IACxB,CAAC;CACF;AAED,MAAM,CAAC,MAAM,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 { ResourceDetector, DetectedResource } 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_SITE_NAME,\n WEBSITE_SLOT_NAME,\n CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE,\n} from '../types';\nimport {\n SEMRESATTRS_CLOUD_REGION,\n SEMRESATTRS_DEPLOYMENT_ENVIRONMENT,\n SEMRESATTRS_HOST_ID,\n SEMRESATTRS_SERVICE_INSTANCE_ID,\n SEMRESATTRS_SERVICE_NAME,\n SEMRESATTRS_CLOUD_PROVIDER,\n SEMRESATTRS_CLOUD_PLATFORM,\n CLOUDPROVIDERVALUES_AZURE,\n CLOUDPLATFORMVALUES_AZURE_APP_SERVICE,\n} from '@opentelemetry/semantic-conventions';\nimport { getAzureResourceUri, isAzureFunction } from '../utils';\n\nconst APP_SERVICE_ATTRIBUTE_ENV_VARS = {\n [SEMRESATTRS_CLOUD_REGION]: REGION_NAME,\n [SEMRESATTRS_DEPLOYMENT_ENVIRONMENT]: WEBSITE_SLOT_NAME,\n [SEMRESATTRS_HOST_ID]: WEBSITE_HOSTNAME,\n [SEMRESATTRS_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 ResourceDetector {\n detect(): DetectedResource {\n let attributes = {};\n const websiteSiteName = process.env[WEBSITE_SITE_NAME];\n if (websiteSiteName && !isAzureFunction()) {\n attributes = {\n ...attributes,\n [SEMRESATTRS_SERVICE_NAME]: websiteSiteName,\n };\n attributes = {\n ...attributes,\n [SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AZURE,\n };\n attributes = {\n ...attributes,\n [SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AZURE_APP_SERVICE,\n };\n\n const azureResourceUri = 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 { attributes };\n }\n}\n\nexport const azureAppServiceDetector = new AzureAppServiceDetector();\n"]}
@@ -1,10 +1,10 @@
1
- import { DetectorSync, IResource } from '@opentelemetry/resources';
1
+ import { ResourceDetector, DetectedResource } from '@opentelemetry/resources';
2
2
  /**
3
3
  * The AzureFunctionsDetector can be used to detect if a process is running in Azure Functions
4
4
  * @returns a {@link Resource} populated with data about the environment or an empty Resource if detection fails.
5
5
  */
6
- declare class AzureFunctionsDetector implements DetectorSync {
7
- detect(): IResource;
6
+ declare class AzureFunctionsDetector implements ResourceDetector {
7
+ detect(): DetectedResource;
8
8
  }
9
9
  export declare const azureFunctionsDetector: AzureFunctionsDetector;
10
10
  export {};
@@ -13,76 +13,70 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- var __assign = (this && this.__assign) || function () {
17
- __assign = Object.assign || function(t) {
18
- for (var s, i = 1, n = arguments.length; i < n; i++) {
19
- s = arguments[i];
20
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
- t[p] = s[p];
22
- }
23
- return t;
24
- };
25
- return __assign.apply(this, arguments);
26
- };
27
- var _a;
28
- import { Resource } from '@opentelemetry/resources';
29
16
  import { SEMRESATTRS_FAAS_MAX_MEMORY, SEMRESATTRS_FAAS_INSTANCE, SEMRESATTRS_CLOUD_PROVIDER, SEMRESATTRS_CLOUD_PLATFORM, SEMRESATTRS_CLOUD_REGION, CLOUDPROVIDERVALUES_AZURE, CLOUDPLATFORMVALUES_AZURE_FUNCTIONS, SEMRESATTRS_SERVICE_NAME, SEMRESATTRS_PROCESS_PID, } from '@opentelemetry/semantic-conventions';
30
17
  import { WEBSITE_SITE_NAME, WEBSITE_INSTANCE_ID, FUNCTIONS_MEM_LIMIT, REGION_NAME, CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE, } from '../types';
31
18
  import { getAzureResourceUri, isAzureFunction } from '../utils';
32
- var AZURE_FUNCTIONS_ATTRIBUTE_ENV_VARS = (_a = {},
33
- _a[SEMRESATTRS_SERVICE_NAME] = WEBSITE_SITE_NAME,
34
- _a[SEMRESATTRS_FAAS_INSTANCE] = WEBSITE_INSTANCE_ID,
35
- _a[SEMRESATTRS_FAAS_MAX_MEMORY] = FUNCTIONS_MEM_LIMIT,
36
- _a);
19
+ const AZURE_FUNCTIONS_ATTRIBUTE_ENV_VARS = {
20
+ [SEMRESATTRS_SERVICE_NAME]: WEBSITE_SITE_NAME,
21
+ [SEMRESATTRS_FAAS_INSTANCE]: WEBSITE_INSTANCE_ID,
22
+ [SEMRESATTRS_FAAS_MAX_MEMORY]: FUNCTIONS_MEM_LIMIT,
23
+ };
37
24
  /**
38
25
  * The AzureFunctionsDetector can be used to detect if a process is running in Azure Functions
39
26
  * @returns a {@link Resource} populated with data about the environment or an empty Resource if detection fails.
40
27
  */
41
- var AzureFunctionsDetector = /** @class */ (function () {
42
- function AzureFunctionsDetector() {
43
- }
44
- AzureFunctionsDetector.prototype.detect = function () {
45
- var _a, _b, _c, _d, _e, _f;
46
- var attributes = {};
47
- var serviceName = process.env[WEBSITE_SITE_NAME];
28
+ class AzureFunctionsDetector {
29
+ detect() {
30
+ let attributes = {};
31
+ const serviceName = process.env[WEBSITE_SITE_NAME];
48
32
  /**
49
33
  * Checks that we are operating within an Azure Function using the function version since WEBSITE_SITE_NAME
50
34
  * will exist in Azure App Service as well and detectors should be mutually exclusive.
51
35
  * If the function version is not present, we check for the website sku to determine if it is a function.
52
36
  */
53
37
  if (serviceName && isAzureFunction()) {
54
- var functionInstance = process.env[WEBSITE_INSTANCE_ID];
55
- var functionMemLimit = process.env[FUNCTIONS_MEM_LIMIT];
56
- attributes = (_a = {},
57
- _a[SEMRESATTRS_CLOUD_PROVIDER] = CLOUDPROVIDERVALUES_AZURE,
58
- _a[SEMRESATTRS_CLOUD_PLATFORM] = CLOUDPLATFORMVALUES_AZURE_FUNCTIONS,
59
- _a[SEMRESATTRS_CLOUD_REGION] = process.env[REGION_NAME],
60
- _a[SEMRESATTRS_PROCESS_PID] = process.pid,
61
- _a);
38
+ const functionInstance = process.env[WEBSITE_INSTANCE_ID];
39
+ const functionMemLimit = process.env[FUNCTIONS_MEM_LIMIT];
40
+ attributes = {
41
+ [SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AZURE,
42
+ [SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AZURE_FUNCTIONS,
43
+ [SEMRESATTRS_CLOUD_REGION]: process.env[REGION_NAME],
44
+ [SEMRESATTRS_PROCESS_PID]: process.pid,
45
+ };
62
46
  if (serviceName) {
63
- attributes = __assign(__assign({}, attributes), (_b = {}, _b[SEMRESATTRS_SERVICE_NAME] = serviceName, _b));
47
+ attributes = {
48
+ ...attributes,
49
+ [SEMRESATTRS_SERVICE_NAME]: serviceName,
50
+ };
64
51
  }
65
52
  if (functionInstance) {
66
- attributes = __assign(__assign({}, attributes), (_c = {}, _c[SEMRESATTRS_FAAS_INSTANCE] = functionInstance, _c));
53
+ attributes = {
54
+ ...attributes,
55
+ [SEMRESATTRS_FAAS_INSTANCE]: functionInstance,
56
+ };
67
57
  }
68
58
  if (functionMemLimit) {
69
- attributes = __assign(__assign({}, attributes), (_d = {}, _d[SEMRESATTRS_FAAS_MAX_MEMORY] = functionMemLimit, _d));
59
+ attributes = {
60
+ ...attributes,
61
+ [SEMRESATTRS_FAAS_MAX_MEMORY]: functionMemLimit,
62
+ };
70
63
  }
71
- var azureResourceUri = getAzureResourceUri(serviceName);
64
+ const azureResourceUri = getAzureResourceUri(serviceName);
72
65
  if (azureResourceUri) {
73
- attributes = __assign(__assign({}, attributes), (_e = {}, _e[CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE] = azureResourceUri, _e));
66
+ attributes = {
67
+ ...attributes,
68
+ ...{ [CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE]: azureResourceUri },
69
+ };
74
70
  }
75
- for (var _i = 0, _g = Object.entries(AZURE_FUNCTIONS_ATTRIBUTE_ENV_VARS); _i < _g.length; _i++) {
76
- var _h = _g[_i], key = _h[0], value = _h[1];
77
- var envVar = process.env[value];
71
+ for (const [key, value] of Object.entries(AZURE_FUNCTIONS_ATTRIBUTE_ENV_VARS)) {
72
+ const envVar = process.env[value];
78
73
  if (envVar) {
79
- attributes = __assign(__assign({}, attributes), (_f = {}, _f[key] = envVar, _f));
74
+ attributes = { ...attributes, ...{ [key]: envVar } };
80
75
  }
81
76
  }
82
77
  }
83
- return new Resource(attributes);
84
- };
85
- return AzureFunctionsDetector;
86
- }());
87
- export var azureFunctionsDetector = new AzureFunctionsDetector();
78
+ return { attributes };
79
+ }
80
+ }
81
+ export const azureFunctionsDetector = new AzureFunctionsDetector();
88
82
  //# sourceMappingURL=AzureFunctionsDetector.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AzureFunctionsDetector.js","sourceRoot":"","sources":["../../../src/detectors/AzureFunctionsDetector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;AAEH,OAAO,EAA2B,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAE7E,OAAO,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,IAAI,gBAAgB,EAAE;gBACpB,UAAU,yBACL,UAAU,gBACZ,2BAA2B,IAAG,gBAAgB,MAChD,CAAC;aACH;YACD,IAAM,gBAAgB,GAAG,mBAAmB,CAAC,WAAW,CAAC,CAAC;YAC1D,IAAI,gBAAgB,EAAE;gBACpB,UAAU,yBACL,UAAU,aACR,GAAC,oCAAoC,IAAG,gBAAgB,MAC9D,CAAC;aACH;YAED,KAA2B,UAE1B,EAF0B,KAAA,MAAM,CAAC,OAAO,CACvC,kCAAkC,CACnC,EAF0B,cAE1B,EAF0B,IAE1B,EAAE;gBAFQ,IAAA,WAAY,EAAX,GAAG,QAAA,EAAE,KAAK,QAAA;gBAGpB,IAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBAClC,IAAI,MAAM,EAAE;oBACV,UAAU,yBAAQ,UAAU,aAAO,GAAC,GAAG,IAAG,MAAM,MAAI,CAAC;iBACtD;aACF;SACF;QACD,OAAO,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC;IACH,6BAAC;AAAD,CAAC,AA1DD,IA0DC;AAED,MAAM,CAAC,IAAM,sBAAsB,GAAG,IAAI,sBAAsB,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';\n\nimport {\n SEMRESATTRS_FAAS_MAX_MEMORY,\n SEMRESATTRS_FAAS_INSTANCE,\n SEMRESATTRS_CLOUD_PROVIDER,\n SEMRESATTRS_CLOUD_PLATFORM,\n SEMRESATTRS_CLOUD_REGION,\n CLOUDPROVIDERVALUES_AZURE,\n CLOUDPLATFORMVALUES_AZURE_FUNCTIONS,\n SEMRESATTRS_SERVICE_NAME,\n SEMRESATTRS_PROCESS_PID,\n} from '@opentelemetry/semantic-conventions';\nimport {\n WEBSITE_SITE_NAME,\n WEBSITE_INSTANCE_ID,\n FUNCTIONS_MEM_LIMIT,\n REGION_NAME,\n CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE,\n} from '../types';\nimport { getAzureResourceUri, isAzureFunction } from '../utils';\n\nconst AZURE_FUNCTIONS_ATTRIBUTE_ENV_VARS = {\n [SEMRESATTRS_SERVICE_NAME]: WEBSITE_SITE_NAME,\n [SEMRESATTRS_FAAS_INSTANCE]: WEBSITE_INSTANCE_ID,\n [SEMRESATTRS_FAAS_MAX_MEMORY]: FUNCTIONS_MEM_LIMIT,\n};\n\n/**\n * The AzureFunctionsDetector can be used to detect if a process is running in Azure Functions\n * @returns a {@link Resource} populated with data about the environment or an empty Resource if detection fails.\n */\nclass AzureFunctionsDetector implements DetectorSync {\n detect(): IResource {\n let attributes = {};\n const serviceName = process.env[WEBSITE_SITE_NAME];\n\n /**\n * Checks that we are operating within an Azure Function using the function version since WEBSITE_SITE_NAME\n * will exist in Azure App Service as well and detectors should be mutually exclusive.\n * If the function version is not present, we check for the website sku to determine if it is a function.\n */\n if (serviceName && isAzureFunction()) {\n const functionInstance = process.env[WEBSITE_INSTANCE_ID];\n const functionMemLimit = process.env[FUNCTIONS_MEM_LIMIT];\n\n attributes = {\n [SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AZURE,\n [SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AZURE_FUNCTIONS,\n [SEMRESATTRS_CLOUD_REGION]: process.env[REGION_NAME],\n [SEMRESATTRS_PROCESS_PID]: process.pid,\n };\n\n if (serviceName) {\n attributes = {\n ...attributes,\n [SEMRESATTRS_SERVICE_NAME]: serviceName,\n };\n }\n if (functionInstance) {\n attributes = {\n ...attributes,\n [SEMRESATTRS_FAAS_INSTANCE]: functionInstance,\n };\n }\n if (functionMemLimit) {\n attributes = {\n ...attributes,\n [SEMRESATTRS_FAAS_MAX_MEMORY]: functionMemLimit,\n };\n }\n const azureResourceUri = getAzureResourceUri(serviceName);\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 AZURE_FUNCTIONS_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\nexport const azureFunctionsDetector = new AzureFunctionsDetector();\n"]}
1
+ {"version":3,"file":"AzureFunctionsDetector.js","sourceRoot":"","sources":["../../../src/detectors/AzureFunctionsDetector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,EAC1B,wBAAwB,EACxB,yBAAyB,EACzB,mCAAmC,EACnC,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,oCAAoC,GACrC,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhE,MAAM,kCAAkC,GAAG;IACzC,CAAC,wBAAwB,CAAC,EAAE,iBAAiB;IAC7C,CAAC,yBAAyB,CAAC,EAAE,mBAAmB;IAChD,CAAC,2BAA2B,CAAC,EAAE,mBAAmB;CACnD,CAAC;AAEF;;;GAGG;AACH,MAAM,sBAAsB;IAC1B,MAAM;QACJ,IAAI,UAAU,GAAG,EAAE,CAAC;QACpB,MAAM,WAAW,GAAG,OA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V,UAAU,GAAG,EAAE,GAAG,UAAU,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;iBACtD;aACF;SACF;QACD,OAAO,EAAE,UAAU,EAAE,CAAC;IACxB,CAAC;CACF;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,sBAAsB,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 { ResourceDetector, DetectedResource } from '@opentelemetry/resources';\nimport {\n SEMRESATTRS_FAAS_MAX_MEMORY,\n SEMRESATTRS_FAAS_INSTANCE,\n SEMRESATTRS_CLOUD_PROVIDER,\n SEMRESATTRS_CLOUD_PLATFORM,\n SEMRESATTRS_CLOUD_REGION,\n CLOUDPROVIDERVALUES_AZURE,\n CLOUDPLATFORMVALUES_AZURE_FUNCTIONS,\n SEMRESATTRS_SERVICE_NAME,\n SEMRESATTRS_PROCESS_PID,\n} from '@opentelemetry/semantic-conventions';\nimport {\n WEBSITE_SITE_NAME,\n WEBSITE_INSTANCE_ID,\n FUNCTIONS_MEM_LIMIT,\n REGION_NAME,\n CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE,\n} from '../types';\nimport { getAzureResourceUri, isAzureFunction } from '../utils';\n\nconst AZURE_FUNCTIONS_ATTRIBUTE_ENV_VARS = {\n [SEMRESATTRS_SERVICE_NAME]: WEBSITE_SITE_NAME,\n [SEMRESATTRS_FAAS_INSTANCE]: WEBSITE_INSTANCE_ID,\n [SEMRESATTRS_FAAS_MAX_MEMORY]: FUNCTIONS_MEM_LIMIT,\n};\n\n/**\n * The AzureFunctionsDetector can be used to detect if a process is running in Azure Functions\n * @returns a {@link Resource} populated with data about the environment or an empty Resource if detection fails.\n */\nclass AzureFunctionsDetector implements ResourceDetector {\n detect(): DetectedResource {\n let attributes = {};\n const serviceName = process.env[WEBSITE_SITE_NAME];\n\n /**\n * Checks that we are operating within an Azure Function using the function version since WEBSITE_SITE_NAME\n * will exist in Azure App Service as well and detectors should be mutually exclusive.\n * If the function version is not present, we check for the website sku to determine if it is a function.\n */\n if (serviceName && isAzureFunction()) {\n const functionInstance = process.env[WEBSITE_INSTANCE_ID];\n const functionMemLimit = process.env[FUNCTIONS_MEM_LIMIT];\n\n attributes = {\n [SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AZURE,\n [SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AZURE_FUNCTIONS,\n [SEMRESATTRS_CLOUD_REGION]: process.env[REGION_NAME],\n [SEMRESATTRS_PROCESS_PID]: process.pid,\n };\n\n if (serviceName) {\n attributes = {\n ...attributes,\n [SEMRESATTRS_SERVICE_NAME]: serviceName,\n };\n }\n if (functionInstance) {\n attributes = {\n ...attributes,\n [SEMRESATTRS_FAAS_INSTANCE]: functionInstance,\n };\n }\n if (functionMemLimit) {\n attributes = {\n ...attributes,\n [SEMRESATTRS_FAAS_MAX_MEMORY]: functionMemLimit,\n };\n }\n const azureResourceUri = getAzureResourceUri(serviceName);\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 AZURE_FUNCTIONS_ATTRIBUTE_ENV_VARS\n )) {\n const envVar = process.env[value];\n if (envVar) {\n attributes = { ...attributes, ...{ [key]: envVar } };\n }\n }\n }\n return { attributes };\n }\n}\n\nexport const azureFunctionsDetector = new AzureFunctionsDetector();\n"]}
@@ -1,11 +1,11 @@
1
- import { DetectorSync, IResource, ResourceAttributes } from '@opentelemetry/resources';
1
+ import { ResourceDetector, DetectedResource, DetectedResourceAttributes } from '@opentelemetry/resources';
2
2
  /**
3
3
  * The AzureVmDetector can be used to detect if a process is running in an Azure VM.
4
4
  * @returns a {@link Resource} populated with data about the environment or an empty Resource if detection fails.
5
5
  */
6
- declare class AzureVmResourceDetector implements DetectorSync {
7
- detect(): IResource;
8
- getAzureVmMetadata(): Promise<ResourceAttributes>;
6
+ declare class AzureVmResourceDetector implements ResourceDetector {
7
+ detect(): DetectedResource;
8
+ getAzureVmMetadata(): Promise<DetectedResourceAttributes>;
9
9
  }
10
10
  export declare const azureVmDetector: AzureVmResourceDetector;
11
11
  export {};
@@ -13,129 +13,98 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
- return new (P || (P = Promise))(function (resolve, reject) {
19
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
- step((generator = generator.apply(thisArg, _arguments || [])).next());
23
- });
24
- };
25
- var __generator = (this && this.__generator) || function (thisArg, body) {
26
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
27
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28
- function verb(n) { return function (v) { return step([n, v]); }; }
29
- function step(op) {
30
- if (f) throw new TypeError("Generator is already executing.");
31
- while (_) try {
32
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
33
- if (y = 0, t) op = [op[0] & 2, t.value];
34
- switch (op[0]) {
35
- case 0: case 1: t = op; break;
36
- case 4: _.label++; return { value: op[1], done: false };
37
- case 5: _.label++; y = op[1]; op = [0]; continue;
38
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
39
- default:
40
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44
- if (t[2]) _.ops.pop();
45
- _.trys.pop(); continue;
46
- }
47
- op = body.call(thisArg, _);
48
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
- }
51
- };
52
16
  import * as http from 'http';
53
- import { context } from '@opentelemetry/api';
17
+ import { context, diag } from '@opentelemetry/api';
54
18
  import { suppressTracing } from '@opentelemetry/core';
55
- import { Resource, } from '@opentelemetry/resources';
56
19
  import { CLOUDPLATFORMVALUES_AZURE_VM, CLOUDPROVIDERVALUES_AZURE, SEMRESATTRS_CLOUD_PLATFORM, SEMRESATTRS_CLOUD_PROVIDER, SEMRESATTRS_CLOUD_REGION, SEMRESATTRS_HOST_ID, SEMRESATTRS_HOST_NAME, SEMRESATTRS_HOST_TYPE, SEMRESATTRS_OS_VERSION, } from '@opentelemetry/semantic-conventions';
57
20
  import { CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE, AZURE_VM_METADATA_HOST, AZURE_VM_METADATA_PATH, AZURE_VM_SCALE_SET_NAME_ATTRIBUTE, AZURE_VM_SKU_ATTRIBUTE, } from '../types';
58
21
  /**
59
22
  * The AzureVmDetector can be used to detect if a process is running in an Azure VM.
60
23
  * @returns a {@link Resource} populated with data about the environment or an empty Resource if detection fails.
61
24
  */
62
- var AzureVmResourceDetector = /** @class */ (function () {
63
- function AzureVmResourceDetector() {
64
- }
65
- AzureVmResourceDetector.prototype.detect = function () {
66
- var _this = this;
67
- var attributes = context.with(suppressTracing(context.active()), function () {
68
- return _this.getAzureVmMetadata();
25
+ class AzureVmResourceDetector {
26
+ detect() {
27
+ const dataPromise = context.with(suppressTracing(context.active()), () => this.getAzureVmMetadata());
28
+ const attrNames = [
29
+ AZURE_VM_SCALE_SET_NAME_ATTRIBUTE,
30
+ AZURE_VM_SKU_ATTRIBUTE,
31
+ SEMRESATTRS_CLOUD_PLATFORM,
32
+ SEMRESATTRS_CLOUD_PROVIDER,
33
+ SEMRESATTRS_CLOUD_REGION,
34
+ CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE,
35
+ SEMRESATTRS_HOST_ID,
36
+ SEMRESATTRS_HOST_NAME,
37
+ SEMRESATTRS_HOST_TYPE,
38
+ SEMRESATTRS_OS_VERSION,
39
+ ];
40
+ const attributes = {};
41
+ attrNames.forEach(name => {
42
+ // Each resource attribute is determined asynchronously in _gatherData().
43
+ attributes[name] = dataPromise.then(data => data[name]);
69
44
  });
70
- return new Resource({}, attributes);
71
- };
72
- AzureVmResourceDetector.prototype.getAzureVmMetadata = function () {
73
- return __awaiter(this, void 0, void 0, function () {
74
- var options, metadata, attributes;
75
- var _a;
76
- return __generator(this, function (_b) {
77
- switch (_b.label) {
78
- case 0:
79
- options = {
80
- host: AZURE_VM_METADATA_HOST,
81
- path: AZURE_VM_METADATA_PATH,
82
- method: 'GET',
83
- timeout: 5000,
84
- headers: {
85
- Metadata: 'True',
86
- },
87
- };
88
- return [4 /*yield*/, new Promise(function (resolve, reject) {
89
- var timeoutId = setTimeout(function () {
90
- req.destroy();
91
- reject(new Error('Azure metadata service request timed out.'));
92
- }, 1000);
93
- var req = http.request(options, function (res) {
94
- clearTimeout(timeoutId);
95
- var statusCode = res.statusCode;
96
- res.setEncoding('utf8');
97
- var rawData = '';
98
- res.on('data', function (chunk) { return (rawData += chunk); });
99
- res.on('end', function () {
100
- if (statusCode && statusCode >= 200 && statusCode < 300) {
101
- try {
102
- resolve(JSON.parse(rawData));
103
- }
104
- catch (error) {
105
- reject(error);
106
- }
107
- }
108
- else {
109
- reject(new Error('Failed to load page, status code: ' + statusCode));
110
- }
111
- });
112
- });
113
- req.on('error', function (err) {
114
- clearTimeout(timeoutId);
115
- reject(err);
116
- });
117
- req.end();
118
- })];
119
- case 1:
120
- metadata = _b.sent();
121
- attributes = (_a = {},
122
- _a[AZURE_VM_SCALE_SET_NAME_ATTRIBUTE] = metadata['vmScaleSetName'],
123
- _a[AZURE_VM_SKU_ATTRIBUTE] = metadata['sku'],
124
- _a[SEMRESATTRS_CLOUD_PLATFORM] = CLOUDPLATFORMVALUES_AZURE_VM,
125
- _a[SEMRESATTRS_CLOUD_PROVIDER] = CLOUDPROVIDERVALUES_AZURE,
126
- _a[SEMRESATTRS_CLOUD_REGION] = metadata['location'],
127
- _a[CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE] = metadata['resourceId'],
128
- _a[SEMRESATTRS_HOST_ID] = metadata['vmId'],
129
- _a[SEMRESATTRS_HOST_NAME] = metadata['name'],
130
- _a[SEMRESATTRS_HOST_TYPE] = metadata['vmSize'],
131
- _a[SEMRESATTRS_OS_VERSION] = metadata['version'],
132
- _a);
133
- return [2 /*return*/, attributes];
134
- }
45
+ return { attributes };
46
+ }
47
+ async getAzureVmMetadata() {
48
+ try {
49
+ const options = {
50
+ host: AZURE_VM_METADATA_HOST,
51
+ path: AZURE_VM_METADATA_PATH,
52
+ method: 'GET',
53
+ timeout: 5000,
54
+ headers: {
55
+ Metadata: 'True',
56
+ },
57
+ };
58
+ const metadata = await new Promise((resolve, reject) => {
59
+ const timeoutId = setTimeout(() => {
60
+ req.destroy();
61
+ reject(new Error('Azure metadata service request timed out.'));
62
+ }, 1000);
63
+ const req = http.request(options, res => {
64
+ clearTimeout(timeoutId);
65
+ const { statusCode } = res;
66
+ res.setEncoding('utf8');
67
+ let rawData = '';
68
+ res.on('data', chunk => (rawData += chunk));
69
+ res.on('end', () => {
70
+ if (statusCode && statusCode >= 200 && statusCode < 300) {
71
+ try {
72
+ resolve(JSON.parse(rawData));
73
+ }
74
+ catch (error) {
75
+ reject(error);
76
+ }
77
+ }
78
+ else {
79
+ reject(new Error('Failed to load page, status code: ' + statusCode));
80
+ }
81
+ });
82
+ });
83
+ req.on('error', err => {
84
+ clearTimeout(timeoutId);
85
+ reject(err);
86
+ });
87
+ req.end();
135
88
  });
136
- });
137
- };
138
- return AzureVmResourceDetector;
139
- }());
140
- export var azureVmDetector = new AzureVmResourceDetector();
89
+ const attributes = {
90
+ [AZURE_VM_SCALE_SET_NAME_ATTRIBUTE]: metadata['vmScaleSetName'],
91
+ [AZURE_VM_SKU_ATTRIBUTE]: metadata['sku'],
92
+ [SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AZURE_VM,
93
+ [SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AZURE,
94
+ [SEMRESATTRS_CLOUD_REGION]: metadata['location'],
95
+ [CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE]: metadata['resourceId'],
96
+ [SEMRESATTRS_HOST_ID]: metadata['vmId'],
97
+ [SEMRESATTRS_HOST_NAME]: metadata['name'],
98
+ [SEMRESATTRS_HOST_TYPE]: metadata['vmSize'],
99
+ [SEMRESATTRS_OS_VERSION]: metadata['version'],
100
+ };
101
+ return attributes;
102
+ }
103
+ catch (err) {
104
+ diag.debug('AzureVmResourceDetector: not running in an Azure VM:', err.message);
105
+ return {};
106
+ }
107
+ }
108
+ }
109
+ export const azureVmDetector = new AzureVmResourceDetector();
141
110
  //# sourceMappingURL=AzureVmDetector.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AzureVmDetector.js","sourceRoot":"","sources":["../../../src/detectors/AzureVmDetector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;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,GAAC,0BAA0B,IAAG,yBAAyB;4BACvD,GAAC,wBAAwB,IAAG,QAAQ,CAAC,UAAU,CAAC;4BAChD,GAAC,oCAAoC,IAAG,QAAQ,CAAC,YAAY,CAAC;4BAC9D,GAAC,mBAAmB,IAAG,QAAQ,CAAC,MAAM,CAAC;4BACvC,GAAC,qBAAqB,IAAG,QAAQ,CAAC,MAAM,CAAC;4BACzC,GAAC,qBAAqB,IAAG,QAAQ,CAAC,QAAQ,CAAC;4BAC3C,GAAC,sBAAsB,IAAG,QAAQ,CAAC,SAAS,CAAC;+BAC9C,CAAC;wBACF,sBAAO,UAAU,EAAC;;;;KACnB;IACH,8BAAC;AAAD,CAAC,AAjED,IAiEC;AAED,MAAM,CAAC,IAAM,eAAe,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 * as http from 'http';\n\nimport { context } from '@opentelemetry/api';\nimport { suppressTracing } from '@opentelemetry/core';\nimport {\n DetectorSync,\n IResource,\n Resource,\n ResourceAttributes,\n} from '@opentelemetry/resources';\nimport {\n CLOUDPLATFORMVALUES_AZURE_VM,\n CLOUDPROVIDERVALUES_AZURE,\n SEMRESATTRS_CLOUD_PLATFORM,\n SEMRESATTRS_CLOUD_PROVIDER,\n SEMRESATTRS_CLOUD_REGION,\n SEMRESATTRS_HOST_ID,\n SEMRESATTRS_HOST_NAME,\n SEMRESATTRS_HOST_TYPE,\n SEMRESATTRS_OS_VERSION,\n} from '@opentelemetry/semantic-conventions';\nimport {\n CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE,\n AZURE_VM_METADATA_HOST,\n AZURE_VM_METADATA_PATH,\n AZURE_VM_SCALE_SET_NAME_ATTRIBUTE,\n AZURE_VM_SKU_ATTRIBUTE,\n AzureVmMetadata,\n} from '../types';\n\n/**\n * The AzureVmDetector can be used to detect if a process is running in an Azure VM.\n * @returns a {@link Resource} populated with data about the environment or an empty Resource if detection fails.\n */\nclass AzureVmResourceDetector implements DetectorSync {\n detect(): IResource {\n const attributes = context.with(suppressTracing(context.active()), () =>\n this.getAzureVmMetadata()\n );\n return new Resource({}, attributes);\n }\n\n async getAzureVmMetadata(): Promise<ResourceAttributes> {\n const options = {\n host: AZURE_VM_METADATA_HOST,\n path: AZURE_VM_METADATA_PATH,\n method: 'GET',\n timeout: 5000,\n headers: {\n Metadata: 'True',\n },\n };\n const metadata: AzureVmMetadata = await new Promise((resolve, reject) => {\n const timeoutId = setTimeout(() => {\n req.destroy();\n reject(new Error('Azure metadata service request timed out.'));\n }, 1000);\n\n const req = http.request(options, res => {\n clearTimeout(timeoutId);\n const { statusCode } = res;\n res.setEncoding('utf8');\n let rawData = '';\n res.on('data', chunk => (rawData += chunk));\n res.on('end', () => {\n if (statusCode && statusCode >= 200 && statusCode < 300) {\n try {\n resolve(JSON.parse(rawData));\n } catch (error) {\n reject(error);\n }\n } else {\n reject(\n new Error('Failed to load page, status code: ' + statusCode)\n );\n }\n });\n });\n req.on('error', err => {\n clearTimeout(timeoutId);\n reject(err);\n });\n req.end();\n });\n\n const attributes = {\n [AZURE_VM_SCALE_SET_NAME_ATTRIBUTE]: metadata['vmScaleSetName'],\n [AZURE_VM_SKU_ATTRIBUTE]: metadata['sku'],\n [SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AZURE_VM,\n [SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AZURE,\n [SEMRESATTRS_CLOUD_REGION]: metadata['location'],\n [CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE]: metadata['resourceId'],\n [SEMRESATTRS_HOST_ID]: metadata['vmId'],\n [SEMRESATTRS_HOST_NAME]: metadata['name'],\n [SEMRESATTRS_HOST_TYPE]: metadata['vmSize'],\n [SEMRESATTRS_OS_VERSION]: metadata['version'],\n };\n return attributes;\n }\n}\n\nexport const azureVmDetector = new AzureVmResourceDetector();\n"]}
1
+ {"version":3,"file":"AzureVmDetector.js","sourceRoot":"","sources":["../../../src/detectors/AzureVmDetector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAMtD,OAAO,EACL,4BAA4B,EAC5B,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,EAC1B,wBAAwB,EACxB,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,oCAAoC,EACpC,sBAAsB,EACtB,sBAAsB,EACtB,iCAAiC,EACjC,sBAAsB,GAEvB,MAAM,UAAU,CAAC;AAElB;;;GAGG;AACH,MAAM,uBAAuB;IAC3B,MAAM;QACJ,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,CACvE,IAAI,CAAC,kBAAkB,EAAE,CAC1B,CAAC;QAEF,MAAM,SAAS,GAAG;YAChB,iCAAiC;YACjC,sBAAsB;YACtB,0BAA0B;YAC1B,0BAA0B;YAC1B,wBAAwB;YACxB,oCAAoC;YACpC,mBAAmB;YACnB,qBAAqB;YACrB,qBAAqB;YACrB,sBAAsB;SACvB,CAAC;QAEF,MAAM,UAAU,GAAG,EAAgC,CAAC;QACpD,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,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AAE,CAAC;SACX;IACH,CAAC;CACF;AAED,MAAM,CAAC,MAAM,eAAe,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 * as http from 'http';\n\nimport { context, diag } from '@opentelemetry/api';\nimport { suppressTracing } from '@opentelemetry/core';\nimport {\n ResourceDetector,\n DetectedResource,\n DetectedResourceAttributes,\n} from '@opentelemetry/resources';\nimport {\n CLOUDPLATFORMVALUES_AZURE_VM,\n CLOUDPROVIDERVALUES_AZURE,\n SEMRESATTRS_CLOUD_PLATFORM,\n SEMRESATTRS_CLOUD_PROVIDER,\n SEMRESATTRS_CLOUD_REGION,\n SEMRESATTRS_HOST_ID,\n SEMRESATTRS_HOST_NAME,\n SEMRESATTRS_HOST_TYPE,\n SEMRESATTRS_OS_VERSION,\n} from '@opentelemetry/semantic-conventions';\nimport {\n CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE,\n AZURE_VM_METADATA_HOST,\n AZURE_VM_METADATA_PATH,\n AZURE_VM_SCALE_SET_NAME_ATTRIBUTE,\n AZURE_VM_SKU_ATTRIBUTE,\n AzureVmMetadata,\n} from '../types';\n\n/**\n * The AzureVmDetector can be used to detect if a process is running in an Azure VM.\n * @returns a {@link Resource} populated with data about the environment or an empty Resource if detection fails.\n */\nclass AzureVmResourceDetector implements ResourceDetector {\n detect(): DetectedResource {\n const dataPromise = context.with(suppressTracing(context.active()), () =>\n this.getAzureVmMetadata()\n );\n\n const attrNames = [\n AZURE_VM_SCALE_SET_NAME_ATTRIBUTE,\n AZURE_VM_SKU_ATTRIBUTE,\n SEMRESATTRS_CLOUD_PLATFORM,\n SEMRESATTRS_CLOUD_PROVIDER,\n SEMRESATTRS_CLOUD_REGION,\n CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE,\n SEMRESATTRS_HOST_ID,\n SEMRESATTRS_HOST_NAME,\n SEMRESATTRS_HOST_TYPE,\n SEMRESATTRS_OS_VERSION,\n ];\n\n const attributes = {} as DetectedResourceAttributes;\n attrNames.forEach(name => {\n // Each resource attribute is determined asynchronously in _gatherData().\n attributes[name] = dataPromise.then(data => data[name]);\n });\n\n return { attributes };\n }\n\n async getAzureVmMetadata(): Promise<DetectedResourceAttributes> {\n try {\n const options = {\n host: AZURE_VM_METADATA_HOST,\n path: AZURE_VM_METADATA_PATH,\n method: 'GET',\n timeout: 5000,\n headers: {\n Metadata: 'True',\n },\n };\n const metadata: AzureVmMetadata = await new Promise((resolve, reject) => {\n const timeoutId = setTimeout(() => {\n req.destroy();\n reject(new Error('Azure metadata service request timed out.'));\n }, 1000);\n\n const req = http.request(options, res => {\n clearTimeout(timeoutId);\n const { statusCode } = res;\n res.setEncoding('utf8');\n let rawData = '';\n res.on('data', chunk => (rawData += chunk));\n res.on('end', () => {\n if (statusCode && statusCode >= 200 && statusCode < 300) {\n try {\n resolve(JSON.parse(rawData));\n } catch (error) {\n reject(error);\n }\n } else {\n reject(\n new Error('Failed to load page, status code: ' + statusCode)\n );\n }\n });\n });\n req.on('error', err => {\n clearTimeout(timeoutId);\n reject(err);\n });\n req.end();\n });\n\n const attributes = {\n [AZURE_VM_SCALE_SET_NAME_ATTRIBUTE]: metadata['vmScaleSetName'],\n [AZURE_VM_SKU_ATTRIBUTE]: metadata['sku'],\n [SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AZURE_VM,\n [SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AZURE,\n [SEMRESATTRS_CLOUD_REGION]: metadata['location'],\n [CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE]: metadata['resourceId'],\n [SEMRESATTRS_HOST_ID]: metadata['vmId'],\n [SEMRESATTRS_HOST_NAME]: metadata['name'],\n [SEMRESATTRS_HOST_TYPE]: metadata['vmSize'],\n [SEMRESATTRS_OS_VERSION]: metadata['version'],\n };\n return attributes;\n } catch (err: any) {\n diag.debug(\n 'AzureVmResourceDetector: not running in an Azure VM:',\n err.message\n );\n return {};\n }\n }\n}\n\nexport const azureVmDetector = new AzureVmResourceDetector();\n"]}
@@ -13,21 +13,21 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export var AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE = 'azure.app.service.stamp';
17
- export var CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE = 'cloud.resource_id';
18
- export var REGION_NAME = 'REGION_NAME';
19
- export var WEBSITE_HOME_STAMPNAME = 'WEBSITE_HOME_STAMPNAME';
20
- export var WEBSITE_HOSTNAME = 'WEBSITE_HOSTNAME';
21
- export var WEBSITE_INSTANCE_ID = 'WEBSITE_INSTANCE_ID';
22
- export var WEBSITE_OWNER_NAME = 'WEBSITE_OWNER_NAME';
23
- export var WEBSITE_RESOURCE_GROUP = 'WEBSITE_RESOURCE_GROUP';
24
- export var WEBSITE_SITE_NAME = 'WEBSITE_SITE_NAME';
25
- export var WEBSITE_SLOT_NAME = 'WEBSITE_SLOT_NAME';
26
- export var WEBSITE_SKU = 'WEBSITE_SKU';
27
- export var FUNCTIONS_VERSION = 'FUNCTIONS_EXTENSION_VERSION';
28
- export var FUNCTIONS_MEM_LIMIT = 'WEBSITE_MEMORY_LIMIT_MB';
29
- export var AZURE_VM_METADATA_HOST = '169.254.169.254';
30
- export var AZURE_VM_METADATA_PATH = '/metadata/instance/compute?api-version=2021-12-13&format=json';
31
- export var AZURE_VM_SCALE_SET_NAME_ATTRIBUTE = 'azure.vm.scaleset.name';
32
- export var AZURE_VM_SKU_ATTRIBUTE = 'azure.vm.sku';
16
+ export const AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE = 'azure.app.service.stamp';
17
+ export const CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE = 'cloud.resource_id';
18
+ export const REGION_NAME = 'REGION_NAME';
19
+ export const WEBSITE_HOME_STAMPNAME = 'WEBSITE_HOME_STAMPNAME';
20
+ export const WEBSITE_HOSTNAME = 'WEBSITE_HOSTNAME';
21
+ export const WEBSITE_INSTANCE_ID = 'WEBSITE_INSTANCE_ID';
22
+ export const WEBSITE_OWNER_NAME = 'WEBSITE_OWNER_NAME';
23
+ export const WEBSITE_RESOURCE_GROUP = 'WEBSITE_RESOURCE_GROUP';
24
+ export const WEBSITE_SITE_NAME = 'WEBSITE_SITE_NAME';
25
+ export const WEBSITE_SLOT_NAME = 'WEBSITE_SLOT_NAME';
26
+ export const WEBSITE_SKU = 'WEBSITE_SKU';
27
+ export const FUNCTIONS_VERSION = 'FUNCTIONS_EXTENSION_VERSION';
28
+ export const FUNCTIONS_MEM_LIMIT = 'WEBSITE_MEMORY_LIMIT_MB';
29
+ export const AZURE_VM_METADATA_HOST = '169.254.169.254';
30
+ export const AZURE_VM_METADATA_PATH = '/metadata/instance/compute?api-version=2021-12-13&format=json';
31
+ export const AZURE_VM_SCALE_SET_NAME_ATTRIBUTE = 'azure.vm.scaleset.name';
32
+ export const AZURE_VM_SKU_ATTRIBUTE = 'azure.vm.sku';
33
33
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,CAAC,IAAM,0CAA0C,GACrD,yBAAyB,CAAC;AAC5B,MAAM,CAAC,IAAM,oCAAoC,GAAG,mBAAmB,CAAC;AACxE,MAAM,CAAC,IAAM,WAAW,GAAG,aAAa,CAAC;AACzC,MAAM,CAAC,IAAM,sBAAsB,GAAG,wBAAwB,CAAC;AAC/D,MAAM,CAAC,IAAM,gBAAgB,GAAG,kBAAkB,CAAC;AACnD,MAAM,CAAC,IAAM,mBAAmB,GAAG,qBAAqB,CAAC;AACzD,MAAM,CAAC,IAAM,kBAAkB,GAAG,oBAAoB,CAAC;AACvD,MAAM,CAAC,IAAM,sBAAsB,GAAG,wBAAwB,CAAC;AAC/D,MAAM,CAAC,IAAM,iBAAiB,GAAG,mBAAmB,CAAC;AACrD,MAAM,CAAC,IAAM,iBAAiB,GAAG,mBAAmB,CAAC;AACrD,MAAM,CAAC,IAAM,WAAW,GAAG,aAAa,CAAC;AAEzC,MAAM,CAAC,IAAM,iBAAiB,GAAG,6BAA6B,CAAC;AAC/D,MAAM,CAAC,IAAM,mBAAmB,GAAG,yBAAyB,CAAC;AAE7D,MAAM,CAAC,IAAM,sBAAsB,GAAG,iBAAiB,CAAC;AACxD,MAAM,CAAC,IAAM,sBAAsB,GACjC,+DAA+D,CAAC;AAClE,MAAM,CAAC,IAAM,iCAAiC,GAAG,wBAAwB,CAAC;AAC1E,MAAM,CAAC,IAAM,sBAAsB,GAAG,cAAc,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\nexport const AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE =\n 'azure.app.service.stamp';\nexport const CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE = 'cloud.resource_id';\nexport const REGION_NAME = 'REGION_NAME';\nexport const WEBSITE_HOME_STAMPNAME = 'WEBSITE_HOME_STAMPNAME';\nexport const WEBSITE_HOSTNAME = 'WEBSITE_HOSTNAME';\nexport const WEBSITE_INSTANCE_ID = 'WEBSITE_INSTANCE_ID';\nexport const WEBSITE_OWNER_NAME = 'WEBSITE_OWNER_NAME';\nexport const WEBSITE_RESOURCE_GROUP = 'WEBSITE_RESOURCE_GROUP';\nexport const WEBSITE_SITE_NAME = 'WEBSITE_SITE_NAME';\nexport const WEBSITE_SLOT_NAME = 'WEBSITE_SLOT_NAME';\nexport const WEBSITE_SKU = 'WEBSITE_SKU';\n\nexport const FUNCTIONS_VERSION = 'FUNCTIONS_EXTENSION_VERSION';\nexport const FUNCTIONS_MEM_LIMIT = 'WEBSITE_MEMORY_LIMIT_MB';\n\nexport const AZURE_VM_METADATA_HOST = '169.254.169.254';\nexport const AZURE_VM_METADATA_PATH =\n '/metadata/instance/compute?api-version=2021-12-13&format=json';\nexport const AZURE_VM_SCALE_SET_NAME_ATTRIBUTE = 'azure.vm.scaleset.name';\nexport const AZURE_VM_SKU_ATTRIBUTE = 'azure.vm.sku';\n\nexport interface AzureVmMetadata {\n azEnvironment?: string;\n additionalCapabilities?: {\n hibernationEnabled?: string;\n };\n hostGroup?: {\n id?: string;\n };\n host?: {\n id?: string;\n };\n extendedLocation?: {\n type?: string;\n name?: string;\n };\n evictionPolicy?: string;\n isHostCompatibilityLayerVm?: string;\n licenseType?: string;\n location: string;\n name: string;\n offer?: string;\n osProfile?: {\n adminUsername?: string;\n computerName?: string;\n disablePasswordAuthentication?: string;\n };\n osType?: string;\n placementGroupId?: string;\n plan?: {\n name?: string;\n product?: string;\n publisher?: string;\n };\n platformFaultDomain?: string;\n platformSubFaultDomain?: string;\n platformUpdateDomain?: string;\n priority?: string;\n provider?: string;\n publicKeys?: [\n {\n keyData?: string;\n path?: string;\n },\n {\n keyData?: string;\n path?: string;\n }\n ];\n publisher?: string;\n resourceGroupName?: string;\n resourceId: string;\n securityProfile?: {\n secureBootEnabled?: string;\n virtualTpmEnabled?: string;\n encryptionAtHost?: string;\n securityType?: string;\n };\n sku: string;\n storageProfile?: {\n dataDisks?: [\n {\n bytesPerSecondThrottle?: string;\n caching?: string;\n createOption?: string;\n diskCapacityBytes?: string;\n diskSizeGB?: string;\n image?: {\n uri?: string;\n };\n isSharedDisk?: string;\n isUltraDisk?: string;\n lun?: string;\n managedDisk?: {\n id?: string;\n storageAccountType?: string;\n };\n name: string;\n opsPerSecondThrottle?: string;\n vhd?: {\n uri?: string;\n };\n writeAcceleratorEnabled?: string;\n }\n ];\n imageReference?: {\n id?: string;\n offer?: string;\n publisher?: string;\n sku?: string;\n version?: string;\n };\n osDisk?: {\n caching?: string;\n createOption?: string;\n diskSizeGB?: string;\n diffDiskSettings?: {\n option?: string;\n };\n encryptionSettings?: {\n enabled?: string;\n diskEncryptionKey?: {\n sourceVault?: {\n id?: string;\n };\n secretUrl?: string;\n };\n keyEncryptionKey?: {\n sourceVault?: {\n id?: string;\n };\n keyUrl?: string;\n };\n };\n image?: {\n uri?: string;\n };\n managedDisk?: {\n id?: string;\n storageAccountType?: string;\n };\n name?: string;\n osType?: string;\n vhd?: {\n uri?: string;\n };\n writeAcceleratorEnabled?: string;\n };\n resourceDisk?: {\n size?: string;\n };\n };\n subscriptionId?: string;\n tags?: string;\n tagsList?: object[];\n customData?: string;\n userData?: string;\n version: string;\n virtualMachineScaleSet?: {\n id?: string;\n };\n vmId: string;\n vmScaleSetName: string;\n vmSize: string;\n zone?: string;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,CAAC,MAAM,0CAA0C,GACrD,yBAAyB,CAAC;AAC5B,MAAM,CAAC,MAAM,oCAAoC,GAAG,mBAAmB,CAAC;AACxE,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAC;AACzC,MAAM,CAAC,MAAM,sBAAsB,GAAG,wBAAwB,CAAC;AAC/D,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AACnD,MAAM,CAAC,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AACzD,MAAM,CAAC,MAAM,kBAAkB,GAAG,oBAAoB,CAAC;AACvD,MAAM,CAAC,MAAM,sBAAsB,GAAG,wBAAwB,CAAC;AAC/D,MAAM,CAAC,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AACrD,MAAM,CAAC,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AACrD,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAC;AAEzC,MAAM,CAAC,MAAM,iBAAiB,GAAG,6BAA6B,CAAC;AAC/D,MAAM,CAAC,MAAM,mBAAmB,GAAG,yBAAyB,CAAC;AAE7D,MAAM,CAAC,MAAM,sBAAsB,GAAG,iBAAiB,CAAC;AACxD,MAAM,CAAC,MAAM,sBAAsB,GACjC,+DAA+D,CAAC;AAClE,MAAM,CAAC,MAAM,iCAAiC,GAAG,wBAAwB,CAAC;AAC1E,MAAM,CAAC,MAAM,sBAAsB,GAAG,cAAc,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\nexport const AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE =\n 'azure.app.service.stamp';\nexport const CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE = 'cloud.resource_id';\nexport const REGION_NAME = 'REGION_NAME';\nexport const WEBSITE_HOME_STAMPNAME = 'WEBSITE_HOME_STAMPNAME';\nexport const WEBSITE_HOSTNAME = 'WEBSITE_HOSTNAME';\nexport const WEBSITE_INSTANCE_ID = 'WEBSITE_INSTANCE_ID';\nexport const WEBSITE_OWNER_NAME = 'WEBSITE_OWNER_NAME';\nexport const WEBSITE_RESOURCE_GROUP = 'WEBSITE_RESOURCE_GROUP';\nexport const WEBSITE_SITE_NAME = 'WEBSITE_SITE_NAME';\nexport const WEBSITE_SLOT_NAME = 'WEBSITE_SLOT_NAME';\nexport const WEBSITE_SKU = 'WEBSITE_SKU';\n\nexport const FUNCTIONS_VERSION = 'FUNCTIONS_EXTENSION_VERSION';\nexport const FUNCTIONS_MEM_LIMIT = 'WEBSITE_MEMORY_LIMIT_MB';\n\nexport const AZURE_VM_METADATA_HOST = '169.254.169.254';\nexport const AZURE_VM_METADATA_PATH =\n '/metadata/instance/compute?api-version=2021-12-13&format=json';\nexport const AZURE_VM_SCALE_SET_NAME_ATTRIBUTE = 'azure.vm.scaleset.name';\nexport const AZURE_VM_SKU_ATTRIBUTE = 'azure.vm.sku';\n\nexport interface AzureVmMetadata {\n azEnvironment?: string;\n additionalCapabilities?: {\n hibernationEnabled?: string;\n };\n hostGroup?: {\n id?: string;\n };\n host?: {\n id?: string;\n };\n extendedLocation?: {\n type?: string;\n name?: string;\n };\n evictionPolicy?: string;\n isHostCompatibilityLayerVm?: string;\n licenseType?: string;\n location: string;\n name: string;\n offer?: string;\n osProfile?: {\n adminUsername?: string;\n computerName?: string;\n disablePasswordAuthentication?: string;\n };\n osType?: string;\n placementGroupId?: string;\n plan?: {\n name?: string;\n product?: string;\n publisher?: string;\n };\n platformFaultDomain?: string;\n platformSubFaultDomain?: string;\n platformUpdateDomain?: string;\n priority?: string;\n provider?: string;\n publicKeys?: [\n {\n keyData?: string;\n path?: string;\n },\n {\n keyData?: string;\n path?: string;\n }\n ];\n publisher?: string;\n resourceGroupName?: string;\n resourceId: string;\n securityProfile?: {\n secureBootEnabled?: string;\n virtualTpmEnabled?: string;\n encryptionAtHost?: string;\n securityType?: string;\n };\n sku: string;\n storageProfile?: {\n dataDisks?: [\n {\n bytesPerSecondThrottle?: string;\n caching?: string;\n createOption?: string;\n diskCapacityBytes?: string;\n diskSizeGB?: string;\n image?: {\n uri?: string;\n };\n isSharedDisk?: string;\n isUltraDisk?: string;\n lun?: string;\n managedDisk?: {\n id?: string;\n storageAccountType?: string;\n };\n name: string;\n opsPerSecondThrottle?: string;\n vhd?: {\n uri?: string;\n };\n writeAcceleratorEnabled?: string;\n }\n ];\n imageReference?: {\n id?: string;\n offer?: string;\n publisher?: string;\n sku?: string;\n version?: string;\n };\n osDisk?: {\n caching?: string;\n createOption?: string;\n diskSizeGB?: string;\n diffDiskSettings?: {\n option?: string;\n };\n encryptionSettings?: {\n enabled?: string;\n diskEncryptionKey?: {\n sourceVault?: {\n id?: string;\n };\n secretUrl?: string;\n };\n keyEncryptionKey?: {\n sourceVault?: {\n id?: string;\n };\n keyUrl?: string;\n };\n };\n image?: {\n uri?: string;\n };\n managedDisk?: {\n id?: string;\n storageAccountType?: string;\n };\n name?: string;\n osType?: string;\n vhd?: {\n uri?: string;\n };\n writeAcceleratorEnabled?: string;\n };\n resourceDisk?: {\n size?: string;\n };\n };\n subscriptionId?: string;\n tags?: string;\n tagsList?: object[];\n customData?: string;\n userData?: string;\n version: string;\n virtualMachineScaleSet?: {\n id?: string;\n };\n vmId: string;\n vmScaleSetName: string;\n vmSize: string;\n zone?: string;\n}\n"]}
@@ -15,16 +15,16 @@
15
15
  */
16
16
  import { FUNCTIONS_VERSION, WEBSITE_OWNER_NAME, WEBSITE_RESOURCE_GROUP, WEBSITE_SKU, } from './types';
17
17
  export function getAzureResourceUri(websiteSiteName) {
18
- var websiteResourceGroup = process.env[WEBSITE_RESOURCE_GROUP];
19
- var websiteOwnerName = process.env[WEBSITE_OWNER_NAME];
20
- var subscriptionId = websiteOwnerName;
18
+ const websiteResourceGroup = process.env[WEBSITE_RESOURCE_GROUP];
19
+ const websiteOwnerName = process.env[WEBSITE_OWNER_NAME];
20
+ let subscriptionId = websiteOwnerName;
21
21
  if (websiteOwnerName && websiteOwnerName.indexOf('+') !== -1) {
22
22
  subscriptionId = websiteOwnerName.split('+')[0];
23
23
  }
24
24
  if (!subscriptionId && !websiteOwnerName) {
25
25
  return undefined;
26
26
  }
27
- return "/subscriptions/" + subscriptionId + "/resourceGroups/" + websiteResourceGroup + "/providers/Microsoft.Web/sites/" + websiteSiteName;
27
+ return `/subscriptions/${subscriptionId}/resourceGroups/${websiteResourceGroup}/providers/Microsoft.Web/sites/${websiteSiteName}`;
28
28
  }
29
29
  export function isAzureFunction() {
30
30
  return !!(process.env[FUNCTIONS_VERSION] ||
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,WAAW,GACZ,MAAM,SAAS,CAAC;AAEjB,MAAM,UAAU,mBAAmB,CACjC,eAAuB;IAEvB,IAAM,oBAAoB,GAAG,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;IACjE,IAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAEzD,IAAI,cAAc,GAAG,gBAAgB,CAAC;IACtC,IAAI,gBAAgB,IAAI,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE;QAC5D,cAAc,GAAG,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;KACjD;IAED,IAAI,CAAC,cAAc,IAAI,CAAC,gBAAgB,EAAE;QACxC,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,oBAAkB,cAAc,wBAAmB,oBAAoB,uCAAkC,eAAiB,CAAC;AACpI,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,OAAO,CAAC,CAAC,CACP,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;QAC9B,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,KAAK,iBAAiB,CAC/C,CAAC;AACJ,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 {\n FUNCTIONS_VERSION,\n WEBSITE_OWNER_NAME,\n WEBSITE_RESOURCE_GROUP,\n WEBSITE_SKU,\n} from './types';\n\nexport function getAzureResourceUri(\n websiteSiteName: string\n): 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\nexport function isAzureFunction(): boolean {\n return !!(\n process.env[FUNCTIONS_VERSION] ||\n process.env[WEBSITE_SKU] === 'FlexConsumption'\n );\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,WAAW,GACZ,MAAM,SAAS,CAAC;AAEjB,MAAM,UAAU,mBAAmB,CACjC,eAAuB;IAEvB,MAAM,oBAAoB,GAAG,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;IACjE,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAEzD,IAAI,cAAc,GAAG,gBAAgB,CAAC;IACtC,IAAI,gBAAgB,IAAI,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE;QAC5D,cAAc,GAAG,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;KACjD;IAED,IAAI,CAAC,cAAc,IAAI,CAAC,gBAAgB,EAAE;QACxC,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,kBAAkB,cAAc,mBAAmB,oBAAoB,kCAAkC,eAAe,EAAE,CAAC;AACpI,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,OAAO,CAAC,CAAC,CACP,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;QAC9B,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,KAAK,iBAAiB,CAC/C,CAAC;AACJ,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 {\n FUNCTIONS_VERSION,\n WEBSITE_OWNER_NAME,\n WEBSITE_RESOURCE_GROUP,\n WEBSITE_SKU,\n} from './types';\n\nexport function getAzureResourceUri(\n websiteSiteName: string\n): 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\nexport function isAzureFunction(): boolean {\n return !!(\n process.env[FUNCTIONS_VERSION] ||\n process.env[WEBSITE_SKU] === 'FlexConsumption'\n );\n}\n"]}
@@ -1,10 +1,10 @@
1
- import { DetectorSync, IResource } from '@opentelemetry/resources';
1
+ import { ResourceDetector, DetectedResource } from '@opentelemetry/resources';
2
2
  /**
3
3
  * The AzureAppServiceDetector can be used to detect if a process is running in an Azure App Service
4
4
  * @returns a {@link Resource} populated with data about the environment or an empty Resource if detection fails.
5
5
  */
6
- declare class AzureAppServiceDetector implements DetectorSync {
7
- detect(): IResource;
6
+ declare class AzureAppServiceDetector implements ResourceDetector {
7
+ detect(): DetectedResource;
8
8
  }
9
9
  export declare const azureAppServiceDetector: AzureAppServiceDetector;
10
10
  export {};
@@ -16,7 +16,6 @@
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.azureAppServiceDetector = void 0;
19
- const resources_1 = require("@opentelemetry/resources");
20
19
  const types_1 = require("../types");
21
20
  const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
22
21
  const utils_1 = require("../utils");
@@ -36,21 +35,33 @@ class AzureAppServiceDetector {
36
35
  let attributes = {};
37
36
  const websiteSiteName = process.env[types_1.WEBSITE_SITE_NAME];
38
37
  if (websiteSiteName && !(0, utils_1.isAzureFunction)()) {
39
- attributes = Object.assign(Object.assign({}, attributes), { [semantic_conventions_1.SEMRESATTRS_SERVICE_NAME]: websiteSiteName });
40
- attributes = Object.assign(Object.assign({}, attributes), { [semantic_conventions_1.SEMRESATTRS_CLOUD_PROVIDER]: semantic_conventions_1.CLOUDPROVIDERVALUES_AZURE });
41
- attributes = Object.assign(Object.assign({}, attributes), { [semantic_conventions_1.SEMRESATTRS_CLOUD_PLATFORM]: semantic_conventions_1.CLOUDPLATFORMVALUES_AZURE_APP_SERVICE });
38
+ attributes = {
39
+ ...attributes,
40
+ [semantic_conventions_1.SEMRESATTRS_SERVICE_NAME]: websiteSiteName,
41
+ };
42
+ attributes = {
43
+ ...attributes,
44
+ [semantic_conventions_1.SEMRESATTRS_CLOUD_PROVIDER]: semantic_conventions_1.CLOUDPROVIDERVALUES_AZURE,
45
+ };
46
+ attributes = {
47
+ ...attributes,
48
+ [semantic_conventions_1.SEMRESATTRS_CLOUD_PLATFORM]: semantic_conventions_1.CLOUDPLATFORMVALUES_AZURE_APP_SERVICE,
49
+ };
42
50
  const azureResourceUri = (0, utils_1.getAzureResourceUri)(websiteSiteName);
43
51
  if (azureResourceUri) {
44
- attributes = Object.assign(Object.assign({}, attributes), { [types_1.CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE]: azureResourceUri });
52
+ attributes = {
53
+ ...attributes,
54
+ ...{ [types_1.CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE]: azureResourceUri },
55
+ };
45
56
  }
46
57
  for (const [key, value] of Object.entries(APP_SERVICE_ATTRIBUTE_ENV_VARS)) {
47
58
  const envVar = process.env[value];
48
59
  if (envVar) {
49
- attributes = Object.assign(Object.assign({}, attributes), { [key]: envVar });
60
+ attributes = { ...attributes, ...{ [key]: envVar } };
50
61
  }
51
62
  }
52
63
  }
53
- return new resources_1.Resource(attributes);
64
+ return { attributes };
54
65
  }
55
66
  }
56
67
  exports.azureAppServiceDetector = new AzureAppServiceDetector();
@@ -1 +1 @@
1
- {"version":3,"file":"AzureAppServiceDetector.js","sourceRoot":"","sources":["../../../src/detectors/AzureAppServiceDetector.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,wDAA6E;AAC7E,oCASkB;AAClB,8EAU6C;AAC7C,oCAAgE;AAEhE,MAAM,8BAA8B,GAAG;IACrC,CAAC,+CAAwB,CAAC,EAAE,mBAAW;IACvC,CAAC,yDAAkC,CAAC,EAAE,yBAAiB;IACvD,CAAC,0CAAmB,CAAC,EAAE,wBAAgB;IACvC,CAAC,sDAA+B,CAAC,EAAE,2BAAmB;IACtD,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,GAAG,CAAC,yBAAiB,CAAC,CAAC;QACvD,IAAI,eAAe,IAAI,CAAC,IAAA,uBAAe,GAAE,EAAE;YACzC,UAAU,mCACL,UAAU,KACb,CAAC,+CAAwB,CAAC,EAAE,eAAe,GAC5C,CAAC;YACF,UAAU,mCACL,UAAU,KACb,CAAC,iDAA0B,CAAC,EAAE,gDAAyB,GACxD,CAAC;YACF,UAAU,mCACL,UAAU,KACb,CAAC,iDAA0B,CAAC,EAAE,4DAAqC,GACpE,CAAC;YAEF,MAAM,gBAAgB,GAAG,IAAA,2BAAmB,EAAC,eAAe,CAAC,CAAC;YAC9D,IAAI,gBAAgB,EAAE;gBACpB,UAAU,mCACL,UAAU,GACV,EAAE,CAAC,4CAAoC,CAAC,EAAE,gBAAgB,EAAE,CAChE,CAAC;aACH;YAED,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CACvC,8BAA8B,CAC/B,EAAE;gBACD,MAAM,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;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_SITE_NAME,\n WEBSITE_SLOT_NAME,\n CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE,\n} from '../types';\nimport {\n SEMRESATTRS_CLOUD_REGION,\n SEMRESATTRS_DEPLOYMENT_ENVIRONMENT,\n SEMRESATTRS_HOST_ID,\n SEMRESATTRS_SERVICE_INSTANCE_ID,\n SEMRESATTRS_SERVICE_NAME,\n SEMRESATTRS_CLOUD_PROVIDER,\n SEMRESATTRS_CLOUD_PLATFORM,\n CLOUDPROVIDERVALUES_AZURE,\n CLOUDPLATFORMVALUES_AZURE_APP_SERVICE,\n} from '@opentelemetry/semantic-conventions';\nimport { getAzureResourceUri, isAzureFunction } from '../utils';\n\nconst APP_SERVICE_ATTRIBUTE_ENV_VARS = {\n [SEMRESATTRS_CLOUD_REGION]: REGION_NAME,\n [SEMRESATTRS_DEPLOYMENT_ENVIRONMENT]: WEBSITE_SLOT_NAME,\n [SEMRESATTRS_HOST_ID]: WEBSITE_HOSTNAME,\n [SEMRESATTRS_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 && !isAzureFunction()) {\n attributes = {\n ...attributes,\n [SEMRESATTRS_SERVICE_NAME]: websiteSiteName,\n };\n attributes = {\n ...attributes,\n [SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AZURE,\n };\n attributes = {\n ...attributes,\n [SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AZURE_APP_SERVICE,\n };\n\n const azureResourceUri = 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\nexport const azureAppServiceDetector = new AzureAppServiceDetector();\n"]}
1
+ {"version":3,"file":"AzureAppServiceDetector.js","sourceRoot":"","sources":["../../../src/detectors/AzureAppServiceDetector.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAGH,oCASkB;AAClB,8EAU6C;AAC7C,oCAAgE;AAEhE,MAAM,8BAA8B,GAAG;IACrC,CAAC,+CAAwB,CAAC,EAAE,mBAAW;IACvC,CAAC,yDAAkC,CAAC,EAAE,yBAAiB;IACvD,CAAC,0CAAmB,CAAC,EAAE,wBAAgB;IACvC,CAAC,sDAA+B,CAAC,EAAE,2BAAmB;IACtD,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,GAAG,CAAC,yBAAiB,CAAC,CAAC;QACvD,IAAI,eAAe,IAAI,CAAC,IAAA,uBAAe,GAAE,EAAE;YACzC,UAAU,GAAG;gBACX,GAAG,UAAU;gBACb,CAAC,+CAAwB,CAAC,EAAE,eAAe;aAC5C,CAAC;YACF,UAAU,GAAG;gBACX,GAAG,UAAU;gBACb,CAAC,iDAA0B,CAAC,EAAE,gDAAyB;aACxD,CAAC;YACF,UAAU,GAAG;gBACX,GAAG,UAAU;gBACb,CAAC,iDAA0B,CAAC,EAAE,4DAAqC;aACpE,CAAC;YAEF,MAAM,gBAAgB,GAAG,IAAA,2BAAmB,EAAC,eAAe,CAAC,CAAC;YAC9D,IAAI,gBAAgB,EAAE;gBACpB,UAAU,GAAG;oBACX,GAAG,UAAU;oBACb,GAAG,EAAE,CAAC,4CAAoC,CAAC,EAAE,gBAAgB,EAAE;iBAChE,CAAC;aACH;YAED,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CACvC,8BAA8B,CAC/B,EAAE;gBACD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBAClC,IAAI,MAAM,EAAE;oBACV,UAAU,GAAG,EAAE,GAAG,UAAU,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;iBACtD;aACF;SACF;QACD,OAAO,EAAE,UAAU,EAAE,CAAC;IACxB,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 { ResourceDetector, DetectedResource } 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_SITE_NAME,\n WEBSITE_SLOT_NAME,\n CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE,\n} from '../types';\nimport {\n SEMRESATTRS_CLOUD_REGION,\n SEMRESATTRS_DEPLOYMENT_ENVIRONMENT,\n SEMRESATTRS_HOST_ID,\n SEMRESATTRS_SERVICE_INSTANCE_ID,\n SEMRESATTRS_SERVICE_NAME,\n SEMRESATTRS_CLOUD_PROVIDER,\n SEMRESATTRS_CLOUD_PLATFORM,\n CLOUDPROVIDERVALUES_AZURE,\n CLOUDPLATFORMVALUES_AZURE_APP_SERVICE,\n} from '@opentelemetry/semantic-conventions';\nimport { getAzureResourceUri, isAzureFunction } from '../utils';\n\nconst APP_SERVICE_ATTRIBUTE_ENV_VARS = {\n [SEMRESATTRS_CLOUD_REGION]: REGION_NAME,\n [SEMRESATTRS_DEPLOYMENT_ENVIRONMENT]: WEBSITE_SLOT_NAME,\n [SEMRESATTRS_HOST_ID]: WEBSITE_HOSTNAME,\n [SEMRESATTRS_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 ResourceDetector {\n detect(): DetectedResource {\n let attributes = {};\n const websiteSiteName = process.env[WEBSITE_SITE_NAME];\n if (websiteSiteName && !isAzureFunction()) {\n attributes = {\n ...attributes,\n [SEMRESATTRS_SERVICE_NAME]: websiteSiteName,\n };\n attributes = {\n ...attributes,\n [SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AZURE,\n };\n attributes = {\n ...attributes,\n [SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AZURE_APP_SERVICE,\n };\n\n const azureResourceUri = 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 { attributes };\n }\n}\n\nexport const azureAppServiceDetector = new AzureAppServiceDetector();\n"]}
@@ -1,10 +1,10 @@
1
- import { DetectorSync, IResource } from '@opentelemetry/resources';
1
+ import { ResourceDetector, DetectedResource } from '@opentelemetry/resources';
2
2
  /**
3
3
  * The AzureFunctionsDetector can be used to detect if a process is running in Azure Functions
4
4
  * @returns a {@link Resource} populated with data about the environment or an empty Resource if detection fails.
5
5
  */
6
- declare class AzureFunctionsDetector implements DetectorSync {
7
- detect(): IResource;
6
+ declare class AzureFunctionsDetector implements ResourceDetector {
7
+ detect(): DetectedResource;
8
8
  }
9
9
  export declare const azureFunctionsDetector: AzureFunctionsDetector;
10
10
  export {};
@@ -16,7 +16,6 @@
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.azureFunctionsDetector = void 0;
19
- const resources_1 = require("@opentelemetry/resources");
20
19
  const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
21
20
  const types_1 = require("../types");
22
21
  const utils_1 = require("../utils");
@@ -48,26 +47,38 @@ class AzureFunctionsDetector {
48
47
  [semantic_conventions_1.SEMRESATTRS_PROCESS_PID]: process.pid,
49
48
  };
50
49
  if (serviceName) {
51
- attributes = Object.assign(Object.assign({}, attributes), { [semantic_conventions_1.SEMRESATTRS_SERVICE_NAME]: serviceName });
50
+ attributes = {
51
+ ...attributes,
52
+ [semantic_conventions_1.SEMRESATTRS_SERVICE_NAME]: serviceName,
53
+ };
52
54
  }
53
55
  if (functionInstance) {
54
- attributes = Object.assign(Object.assign({}, attributes), { [semantic_conventions_1.SEMRESATTRS_FAAS_INSTANCE]: functionInstance });
56
+ attributes = {
57
+ ...attributes,
58
+ [semantic_conventions_1.SEMRESATTRS_FAAS_INSTANCE]: functionInstance,
59
+ };
55
60
  }
56
61
  if (functionMemLimit) {
57
- attributes = Object.assign(Object.assign({}, attributes), { [semantic_conventions_1.SEMRESATTRS_FAAS_MAX_MEMORY]: functionMemLimit });
62
+ attributes = {
63
+ ...attributes,
64
+ [semantic_conventions_1.SEMRESATTRS_FAAS_MAX_MEMORY]: functionMemLimit,
65
+ };
58
66
  }
59
67
  const azureResourceUri = (0, utils_1.getAzureResourceUri)(serviceName);
60
68
  if (azureResourceUri) {
61
- attributes = Object.assign(Object.assign({}, attributes), { [types_1.CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE]: azureResourceUri });
69
+ attributes = {
70
+ ...attributes,
71
+ ...{ [types_1.CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE]: azureResourceUri },
72
+ };
62
73
  }
63
74
  for (const [key, value] of Object.entries(AZURE_FUNCTIONS_ATTRIBUTE_ENV_VARS)) {
64
75
  const envVar = process.env[value];
65
76
  if (envVar) {
66
- attributes = Object.assign(Object.assign({}, attributes), { [key]: envVar });
77
+ attributes = { ...attributes, ...{ [key]: envVar } };
67
78
  }
68
79
  }
69
80
  }
70
- return new resources_1.Resource(attributes);
81
+ return { attributes };
71
82
  }
72
83
  }
73
84
  exports.azureFunctionsDetector = new AzureFunctionsDetector();
@@ -1 +1 @@
1
- {"version":3,"file":"AzureFunctionsDetector.js","sourceRoot":"","sources":["../../../src/detectors/AzureFunctionsDetector.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,wDAA6E;AAE7E,8EAU6C;AAC7C,oCAMkB;AAClB,oCAAgE;AAEhE,MAAM,kCAAkC,GAAG;IACzC,CAAC,+CAAwB,CAAC,EAAE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,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CACvC,kCAAkC,CACnC,EAAE;gBACD,MAAM,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;CACF;AAEY,QAAA,sBAAsB,GAAG,IAAI,sBAAsB,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';\n\nimport {\n SEMRESATTRS_FAAS_MAX_MEMORY,\n SEMRESATTRS_FAAS_INSTANCE,\n SEMRESATTRS_CLOUD_PROVIDER,\n SEMRESATTRS_CLOUD_PLATFORM,\n SEMRESATTRS_CLOUD_REGION,\n CLOUDPROVIDERVALUES_AZURE,\n CLOUDPLATFORMVALUES_AZURE_FUNCTIONS,\n SEMRESATTRS_SERVICE_NAME,\n SEMRESATTRS_PROCESS_PID,\n} from '@opentelemetry/semantic-conventions';\nimport {\n WEBSITE_SITE_NAME,\n WEBSITE_INSTANCE_ID,\n FUNCTIONS_MEM_LIMIT,\n REGION_NAME,\n CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE,\n} from '../types';\nimport { getAzureResourceUri, isAzureFunction } from '../utils';\n\nconst AZURE_FUNCTIONS_ATTRIBUTE_ENV_VARS = {\n [SEMRESATTRS_SERVICE_NAME]: WEBSITE_SITE_NAME,\n [SEMRESATTRS_FAAS_INSTANCE]: WEBSITE_INSTANCE_ID,\n [SEMRESATTRS_FAAS_MAX_MEMORY]: FUNCTIONS_MEM_LIMIT,\n};\n\n/**\n * The AzureFunctionsDetector can be used to detect if a process is running in Azure Functions\n * @returns a {@link Resource} populated with data about the environment or an empty Resource if detection fails.\n */\nclass AzureFunctionsDetector implements DetectorSync {\n detect(): IResource {\n let attributes = {};\n const serviceName = process.env[WEBSITE_SITE_NAME];\n\n /**\n * Checks that we are operating within an Azure Function using the function version since WEBSITE_SITE_NAME\n * will exist in Azure App Service as well and detectors should be mutually exclusive.\n * If the function version is not present, we check for the website sku to determine if it is a function.\n */\n if (serviceName && isAzureFunction()) {\n const functionInstance = process.env[WEBSITE_INSTANCE_ID];\n const functionMemLimit = process.env[FUNCTIONS_MEM_LIMIT];\n\n attributes = {\n [SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AZURE,\n [SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AZURE_FUNCTIONS,\n [SEMRESATTRS_CLOUD_REGION]: process.env[REGION_NAME],\n [SEMRESATTRS_PROCESS_PID]: process.pid,\n };\n\n if (serviceName) {\n attributes = {\n ...attributes,\n [SEMRESATTRS_SERVICE_NAME]: serviceName,\n };\n }\n if (functionInstance) {\n attributes = {\n ...attributes,\n [SEMRESATTRS_FAAS_INSTANCE]: functionInstance,\n };\n }\n if (functionMemLimit) {\n attributes = {\n ...attributes,\n [SEMRESATTRS_FAAS_MAX_MEMORY]: functionMemLimit,\n };\n }\n const azureResourceUri = getAzureResourceUri(serviceName);\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 AZURE_FUNCTIONS_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\nexport const azureFunctionsDetector = new AzureFunctionsDetector();\n"]}
1
+ {"version":3,"file":"AzureFunctionsDetector.js","sourceRoot":"","sources":["../../../src/detectors/AzureFunctionsDetector.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAGH,8EAU6C;AAC7C,oCAMkB;AAClB,oCAAgE;AAEhE,MAAM,kCAAkC,GAAG;IACzC,CAAC,+CAAwB,CAAC,EAAE,yBAAiB;IAC7C,CAAC,gDAAyB,CAAC,EAAE,2BAAmB;IAChD,CAAC,kDAA2B,CAAC,EAAE,2BAAmB;CACnD,CAAC;AAEF;;;GAGG;AACH,MAAM,sBAAsB;IAC1B,MAAM;QACJ,IAAI,UAAU,GAAG,EAAE,CAAC;QACpB,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,yBAAiB,CAAC,CAAC;QAEnD;;;;WAIG;QACH,IAAI,WAAW,IAAI,IAAA,uBAAe,GAAE,EAAE;YACpC,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,2BAAmB,CAAC,CAAC;YAC1D,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,2BAAmB,CAAC,CAAC;YAE1D,UAAU,GAAG;gBACX,CAAC,iDAA0B,CAAC,EAAE,gDAAyB;gBACvD,CAAC,iDAA0B,CAAC,EAAE,0DAAmC;gBACjE,CAAC,+CAAwB,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAW,CAAC;gBACpD,CAAC,8CAAuB,CAAC,EAAE,OAAO,CAAC,GAAG;aACvC,CAAC;YAEF,IAAI,WAAW,EAAE;gBACf,UAAU,GAAG;oBACX,GAAG,UAAU;oBACb,CAAC,+CAAwB,CAAC,EAAE,WAAW;iBACxC,CAAC;aACH;YACD,IAAI,gBAAgB,EAAE;gBACpB,UAAU,GAAG;oBACX,GAAG,UAAU;oBACb,CAAC,gDAAyB,CAAC,EAAE,gBAAgB;iBAC9C,CAAC;aACH;YACD,IAAI,gBAAgB,EAAE;gBACpB,UAAU,GAAG;oBACX,GAAG,UAAU;oBACb,CAAC,kDAA2B,CAAC,EAAE,gBAAgB;iBAChD,CAAC;aACH;YACD,MAAM,gBAAgB,GAAG,IAAA,2BAAmB,EAAC,WAAW,CAAC,CAAC;YAC1D,IAAI,gBAAgB,EAAE;gBACpB,UAAU,GAAG;oBACX,GAAG,UAAU;oBACb,GAAG,EAAE,CAAC,4CAAoC,CAAC,EAAE,gBAAgB,EAAE;iBAChE,CAAC;aACH;YAED,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CACvC,kCAAkC,CACnC,EAAE;gBACD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBAClC,IAAI,MAAM,EAAE;oBACV,UAAU,GAAG,EAAE,GAAG,UAAU,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;iBACtD;aACF;SACF;QACD,OAAO,EAAE,UAAU,EAAE,CAAC;IACxB,CAAC;CACF;AAEY,QAAA,sBAAsB,GAAG,IAAI,sBAAsB,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 { ResourceDetector, DetectedResource } from '@opentelemetry/resources';\nimport {\n SEMRESATTRS_FAAS_MAX_MEMORY,\n SEMRESATTRS_FAAS_INSTANCE,\n SEMRESATTRS_CLOUD_PROVIDER,\n SEMRESATTRS_CLOUD_PLATFORM,\n SEMRESATTRS_CLOUD_REGION,\n CLOUDPROVIDERVALUES_AZURE,\n CLOUDPLATFORMVALUES_AZURE_FUNCTIONS,\n SEMRESATTRS_SERVICE_NAME,\n SEMRESATTRS_PROCESS_PID,\n} from '@opentelemetry/semantic-conventions';\nimport {\n WEBSITE_SITE_NAME,\n WEBSITE_INSTANCE_ID,\n FUNCTIONS_MEM_LIMIT,\n REGION_NAME,\n CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE,\n} from '../types';\nimport { getAzureResourceUri, isAzureFunction } from '../utils';\n\nconst AZURE_FUNCTIONS_ATTRIBUTE_ENV_VARS = {\n [SEMRESATTRS_SERVICE_NAME]: WEBSITE_SITE_NAME,\n [SEMRESATTRS_FAAS_INSTANCE]: WEBSITE_INSTANCE_ID,\n [SEMRESATTRS_FAAS_MAX_MEMORY]: FUNCTIONS_MEM_LIMIT,\n};\n\n/**\n * The AzureFunctionsDetector can be used to detect if a process is running in Azure Functions\n * @returns a {@link Resource} populated with data about the environment or an empty Resource if detection fails.\n */\nclass AzureFunctionsDetector implements ResourceDetector {\n detect(): DetectedResource {\n let attributes = {};\n const serviceName = process.env[WEBSITE_SITE_NAME];\n\n /**\n * Checks that we are operating within an Azure Function using the function version since WEBSITE_SITE_NAME\n * will exist in Azure App Service as well and detectors should be mutually exclusive.\n * If the function version is not present, we check for the website sku to determine if it is a function.\n */\n if (serviceName && isAzureFunction()) {\n const functionInstance = process.env[WEBSITE_INSTANCE_ID];\n const functionMemLimit = process.env[FUNCTIONS_MEM_LIMIT];\n\n attributes = {\n [SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AZURE,\n [SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AZURE_FUNCTIONS,\n [SEMRESATTRS_CLOUD_REGION]: process.env[REGION_NAME],\n [SEMRESATTRS_PROCESS_PID]: process.pid,\n };\n\n if (serviceName) {\n attributes = {\n ...attributes,\n [SEMRESATTRS_SERVICE_NAME]: serviceName,\n };\n }\n if (functionInstance) {\n attributes = {\n ...attributes,\n [SEMRESATTRS_FAAS_INSTANCE]: functionInstance,\n };\n }\n if (functionMemLimit) {\n attributes = {\n ...attributes,\n [SEMRESATTRS_FAAS_MAX_MEMORY]: functionMemLimit,\n };\n }\n const azureResourceUri = getAzureResourceUri(serviceName);\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 AZURE_FUNCTIONS_ATTRIBUTE_ENV_VARS\n )) {\n const envVar = process.env[value];\n if (envVar) {\n attributes = { ...attributes, ...{ [key]: envVar } };\n }\n }\n }\n return { attributes };\n }\n}\n\nexport const azureFunctionsDetector = new AzureFunctionsDetector();\n"]}
@@ -1,11 +1,11 @@
1
- import { DetectorSync, IResource, ResourceAttributes } from '@opentelemetry/resources';
1
+ import { ResourceDetector, DetectedResource, DetectedResourceAttributes } from '@opentelemetry/resources';
2
2
  /**
3
3
  * The AzureVmDetector can be used to detect if a process is running in an Azure VM.
4
4
  * @returns a {@link Resource} populated with data about the environment or an empty Resource if detection fails.
5
5
  */
6
- declare class AzureVmResourceDetector implements DetectorSync {
7
- detect(): IResource;
8
- getAzureVmMetadata(): Promise<ResourceAttributes>;
6
+ declare class AzureVmResourceDetector implements ResourceDetector {
7
+ detect(): DetectedResource;
8
+ getAzureVmMetadata(): Promise<DetectedResourceAttributes>;
9
9
  }
10
10
  export declare const azureVmDetector: AzureVmResourceDetector;
11
11
  export {};
@@ -19,7 +19,6 @@ exports.azureVmDetector = void 0;
19
19
  const http = require("http");
20
20
  const api_1 = require("@opentelemetry/api");
21
21
  const core_1 = require("@opentelemetry/core");
22
- const resources_1 = require("@opentelemetry/resources");
23
22
  const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
24
23
  const types_1 = require("../types");
25
24
  /**
@@ -28,63 +27,86 @@ const types_1 = require("../types");
28
27
  */
29
28
  class AzureVmResourceDetector {
30
29
  detect() {
31
- const attributes = api_1.context.with((0, core_1.suppressTracing)(api_1.context.active()), () => this.getAzureVmMetadata());
32
- return new resources_1.Resource({}, attributes);
30
+ const dataPromise = api_1.context.with((0, core_1.suppressTracing)(api_1.context.active()), () => this.getAzureVmMetadata());
31
+ const attrNames = [
32
+ types_1.AZURE_VM_SCALE_SET_NAME_ATTRIBUTE,
33
+ types_1.AZURE_VM_SKU_ATTRIBUTE,
34
+ semantic_conventions_1.SEMRESATTRS_CLOUD_PLATFORM,
35
+ semantic_conventions_1.SEMRESATTRS_CLOUD_PROVIDER,
36
+ semantic_conventions_1.SEMRESATTRS_CLOUD_REGION,
37
+ types_1.CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE,
38
+ semantic_conventions_1.SEMRESATTRS_HOST_ID,
39
+ semantic_conventions_1.SEMRESATTRS_HOST_NAME,
40
+ semantic_conventions_1.SEMRESATTRS_HOST_TYPE,
41
+ semantic_conventions_1.SEMRESATTRS_OS_VERSION,
42
+ ];
43
+ const attributes = {};
44
+ attrNames.forEach(name => {
45
+ // Each resource attribute is determined asynchronously in _gatherData().
46
+ attributes[name] = dataPromise.then(data => data[name]);
47
+ });
48
+ return { attributes };
33
49
  }
34
50
  async getAzureVmMetadata() {
35
- const options = {
36
- host: types_1.AZURE_VM_METADATA_HOST,
37
- path: types_1.AZURE_VM_METADATA_PATH,
38
- method: 'GET',
39
- timeout: 5000,
40
- headers: {
41
- Metadata: 'True',
42
- },
43
- };
44
- const metadata = await new Promise((resolve, reject) => {
45
- const timeoutId = setTimeout(() => {
46
- req.destroy();
47
- reject(new Error('Azure metadata service request timed out.'));
48
- }, 1000);
49
- const req = http.request(options, res => {
50
- clearTimeout(timeoutId);
51
- const { statusCode } = res;
52
- res.setEncoding('utf8');
53
- let rawData = '';
54
- res.on('data', chunk => (rawData += chunk));
55
- res.on('end', () => {
56
- if (statusCode && statusCode >= 200 && statusCode < 300) {
57
- try {
58
- resolve(JSON.parse(rawData));
51
+ try {
52
+ const options = {
53
+ host: types_1.AZURE_VM_METADATA_HOST,
54
+ path: types_1.AZURE_VM_METADATA_PATH,
55
+ method: 'GET',
56
+ timeout: 5000,
57
+ headers: {
58
+ Metadata: 'True',
59
+ },
60
+ };
61
+ const metadata = await new Promise((resolve, reject) => {
62
+ const timeoutId = setTimeout(() => {
63
+ req.destroy();
64
+ reject(new Error('Azure metadata service request timed out.'));
65
+ }, 1000);
66
+ const req = http.request(options, res => {
67
+ clearTimeout(timeoutId);
68
+ const { statusCode } = res;
69
+ res.setEncoding('utf8');
70
+ let rawData = '';
71
+ res.on('data', chunk => (rawData += chunk));
72
+ res.on('end', () => {
73
+ if (statusCode && statusCode >= 200 && statusCode < 300) {
74
+ try {
75
+ resolve(JSON.parse(rawData));
76
+ }
77
+ catch (error) {
78
+ reject(error);
79
+ }
59
80
  }
60
- catch (error) {
61
- reject(error);
81
+ else {
82
+ reject(new Error('Failed to load page, status code: ' + statusCode));
62
83
  }
63
- }
64
- else {
65
- reject(new Error('Failed to load page, status code: ' + statusCode));
66
- }
84
+ });
67
85
  });
86
+ req.on('error', err => {
87
+ clearTimeout(timeoutId);
88
+ reject(err);
89
+ });
90
+ req.end();
68
91
  });
69
- req.on('error', err => {
70
- clearTimeout(timeoutId);
71
- reject(err);
72
- });
73
- req.end();
74
- });
75
- const attributes = {
76
- [types_1.AZURE_VM_SCALE_SET_NAME_ATTRIBUTE]: metadata['vmScaleSetName'],
77
- [types_1.AZURE_VM_SKU_ATTRIBUTE]: metadata['sku'],
78
- [semantic_conventions_1.SEMRESATTRS_CLOUD_PLATFORM]: semantic_conventions_1.CLOUDPLATFORMVALUES_AZURE_VM,
79
- [semantic_conventions_1.SEMRESATTRS_CLOUD_PROVIDER]: semantic_conventions_1.CLOUDPROVIDERVALUES_AZURE,
80
- [semantic_conventions_1.SEMRESATTRS_CLOUD_REGION]: metadata['location'],
81
- [types_1.CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE]: metadata['resourceId'],
82
- [semantic_conventions_1.SEMRESATTRS_HOST_ID]: metadata['vmId'],
83
- [semantic_conventions_1.SEMRESATTRS_HOST_NAME]: metadata['name'],
84
- [semantic_conventions_1.SEMRESATTRS_HOST_TYPE]: metadata['vmSize'],
85
- [semantic_conventions_1.SEMRESATTRS_OS_VERSION]: metadata['version'],
86
- };
87
- return attributes;
92
+ const attributes = {
93
+ [types_1.AZURE_VM_SCALE_SET_NAME_ATTRIBUTE]: metadata['vmScaleSetName'],
94
+ [types_1.AZURE_VM_SKU_ATTRIBUTE]: metadata['sku'],
95
+ [semantic_conventions_1.SEMRESATTRS_CLOUD_PLATFORM]: semantic_conventions_1.CLOUDPLATFORMVALUES_AZURE_VM,
96
+ [semantic_conventions_1.SEMRESATTRS_CLOUD_PROVIDER]: semantic_conventions_1.CLOUDPROVIDERVALUES_AZURE,
97
+ [semantic_conventions_1.SEMRESATTRS_CLOUD_REGION]: metadata['location'],
98
+ [types_1.CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE]: metadata['resourceId'],
99
+ [semantic_conventions_1.SEMRESATTRS_HOST_ID]: metadata['vmId'],
100
+ [semantic_conventions_1.SEMRESATTRS_HOST_NAME]: metadata['name'],
101
+ [semantic_conventions_1.SEMRESATTRS_HOST_TYPE]: metadata['vmSize'],
102
+ [semantic_conventions_1.SEMRESATTRS_OS_VERSION]: metadata['version'],
103
+ };
104
+ return attributes;
105
+ }
106
+ catch (err) {
107
+ api_1.diag.debug('AzureVmResourceDetector: not running in an Azure VM:', err.message);
108
+ return {};
109
+ }
88
110
  }
89
111
  }
90
112
  exports.azureVmDetector = new AzureVmResourceDetector();
@@ -1 +1 @@
1
- {"version":3,"file":"AzureVmDetector.js","sourceRoot":"","sources":["../../../src/detectors/AzureVmDetector.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,6BAA6B;AAE7B,4CAA6C;AAC7C,8CAAsD;AACtD,wDA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B,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 * as http from 'http';\n\nimport { context } from '@opentelemetry/api';\nimport { suppressTracing } from '@opentelemetry/core';\nimport {\n DetectorSync,\n IResource,\n Resource,\n ResourceAttributes,\n} from '@opentelemetry/resources';\nimport {\n CLOUDPLATFORMVALUES_AZURE_VM,\n CLOUDPROVIDERVALUES_AZURE,\n SEMRESATTRS_CLOUD_PLATFORM,\n SEMRESATTRS_CLOUD_PROVIDER,\n SEMRESATTRS_CLOUD_REGION,\n SEMRESATTRS_HOST_ID,\n SEMRESATTRS_HOST_NAME,\n SEMRESATTRS_HOST_TYPE,\n SEMRESATTRS_OS_VERSION,\n} from '@opentelemetry/semantic-conventions';\nimport {\n CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE,\n AZURE_VM_METADATA_HOST,\n AZURE_VM_METADATA_PATH,\n AZURE_VM_SCALE_SET_NAME_ATTRIBUTE,\n AZURE_VM_SKU_ATTRIBUTE,\n AzureVmMetadata,\n} from '../types';\n\n/**\n * The AzureVmDetector can be used to detect if a process is running in an Azure VM.\n * @returns a {@link Resource} populated with data about the environment or an empty Resource if detection fails.\n */\nclass AzureVmResourceDetector implements DetectorSync {\n detect(): IResource {\n const attributes = context.with(suppressTracing(context.active()), () =>\n this.getAzureVmMetadata()\n );\n return new Resource({}, attributes);\n }\n\n async getAzureVmMetadata(): Promise<ResourceAttributes> {\n const options = {\n host: AZURE_VM_METADATA_HOST,\n path: AZURE_VM_METADATA_PATH,\n method: 'GET',\n timeout: 5000,\n headers: {\n Metadata: 'True',\n },\n };\n const metadata: AzureVmMetadata = await new Promise((resolve, reject) => {\n const timeoutId = setTimeout(() => {\n req.destroy();\n reject(new Error('Azure metadata service request timed out.'));\n }, 1000);\n\n const req = http.request(options, res => {\n clearTimeout(timeoutId);\n const { statusCode } = res;\n res.setEncoding('utf8');\n let rawData = '';\n res.on('data', chunk => (rawData += chunk));\n res.on('end', () => {\n if (statusCode && statusCode >= 200 && statusCode < 300) {\n try {\n resolve(JSON.parse(rawData));\n } catch (error) {\n reject(error);\n }\n } else {\n reject(\n new Error('Failed to load page, status code: ' + statusCode)\n );\n }\n });\n });\n req.on('error', err => {\n clearTimeout(timeoutId);\n reject(err);\n });\n req.end();\n });\n\n const attributes = {\n [AZURE_VM_SCALE_SET_NAME_ATTRIBUTE]: metadata['vmScaleSetName'],\n [AZURE_VM_SKU_ATTRIBUTE]: metadata['sku'],\n [SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AZURE_VM,\n [SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AZURE,\n [SEMRESATTRS_CLOUD_REGION]: metadata['location'],\n [CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE]: metadata['resourceId'],\n [SEMRESATTRS_HOST_ID]: metadata['vmId'],\n [SEMRESATTRS_HOST_NAME]: metadata['name'],\n [SEMRESATTRS_HOST_TYPE]: metadata['vmSize'],\n [SEMRESATTRS_OS_VERSION]: metadata['version'],\n };\n return attributes;\n }\n}\n\nexport const azureVmDetector = new AzureVmResourceDetector();\n"]}
1
+ {"version":3,"file":"AzureVmDetector.js","sourceRoot":"","sources":["../../../src/detectors/AzureVmDetector.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,6BAA6B;AAE7B,4CAAmD;AACnD,8CAAsD;AAMtD,8EAU6C;AAC7C,oCAOkB;AAElB;;;GAGG;AACH,MAAM,uBAAuB;IAC3B,MAAM;QACJ,MAAM,WAAW,GAAG,aAAO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C;gBAC9D,CAAC,0CAAmB,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC;gBACvC,CAAC,4CAAqB,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC;gBACzC,CAAC,4CAAqB,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC;gBAC3C,CAAC,6CAAsB,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC;aAC9C,CAAC;YACF,OAAO,UAAU,CAAC;SACnB;QAAC,OAAO,GAAQ,EAAE;YACjB,UAAI,CAAC,KAAK,CACR,sDAAsD,EACtD,GAAG,CAAC,OAAO,CACZ,CAAC;YACF,OAAO,EAAE,CAAC;SACX;IACH,CAAC;CACF;AAEY,QAAA,eAAe,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 * as http from 'http';\n\nimport { context, diag } from '@opentelemetry/api';\nimport { suppressTracing } from '@opentelemetry/core';\nimport {\n ResourceDetector,\n DetectedResource,\n DetectedResourceAttributes,\n} from '@opentelemetry/resources';\nimport {\n CLOUDPLATFORMVALUES_AZURE_VM,\n CLOUDPROVIDERVALUES_AZURE,\n SEMRESATTRS_CLOUD_PLATFORM,\n SEMRESATTRS_CLOUD_PROVIDER,\n SEMRESATTRS_CLOUD_REGION,\n SEMRESATTRS_HOST_ID,\n SEMRESATTRS_HOST_NAME,\n SEMRESATTRS_HOST_TYPE,\n SEMRESATTRS_OS_VERSION,\n} from '@opentelemetry/semantic-conventions';\nimport {\n CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE,\n AZURE_VM_METADATA_HOST,\n AZURE_VM_METADATA_PATH,\n AZURE_VM_SCALE_SET_NAME_ATTRIBUTE,\n AZURE_VM_SKU_ATTRIBUTE,\n AzureVmMetadata,\n} from '../types';\n\n/**\n * The AzureVmDetector can be used to detect if a process is running in an Azure VM.\n * @returns a {@link Resource} populated with data about the environment or an empty Resource if detection fails.\n */\nclass AzureVmResourceDetector implements ResourceDetector {\n detect(): DetectedResource {\n const dataPromise = context.with(suppressTracing(context.active()), () =>\n this.getAzureVmMetadata()\n );\n\n const attrNames = [\n AZURE_VM_SCALE_SET_NAME_ATTRIBUTE,\n AZURE_VM_SKU_ATTRIBUTE,\n SEMRESATTRS_CLOUD_PLATFORM,\n SEMRESATTRS_CLOUD_PROVIDER,\n SEMRESATTRS_CLOUD_REGION,\n CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE,\n SEMRESATTRS_HOST_ID,\n SEMRESATTRS_HOST_NAME,\n SEMRESATTRS_HOST_TYPE,\n SEMRESATTRS_OS_VERSION,\n ];\n\n const attributes = {} as DetectedResourceAttributes;\n attrNames.forEach(name => {\n // Each resource attribute is determined asynchronously in _gatherData().\n attributes[name] = dataPromise.then(data => data[name]);\n });\n\n return { attributes };\n }\n\n async getAzureVmMetadata(): Promise<DetectedResourceAttributes> {\n try {\n const options = {\n host: AZURE_VM_METADATA_HOST,\n path: AZURE_VM_METADATA_PATH,\n method: 'GET',\n timeout: 5000,\n headers: {\n Metadata: 'True',\n },\n };\n const metadata: AzureVmMetadata = await new Promise((resolve, reject) => {\n const timeoutId = setTimeout(() => {\n req.destroy();\n reject(new Error('Azure metadata service request timed out.'));\n }, 1000);\n\n const req = http.request(options, res => {\n clearTimeout(timeoutId);\n const { statusCode } = res;\n res.setEncoding('utf8');\n let rawData = '';\n res.on('data', chunk => (rawData += chunk));\n res.on('end', () => {\n if (statusCode && statusCode >= 200 && statusCode < 300) {\n try {\n resolve(JSON.parse(rawData));\n } catch (error) {\n reject(error);\n }\n } else {\n reject(\n new Error('Failed to load page, status code: ' + statusCode)\n );\n }\n });\n });\n req.on('error', err => {\n clearTimeout(timeoutId);\n reject(err);\n });\n req.end();\n });\n\n const attributes = {\n [AZURE_VM_SCALE_SET_NAME_ATTRIBUTE]: metadata['vmScaleSetName'],\n [AZURE_VM_SKU_ATTRIBUTE]: metadata['sku'],\n [SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AZURE_VM,\n [SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AZURE,\n [SEMRESATTRS_CLOUD_REGION]: metadata['location'],\n [CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE]: metadata['resourceId'],\n [SEMRESATTRS_HOST_ID]: metadata['vmId'],\n [SEMRESATTRS_HOST_NAME]: metadata['name'],\n [SEMRESATTRS_HOST_TYPE]: metadata['vmSize'],\n [SEMRESATTRS_OS_VERSION]: metadata['version'],\n };\n return attributes;\n } catch (err: any) {\n diag.debug(\n 'AzureVmResourceDetector: not running in an Azure VM:',\n err.message\n );\n return {};\n }\n }\n}\n\nexport const azureVmDetector = new AzureVmResourceDetector();\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentelemetry/resource-detector-azure",
3
- "version": "0.6.1",
3
+ "version": "0.8.0",
4
4
  "description": "OpenTelemetry SDK resource detector for Azure",
5
5
  "main": "build/src/index.js",
6
6
  "module": "build/esm/index.js",
@@ -20,7 +20,7 @@
20
20
  "author": "OpenTelemetry Authors",
21
21
  "license": "Apache-2.0",
22
22
  "engines": {
23
- "node": ">=14"
23
+ "node": "^18.19.0 || >=20.6.0"
24
24
  },
25
25
  "files": [
26
26
  "build/src/**/*.js",
@@ -35,25 +35,26 @@
35
35
  },
36
36
  "devDependencies": {
37
37
  "@opentelemetry/api": "^1.0.0",
38
- "@opentelemetry/contrib-test-utils": "^0.45.1",
39
- "@opentelemetry/instrumentation-http": "^0.57.1",
40
- "@types/mocha": "8.2.3",
38
+ "@opentelemetry/contrib-test-utils": "^0.47.0",
39
+ "@opentelemetry/instrumentation-http": "^0.201.0",
40
+ "@opentelemetry/sdk-trace-base": "^2.0.0",
41
+ "@types/mocha": "10.0.10",
41
42
  "@types/node": "18.18.14",
42
- "@types/sinon": "10.0.20",
43
+ "@types/sinon": "17.0.4",
43
44
  "nock": "13.3.3",
44
- "nyc": "15.1.0",
45
+ "nyc": "17.1.0",
45
46
  "rimraf": "5.0.10",
46
- "typescript": "4.4.4"
47
+ "typescript": "5.0.4"
47
48
  },
48
49
  "peerDependencies": {
49
50
  "@opentelemetry/api": "^1.0.0"
50
51
  },
51
52
  "dependencies": {
52
- "@opentelemetry/core": "^1.25.1",
53
- "@opentelemetry/resources": "^1.10.1",
53
+ "@opentelemetry/core": "^2.0.0",
54
+ "@opentelemetry/resources": "^2.0.0",
54
55
  "@opentelemetry/semantic-conventions": "^1.27.0"
55
56
  },
56
57
  "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/detectors/node/opentelemetry-resource-detector-azure#readme",
57
58
  "sideEffects": false,
58
- "gitHead": "1eb77007669bae87fe5664d68ba6533b95275d52"
59
+ "gitHead": "393b51596dc869983a03ce8857658029ca122a15"
59
60
  }