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..430899b81c 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..2918f245f5 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,10 @@ 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'; +import { AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE } from '../../src/types'; describe('AzureFunctionsDetector', () => { let originalEnv: NodeJS.ProcessEnv; @@ -35,7 +38,9 @@ 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( @@ -66,5 +71,16 @@ describe('AzureFunctionsDetector', () => { attributes[SemanticResourceAttributes.FAAS_VERSION], '~4' ); + + // Should not detect app service values + assert.strictEqual( + attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID], + undefined + ); + + assert.strictEqual( + attributes[AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE], + undefined + ); }); });