diff --git a/detectors/node/opentelemetry-resource-detector-azure/package.json b/detectors/node/opentelemetry-resource-detector-azure/package.json index 6e1f51ae42..7690843f9d 100644 --- a/detectors/node/opentelemetry-resource-detector-azure/package.json +++ b/detectors/node/opentelemetry-resource-detector-azure/package.json @@ -48,7 +48,7 @@ }, "dependencies": { "@opentelemetry/resources": "^1.10.1", - "@opentelemetry/semantic-conventions": "^1.0.0" + "@opentelemetry/semantic-conventions": "^1.22.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 430899b81c..7811ba4fa3 100644 --- a/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureAppServiceDetector.ts +++ b/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureAppServiceDetector.ts @@ -29,16 +29,22 @@ import { FUNCTIONS_VERSION, } from '../types'; import { - CloudProviderValues, - CloudPlatformValues, - SemanticResourceAttributes, + 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'; const APP_SERVICE_ATTRIBUTE_ENV_VARS = { - [SemanticResourceAttributes.CLOUD_REGION]: REGION_NAME, - [SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: WEBSITE_SLOT_NAME, - [SemanticResourceAttributes.HOST_ID]: WEBSITE_HOSTNAME, - [SemanticResourceAttributes.SERVICE_INSTANCE_ID]: WEBSITE_INSTANCE_ID, + [SEMRESATTRS_CLOUD_REGION]: REGION_NAME, + [SEMRESATTRS_DEPLOYMENT_ENVIRONMENT]: WEBSITE_SLOT_NAME, + [SEMRESATTRS_HOST_ID]: WEBSITE_HOSTNAME, + [SEMRESATTRS_SERVICE_INSTANCE_ID]: WEBSITE_INSTANCE_ID, [AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE]: WEBSITE_HOME_STAMPNAME, }; @@ -54,16 +60,15 @@ class AzureAppServiceDetector implements DetectorSync { if (websiteSiteName && !isAzureFunction) { attributes = { ...attributes, - [SemanticResourceAttributes.SERVICE_NAME]: websiteSiteName, + [SEMRESATTRS_SERVICE_NAME]: websiteSiteName, }; attributes = { ...attributes, - [SemanticResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AZURE, + [SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AZURE, }; attributes = { ...attributes, - [SemanticResourceAttributes.CLOUD_PLATFORM]: - CloudPlatformValues.AZURE_APP_SERVICE, + [SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AZURE_APP_SERVICE, }; const azureResourceUri = this.getAzureResourceUri(websiteSiteName); diff --git a/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureFunctionsDetector.ts b/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureFunctionsDetector.ts index 2a695fd2d6..38b2f62f5e 100644 --- a/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureFunctionsDetector.ts +++ b/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureFunctionsDetector.ts @@ -17,9 +17,15 @@ import { DetectorSync, IResource, Resource } from '@opentelemetry/resources'; import { - CloudProviderValues, - CloudPlatformValues, - SemanticResourceAttributes, + SEMRESATTRS_FAAS_NAME, + SEMRESATTRS_FAAS_VERSION, + SEMRESATTRS_FAAS_MAX_MEMORY, + SEMRESATTRS_FAAS_INSTANCE, + SEMRESATTRS_CLOUD_PROVIDER, + SEMRESATTRS_CLOUD_PLATFORM, + SEMRESATTRS_CLOUD_REGION, + CLOUDPROVIDERVALUES_AZURE, + CLOUDPLATFORMVALUES_AZURE_FUNCTIONS, } from '@opentelemetry/semantic-conventions'; import { WEBSITE_SITE_NAME, @@ -30,10 +36,10 @@ import { } from '../types'; const AZURE_FUNCTIONS_ATTRIBUTE_ENV_VARS = { - [SemanticResourceAttributes.FAAS_NAME]: WEBSITE_SITE_NAME, - [SemanticResourceAttributes.FAAS_VERSION]: FUNCTIONS_VERSION, - [SemanticResourceAttributes.FAAS_INSTANCE]: WEBSITE_INSTANCE_ID, - [SemanticResourceAttributes.FAAS_MAX_MEMORY]: FUNCTIONS_MEM_LIMIT, + [SEMRESATTRS_FAAS_NAME]: WEBSITE_SITE_NAME, + [SEMRESATTRS_FAAS_VERSION]: FUNCTIONS_VERSION, + [SEMRESATTRS_FAAS_INSTANCE]: WEBSITE_INSTANCE_ID, + [SEMRESATTRS_FAAS_MAX_MEMORY]: FUNCTIONS_MEM_LIMIT, }; /** @@ -50,34 +56,33 @@ class AzureFunctionsDetector implements DetectorSync { const functionMemLimit = process.env[FUNCTIONS_MEM_LIMIT]; attributes = { - [SemanticResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AZURE, - [SemanticResourceAttributes.CLOUD_PLATFORM]: - CloudPlatformValues.AZURE_FUNCTIONS, - [SemanticResourceAttributes.CLOUD_REGION]: process.env[REGION_NAME], + [SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AZURE, + [SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AZURE_FUNCTIONS, + [SEMRESATTRS_CLOUD_REGION]: process.env[REGION_NAME], }; if (functionName) { attributes = { ...attributes, - [SemanticResourceAttributes.FAAS_NAME]: functionName, + [SEMRESATTRS_FAAS_NAME]: functionName, }; } if (functionVersion) { attributes = { ...attributes, - [SemanticResourceAttributes.FAAS_VERSION]: functionVersion, + [SEMRESATTRS_FAAS_VERSION]: functionVersion, }; } if (functionInstance) { attributes = { ...attributes, - [SemanticResourceAttributes.FAAS_INSTANCE]: functionInstance, + [SEMRESATTRS_FAAS_INSTANCE]: functionInstance, }; } if (functionMemLimit) { attributes = { ...attributes, - [SemanticResourceAttributes.FAAS_MAX_MEMORY]: functionMemLimit, + [SEMRESATTRS_FAAS_MAX_MEMORY]: functionMemLimit, }; } 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 9de9bc330b..1dfc6da705 100644 --- a/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureVmDetector.ts +++ b/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureVmDetector.ts @@ -22,9 +22,15 @@ import { ResourceAttributes, } from '@opentelemetry/resources'; import { - CloudPlatformValues, - CloudProviderValues, - SemanticResourceAttributes, + 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'; import { CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE, @@ -90,14 +96,14 @@ class AzureVmResourceDetector implements DetectorSync { const attributes = { [AZURE_VM_SCALE_SET_NAME_ATTRIBUTE]: metadata['vmScaleSetName'], [AZURE_VM_SKU_ATTRIBUTE]: metadata['sku'], - [SemanticResourceAttributes.CLOUD_PLATFORM]: CloudPlatformValues.AZURE_VM, - [SemanticResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AZURE, - [SemanticResourceAttributes.CLOUD_REGION]: metadata['location'], + [SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AZURE_VM, + [SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AZURE, + [SEMRESATTRS_CLOUD_REGION]: metadata['location'], [CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE]: metadata['resourceId'], - [SemanticResourceAttributes.HOST_ID]: metadata['vmId'], - [SemanticResourceAttributes.HOST_NAME]: metadata['name'], - [SemanticResourceAttributes.HOST_TYPE]: metadata['vmSize'], - [SemanticResourceAttributes.OS_VERSION]: metadata['version'], + [SEMRESATTRS_HOST_ID]: metadata['vmId'], + [SEMRESATTRS_HOST_NAME]: metadata['name'], + [SEMRESATTRS_HOST_TYPE]: metadata['vmSize'], + [SEMRESATTRS_OS_VERSION]: metadata['version'], }; return attributes; } diff --git a/detectors/node/opentelemetry-resource-detector-azure/test/detectors/AzureAppServiceDetector.test.ts b/detectors/node/opentelemetry-resource-detector-azure/test/detectors/AzureAppServiceDetector.test.ts index 46796d3a6a..c178106f32 100644 --- a/detectors/node/opentelemetry-resource-detector-azure/test/detectors/AzureAppServiceDetector.test.ts +++ b/detectors/node/opentelemetry-resource-detector-azure/test/detectors/AzureAppServiceDetector.test.ts @@ -16,7 +16,15 @@ import * as assert from 'assert'; import { azureAppServiceDetector } from '../../src/detectors/AzureAppServiceDetector'; -import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; +import { + SEMRESATTRS_CLOUD_PLATFORM, + SEMRESATTRS_CLOUD_PROVIDER, + SEMRESATTRS_CLOUD_REGION, + SEMRESATTRS_DEPLOYMENT_ENVIRONMENT, + SEMRESATTRS_HOST_ID, + SEMRESATTRS_SERVICE_INSTANCE_ID, + SEMRESATTRS_SERVICE_NAME, +} from '@opentelemetry/semantic-conventions'; import { azureFunctionsDetector } from '../../src'; import { detectResourcesSync } from '@opentelemetry/resources'; @@ -45,36 +53,24 @@ describe('AzureAppServiceDetector', () => { }); assert.ok(resource); const attributes = resource.attributes; + assert.strictEqual(attributes[SEMRESATTRS_SERVICE_NAME], 'test-site'); + assert.strictEqual(attributes[SEMRESATTRS_CLOUD_PROVIDER], 'azure'); assert.strictEqual( - attributes[SemanticResourceAttributes.SERVICE_NAME], - 'test-site' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.CLOUD_PROVIDER], - 'azure' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.CLOUD_PLATFORM], + attributes[SEMRESATTRS_CLOUD_PLATFORM], 'azure_app_service' ); assert.strictEqual( attributes['cloud.resource_id'], `/subscriptions/${process.env.WEBSITE_OWNER_NAME}/resourceGroups/${process.env.WEBSITE_RESOURCE_GROUP}/providers/Microsoft.Web/sites/${process.env.WEBSITE_SITE_NAME}` ); + assert.strictEqual(attributes[SEMRESATTRS_CLOUD_REGION], 'test-region'); assert.strictEqual( - attributes[SemanticResourceAttributes.CLOUD_REGION], - 'test-region' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT], + attributes[SEMRESATTRS_DEPLOYMENT_ENVIRONMENT], 'test-slot' ); + assert.strictEqual(attributes[SEMRESATTRS_HOST_ID], 'test-hostname'); assert.strictEqual( - attributes[SemanticResourceAttributes.HOST_ID], - 'test-hostname' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID], + attributes[SEMRESATTRS_SERVICE_INSTANCE_ID], 'test-instance-id' ); assert.strictEqual( @@ -97,20 +93,14 @@ describe('AzureAppServiceDetector', () => { }); assert.ok(resource); const attributes = resource.attributes; + assert.strictEqual(attributes[SEMRESATTRS_CLOUD_REGION], 'test-region'); assert.strictEqual( - attributes[SemanticResourceAttributes.CLOUD_REGION], - 'test-region' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT], + attributes[SEMRESATTRS_DEPLOYMENT_ENVIRONMENT], 'test-slot' ); + assert.strictEqual(attributes[SEMRESATTRS_HOST_ID], 'test-hostname'); assert.strictEqual( - attributes[SemanticResourceAttributes.HOST_ID], - 'test-hostname' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID], + attributes[SEMRESATTRS_SERVICE_INSTANCE_ID], 'test-instance-id' ); assert.strictEqual( @@ -134,20 +124,14 @@ describe('AzureAppServiceDetector', () => { }); assert.ok(resource); const attributes = resource.attributes; + assert.strictEqual(attributes[SEMRESATTRS_CLOUD_REGION], 'test-region'); assert.strictEqual( - attributes[SemanticResourceAttributes.CLOUD_REGION], - 'test-region' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT], + attributes[SEMRESATTRS_DEPLOYMENT_ENVIRONMENT], 'test-slot' ); + assert.strictEqual(attributes[SEMRESATTRS_HOST_ID], 'test-hostname'); assert.strictEqual( - attributes[SemanticResourceAttributes.HOST_ID], - 'test-hostname' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID], + attributes[SEMRESATTRS_SERVICE_INSTANCE_ID], 'test-instance-id' ); assert.strictEqual( 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 2918f245f5..0a334ab66f 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 @@ -17,7 +17,16 @@ import * as assert from 'assert'; import { azureFunctionsDetector } from '../../src/detectors/AzureFunctionsDetector'; import { azureAppServiceDetector } from '../../src/detectors/AzureAppServiceDetector'; -import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; +import { + SEMRESATTRS_CLOUD_PLATFORM, + SEMRESATTRS_CLOUD_PROVIDER, + SEMRESATTRS_CLOUD_REGION, + SEMRESATTRS_FAAS_INSTANCE, + SEMRESATTRS_FAAS_MAX_MEMORY, + SEMRESATTRS_FAAS_NAME, + SEMRESATTRS_FAAS_VERSION, + SEMRESATTRS_SERVICE_INSTANCE_ID, +} from '@opentelemetry/semantic-conventions'; import { detectResourcesSync } from '@opentelemetry/resources'; import { AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE } from '../../src/types'; @@ -43,40 +52,22 @@ describe('AzureFunctionsDetector', () => { }); assert.ok(resource); const attributes = resource.attributes; + assert.strictEqual(attributes[SEMRESATTRS_FAAS_NAME], 'test-function'); + assert.strictEqual(attributes[SEMRESATTRS_CLOUD_PROVIDER], 'azure'); assert.strictEqual( - attributes[SemanticResourceAttributes.FAAS_NAME], - 'test-function' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.CLOUD_PROVIDER], - 'azure' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.CLOUD_PLATFORM], + attributes[SEMRESATTRS_CLOUD_PLATFORM], 'azure_functions' ); + assert.strictEqual(attributes[SEMRESATTRS_CLOUD_REGION], 'test-region'); assert.strictEqual( - attributes[SemanticResourceAttributes.CLOUD_REGION], - 'test-region' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.FAAS_INSTANCE], + attributes[SEMRESATTRS_FAAS_INSTANCE], 'test-instance-id' ); - assert.strictEqual( - attributes[SemanticResourceAttributes.FAAS_MAX_MEMORY], - '1000' - ); - assert.strictEqual( - attributes[SemanticResourceAttributes.FAAS_VERSION], - '~4' - ); + assert.strictEqual(attributes[SEMRESATTRS_FAAS_MAX_MEMORY], '1000'); + assert.strictEqual(attributes[SEMRESATTRS_FAAS_VERSION], '~4'); // Should not detect app service values - assert.strictEqual( - attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID], - undefined - ); + assert.strictEqual(attributes[SEMRESATTRS_SERVICE_INSTANCE_ID], undefined); assert.strictEqual( attributes[AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE], diff --git a/package-lock.json b/package-lock.json index 9a502dc61d..f215b16732 100644 --- a/package-lock.json +++ b/package-lock.json @@ -112,7 +112,7 @@ "license": "Apache-2.0", "dependencies": { "@opentelemetry/resources": "^1.10.1", - "@opentelemetry/semantic-conventions": "^1.0.0" + "@opentelemetry/semantic-conventions": "^1.22.0" }, "devDependencies": { "@opentelemetry/api": "^1.0.0", @@ -48028,7 +48028,7 @@ "@opentelemetry/api": "^1.0.0", "@opentelemetry/contrib-test-utils": "^0.38.0", "@opentelemetry/resources": "^1.10.1", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.22.0", "@types/mocha": "8.2.3", "@types/node": "18.6.5", "@types/sinon": "10.0.18",