diff --git a/detectors/node/opentelemetry-resource-detector-azure/README.md b/detectors/node/opentelemetry-resource-detector-azure/README.md index f8dd11df05..47ee72608f 100644 --- a/detectors/node/opentelemetry-resource-detector-azure/README.md +++ b/detectors/node/opentelemetry-resource-detector-azure/README.md @@ -16,7 +16,7 @@ npm install --save @opentelemetry/resource-detector-azure ## Usage ```typescript import { detectResources } from '@opentelemetry/resources'; -import { azureAppServiceDetector } from '@opentelemetry/resource-detecotr-azure'; +import { azureAppServiceDetector } from '@opentelemetry/resource-detector-azure'; const resource = detectResourcesSync({ detectors: [azureAppServiceDetector], }); diff --git a/detectors/node/opentelemetry-resource-detector-azure/package.json b/detectors/node/opentelemetry-resource-detector-azure/package.json index 68c5a06217..6b47e05fba 100644 --- a/detectors/node/opentelemetry-resource-detector-azure/package.json +++ b/detectors/node/opentelemetry-resource-detector-azure/package.json @@ -42,16 +42,11 @@ "nock": "13.3.3", "nyc": "15.1.0", "rimraf": "5.0.5", - "sinon": "15.2.0", "ts-mocha": "10.0.0", "typescript": "4.4.4" }, - "peerDependencies": { - "@opentelemetry/api": "^1.0.0" - }, "dependencies": { - "@opentelemetry/core": "^1.0.0", - "@opentelemetry/resources": "^1.0.0", + "@opentelemetry/resources": "^1.10.1", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/detectors/node/opentelemetry-resource-detector-azure#readme" diff --git a/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureAppServiceDetector.ts b/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureAppServiceDetector.ts index fe47320fcd..ad7525ea25 100644 --- a/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureAppServiceDetector.ts +++ b/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureAppServiceDetector.ts @@ -14,11 +14,7 @@ * limitations under the License. */ -import { - DetectorSync, - IResource, - Resource -} from '@opentelemetry/resources'; +import { DetectorSync, IResource, Resource } from '@opentelemetry/resources'; import { CloudProviderValues, diff --git a/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureFunctionsDetector.ts b/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureFunctionsDetector.ts index c539f0e6f0..480d0e800e 100644 --- a/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureFunctionsDetector.ts +++ b/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureFunctionsDetector.ts @@ -14,16 +14,12 @@ * limitations under the License. */ -import { - DetectorSync, - IResource, - Resource -} from '@opentelemetry/resources'; +import { DetectorSync, IResource, Resource } from '@opentelemetry/resources'; import { - CloudProviderValues, - CloudPlatformValues, - SemanticResourceAttributes, + CloudProviderValues, + CloudPlatformValues, + SemanticResourceAttributes, } from '@opentelemetry/semantic-conventions'; const FUNCTION_NAME = 'WEBSITE_SITE_NAME'; @@ -33,10 +29,10 @@ const FUNCTIONS_MEM_LIMIT = 'WEBSITE_MEMORY_LIMIT_MB'; const FUNCTIONS_REGION = 'REGION_NAME'; const AZURE_FUNCTIONS_ATTRIBUTE_ENV_VARS = { - [SemanticResourceAttributes.FAAS_NAME]: FUNCTION_NAME, - [SemanticResourceAttributes.FAAS_VERSION]: FUNCTIONS_VERSION, - [SemanticResourceAttributes.FAAS_INSTANCE]: FUNCTIONS_INSTANCE, - [SemanticResourceAttributes.FAAS_MAX_MEMORY]: FUNCTIONS_MEM_LIMIT, + [SemanticResourceAttributes.FAAS_NAME]: FUNCTION_NAME, + [SemanticResourceAttributes.FAAS_VERSION]: FUNCTIONS_VERSION, + [SemanticResourceAttributes.FAAS_INSTANCE]: FUNCTIONS_INSTANCE, + [SemanticResourceAttributes.FAAS_MAX_MEMORY]: FUNCTIONS_MEM_LIMIT, }; /** @@ -44,56 +40,58 @@ const AZURE_FUNCTIONS_ATTRIBUTE_ENV_VARS = { * @returns a {@link Resource} populated with data about the environment or an empty Resource if detection fails. */ class AzureFunctionsDetector implements DetectorSync { - detect(): IResource { - let attributes = {}; - const functionName = process.env[FUNCTION_NAME]; - if (functionName) { - const functionVersion = process.env[FUNCTIONS_VERSION]; - const functionInstance = process.env[FUNCTIONS_INSTANCE]; - const functionMemLimit = process.env[FUNCTIONS_MEM_LIMIT]; - - attributes = { - [SemanticResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AZURE, - [SemanticResourceAttributes.CLOUD_PLATFORM]: CloudPlatformValues.AZURE_FUNCTIONS, - [SemanticResourceAttributes.CLOUD_REGION]: process.env[FUNCTIONS_REGION], - }; - - if (functionName) { - attributes = { - ...attributes, - [SemanticResourceAttributes.FAAS_NAME]: functionName, - }; - } - if (functionVersion) { - attributes = { - ...attributes, - [SemanticResourceAttributes.FAAS_VERSION]: functionVersion, - }; - } - if (functionInstance) { - attributes = { - ...attributes, - [SemanticResourceAttributes.FAAS_INSTANCE]: functionInstance, - }; - } - if (functionMemLimit) { - attributes = { - ...attributes, - [SemanticResourceAttributes.FAAS_MAX_MEMORY]: functionMemLimit, - }; - } + detect(): IResource { + let attributes = {}; + const functionName = process.env[FUNCTION_NAME]; + if (functionName) { + const functionVersion = process.env[FUNCTIONS_VERSION]; + const functionInstance = process.env[FUNCTIONS_INSTANCE]; + const functionMemLimit = process.env[FUNCTIONS_MEM_LIMIT]; + + attributes = { + [SemanticResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AZURE, + [SemanticResourceAttributes.CLOUD_PLATFORM]: + CloudPlatformValues.AZURE_FUNCTIONS, + [SemanticResourceAttributes.CLOUD_REGION]: + process.env[FUNCTIONS_REGION], + }; + + if (functionName) { + attributes = { + ...attributes, + [SemanticResourceAttributes.FAAS_NAME]: functionName, + }; + } + if (functionVersion) { + attributes = { + ...attributes, + [SemanticResourceAttributes.FAAS_VERSION]: functionVersion, + }; + } + if (functionInstance) { + attributes = { + ...attributes, + [SemanticResourceAttributes.FAAS_INSTANCE]: functionInstance, + }; + } + if (functionMemLimit) { + attributes = { + ...attributes, + [SemanticResourceAttributes.FAAS_MAX_MEMORY]: functionMemLimit, + }; + } - for (const [key, value] of Object.entries( - AZURE_FUNCTIONS_ATTRIBUTE_ENV_VARS - )) { - const envVar = process.env[value]; - if (envVar) { - attributes = { ...attributes, ...{ [key]: envVar } }; - } - } + for (const [key, value] of Object.entries( + AZURE_FUNCTIONS_ATTRIBUTE_ENV_VARS + )) { + const envVar = process.env[value]; + if (envVar) { + attributes = { ...attributes, ...{ [key]: envVar } }; } - return new Resource(attributes); + } } + return new Resource(attributes); + } } export const azureFunctionsDetector = new AzureFunctionsDetector(); diff --git a/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureVmDetector.ts b/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureVmDetector.ts index 31e765933c..19aa648b65 100644 --- a/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureVmDetector.ts +++ b/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureVmDetector.ts @@ -59,7 +59,7 @@ class AzureVmResourceDetector implements DetectorSync { const metadata: any = await new Promise((resolve, reject) => { const timeoutId = setTimeout(() => { req.destroy(); - reject(new Error('EC2 metadata api request timed out.')); + reject(new Error('Azure metadata service request timed out.')); }, 1000); const req = http.request(options, res => { diff --git a/detectors/node/opentelemetry-resource-detector-azure/test/detectors/AzureFunctionsDetector.test.ts b/detectors/node/opentelemetry-resource-detector-azure/test/detectors/AzureFunctionsDetector.test.ts index 2a86ad9192..9e14426090 100644 --- a/detectors/node/opentelemetry-resource-detector-azure/test/detectors/AzureFunctionsDetector.test.ts +++ b/detectors/node/opentelemetry-resource-detector-azure/test/detectors/AzureFunctionsDetector.test.ts @@ -19,52 +19,52 @@ import { azureFunctionsDetector } from '../../src/detectors/AzureFunctionsDetect import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; describe('AzureFunctionsDetector', () => { - let originalEnv: NodeJS.ProcessEnv; - beforeEach(() => { - originalEnv = process.env; - }); - - afterEach(() => { - process.env = originalEnv; - }); - - it('should test functions values', () => { - process.env.WEBSITE_SITE_NAME = 'test-function'; - process.env.REGION_NAME = 'test-region'; - process.env.WEBSITE_INSTANCE_ID = 'test-instance-id'; - process.env.FUNCTIONS_EXTENSION_VERSION = '~4'; - process.env.WEBSITE_MEMORY_LIMIT_MB = '1000'; - - const resource = azureFunctionsDetector.detect(); - assert.ok(resource); - const attributes = resource.attributes; - assert.strictEqual( - attributes[SemanticResourceAttributes.FAAS_NAME], - 'test-function' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.CLOUD_PROVIDER], - 'azure' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.CLOUD_PLATFORM], - 'azure_functions' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.CLOUD_REGION], - 'test-region' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.FAAS_INSTANCE], - 'test-instance-id' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.FAAS_MAX_MEMORY], - '1000' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.FAAS_VERSION], - '~4' - ); - }); + let originalEnv: NodeJS.ProcessEnv; + beforeEach(() => { + originalEnv = process.env; }); + + afterEach(() => { + process.env = originalEnv; + }); + + it('should test functions values', () => { + process.env.WEBSITE_SITE_NAME = 'test-function'; + process.env.REGION_NAME = 'test-region'; + process.env.WEBSITE_INSTANCE_ID = 'test-instance-id'; + process.env.FUNCTIONS_EXTENSION_VERSION = '~4'; + process.env.WEBSITE_MEMORY_LIMIT_MB = '1000'; + + const resource = azureFunctionsDetector.detect(); + assert.ok(resource); + const attributes = resource.attributes; + assert.strictEqual( + attributes[SemanticResourceAttributes.FAAS_NAME], + 'test-function' + ); + assert.strictEqual( + attributes[SemanticResourceAttributes.CLOUD_PROVIDER], + 'azure' + ); + assert.strictEqual( + attributes[SemanticResourceAttributes.CLOUD_PLATFORM], + 'azure_functions' + ); + assert.strictEqual( + attributes[SemanticResourceAttributes.CLOUD_REGION], + 'test-region' + ); + assert.strictEqual( + attributes[SemanticResourceAttributes.FAAS_INSTANCE], + 'test-instance-id' + ); + assert.strictEqual( + attributes[SemanticResourceAttributes.FAAS_MAX_MEMORY], + '1000' + ); + assert.strictEqual( + attributes[SemanticResourceAttributes.FAAS_VERSION], + '~4' + ); + }); +});