Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix Azure Fns Detector When Running with App Service Detector #1884

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
WEBSITE_SITE_NAME,
WEBSITE_SLOT_NAME,
CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE,
FUNCTIONS_VERSION,
} from '../types';
import {
CloudProviderValues,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand Down Expand Up @@ -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
);
});
});
Loading