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 8fe785fa82..a23101a1f6 100644 --- a/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureAppServiceDetector.ts +++ b/detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureAppServiceDetector.ts @@ -26,6 +26,7 @@ import { WEBSITE_SITE_NAME, WEBSITE_SLOT_NAME, CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE, + FUNCTIONS_VERSION } from '../types'; import { CloudProviderValues, @@ -49,7 +50,8 @@ class AzureAppServiceDetector implements DetectorSync { detect(): IResource { let attributes = {}; const websiteSiteName = process.env[WEBSITE_SITE_NAME]; - if (websiteSiteName) { + const isAzureFunction = !!process.env[FUNCTIONS_VERSION]; + if (websiteSiteName && !isAzureFunction) { attributes = { ...attributes, [SemanticResourceAttributes.SERVICE_NAME]: websiteSiteName, 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 9c74ecf7d4..46796d3a6a 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 @@ -17,6 +17,8 @@ import * as assert from 'assert'; import { azureAppServiceDetector } from '../../src/detectors/AzureAppServiceDetector'; import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; +import { azureFunctionsDetector } from '../../src'; +import { detectResourcesSync } from '@opentelemetry/resources'; describe('AzureAppServiceDetector', () => { let originalEnv: NodeJS.ProcessEnv; @@ -38,7 +40,9 @@ describe('AzureAppServiceDetector', () => { process.env.WEBSITE_RESOURCE_GROUP = 'test-resource-group'; process.env.WEBSITE_OWNER_NAME = 'test-owner-name'; - const resource = azureAppServiceDetector.detect(); + const resource = detectResourcesSync({ + detectors: [azureFunctionsDetector, azureAppServiceDetector], + }); assert.ok(resource); const attributes = resource.attributes; assert.strictEqual( @@ -88,7 +92,9 @@ describe('AzureAppServiceDetector', () => { process.env.WEBSITE_HOME_STAMPNAME = 'test-home-stamp'; process.env.WEBSITE_OWNER_NAME = 'test-owner-name'; - const resource = azureAppServiceDetector.detect(); + const resource = detectResourcesSync({ + detectors: [azureFunctionsDetector, azureAppServiceDetector], + }); assert.ok(resource); const attributes = resource.attributes; assert.strictEqual( @@ -123,7 +129,9 @@ describe('AzureAppServiceDetector', () => { process.env.WEBSITE_RESOURCE_GROUP = 'test-resource-group'; delete process.env.WEBSITE_OWNER_NAME; - const resource = azureAppServiceDetector.detect(); + const resource = detectResourcesSync({ + detectors: [azureFunctionsDetector, azureAppServiceDetector], + }); assert.ok(resource); const attributes = resource.attributes; 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 9e14426090..1632d0f426 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 @@ -16,7 +16,9 @@ import * as assert from 'assert'; import { azureFunctionsDetector } from '../../src/detectors/AzureFunctionsDetector'; +import { azureAppServiceDetector } from '../../src/detectors/AzureAppServiceDetector'; import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; +import { detectResourcesSync } from '@opentelemetry/resources'; describe('AzureFunctionsDetector', () => { let originalEnv: NodeJS.ProcessEnv; @@ -35,7 +37,51 @@ describe('AzureFunctionsDetector', () => { process.env.FUNCTIONS_EXTENSION_VERSION = '~4'; process.env.WEBSITE_MEMORY_LIMIT_MB = '1000'; - const resource = azureFunctionsDetector.detect(); + const resource = detectResourcesSync({ + detectors: [azureFunctionsDetector, azureAppServiceDetector], + }); + 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' + ); + }); + + it('should not detect azure app service 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 = detectResourcesSync({ + detectors: [azureFunctionsDetector, azureAppServiceDetector], + }); assert.ok(resource); const attributes = resource.attributes; assert.strictEqual(