Skip to content

Commit b9bdfe2

Browse files
authored
Make sure functions aren't marked as App Services (#41327)
* Make sure functions aren't marked as windows * changelog * Fix statsbeat functions vs appsvc conflict
1 parent 4dce682 commit b9bdfe2

File tree

5 files changed

+27
-10
lines changed

5 files changed

+27
-10
lines changed

sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
### Bugs Fixed
1515

16+
- Do not count Functions as App Service
17+
([#41327](https://github.com/Azure/azure-sdk-for-python/pull/41327))
18+
1619
### Other Changes
1720

1821
- Extend version range for `psutil` to include 7.x

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ def _is_on_aks():
7070

7171

7272
def _is_attach_enabled():
73-
if _is_on_app_service():
74-
return isdir("/agents/python/")
7573
if _is_on_functions():
7674
return environ.get(_PYTHON_APPLICATIONINSIGHTS_ENABLE_TELEMETRY) == "true"
75+
if _is_on_app_service():
76+
return isdir("/agents/python/")
7777
if _is_on_aks():
7878
return _AKS_ARM_NAMESPACE_ID in environ
7979
return False

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/statsbeat/_statsbeat_metrics.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,14 @@ def _get_attach_metric(self, options: CallbackOptions) -> Iterable[Observation]:
177177
rpId = ""
178178
os_type = platform.system()
179179
# rp, rpId
180-
if _utils._is_on_app_service():
181-
# Web apps
182-
rp = _RP_Names.APP_SERVICE.value
183-
rpId = "{}/{}".format(os.environ.get(_WEBSITE_SITE_NAME), os.environ.get(_WEBSITE_HOME_STAMPNAME, ""))
184-
elif _utils._is_on_functions():
180+
if _utils._is_on_functions():
185181
# Function apps
186182
rp = _RP_Names.FUNCTIONS.value
187183
rpId = os.environ.get(_WEBSITE_HOSTNAME, "")
184+
elif _utils._is_on_app_service():
185+
# Web apps
186+
rp = _RP_Names.APP_SERVICE.value
187+
rpId = "{}/{}".format(os.environ.get(_WEBSITE_SITE_NAME), os.environ.get(_WEBSITE_HOME_STAMPNAME, ""))
188188
elif _utils._is_on_aks():
189189
# AKS
190190
rp = _RP_Names.AKS.value

sdk/monitor/azure-monitor-opentelemetry-exporter/tests/statsbeat/test_statsbeat.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ def test_get_attach_metric_appsvc(self, metadata_mock):
424424
os.environ,
425425
{
426426
"FUNCTIONS_WORKER_RUNTIME": "runtime",
427+
# Functions can have WEBSITE_SITE_NAME
428+
"WEBSITE_SITE_NAME": "site_name",
427429
"WEBSITE_HOSTNAME": "host_name",
428430
},
429431
)

sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_utils.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,10 @@ def test_get_sdk_version_prefix_app_service_windows_attach(self, mock_system, mo
377377

378378
@patch.dict(
379379
"azure.monitor.opentelemetry.exporter._utils.environ",
380-
{"FUNCTIONS_WORKER_RUNTIME": TEST_WEBSITE_SITE_NAME},
380+
{
381+
"FUNCTIONS_WORKER_RUNTIME": TEST_WEBSITE_SITE_NAME,
382+
"WEBSITE_SITE_NAME": TEST_WEBSITE_SITE_NAME,
383+
},
381384
clear=True,
382385
)
383386
@patch("azure.monitor.opentelemetry.exporter._utils.platform.system", return_value="")
@@ -387,7 +390,10 @@ def test_get_sdk_version_prefix_function(self, mock_system):
387390

388391
@patch.dict(
389392
"azure.monitor.opentelemetry.exporter._utils.environ",
390-
{"FUNCTIONS_WORKER_RUNTIME": TEST_WEBSITE_SITE_NAME},
393+
{
394+
"FUNCTIONS_WORKER_RUNTIME": TEST_WEBSITE_SITE_NAME,
395+
"WEBSITE_SITE_NAME": TEST_WEBSITE_SITE_NAME,
396+
},
391397
clear=True,
392398
)
393399
@patch("azure.monitor.opentelemetry.exporter._utils.platform.system", return_value="Linux")
@@ -397,7 +403,10 @@ def test_get_sdk_version_prefix_function_linux(self, mock_system):
397403

398404
@patch.dict(
399405
"azure.monitor.opentelemetry.exporter._utils.environ",
400-
{"FUNCTIONS_WORKER_RUNTIME": TEST_WEBSITE_SITE_NAME},
406+
{
407+
"FUNCTIONS_WORKER_RUNTIME": TEST_WEBSITE_SITE_NAME,
408+
"WEBSITE_SITE_NAME": TEST_WEBSITE_SITE_NAME,
409+
},
401410
clear=True,
402411
)
403412
@patch("azure.monitor.opentelemetry.exporter._utils.platform.system", return_value="Windows")
@@ -409,6 +418,7 @@ def test_get_sdk_version_prefix_function_windows(self, mock_system):
409418
"azure.monitor.opentelemetry.exporter._utils.environ",
410419
{
411420
"FUNCTIONS_WORKER_RUNTIME": TEST_WEBSITE_SITE_NAME,
421+
"WEBSITE_SITE_NAME": TEST_WEBSITE_SITE_NAME,
412422
"PYTHON_APPLICATIONINSIGHTS_ENABLE_TELEMETRY": "true",
413423
},
414424
clear=True,
@@ -422,6 +432,7 @@ def test_get_sdk_version_prefix_function_attach(self, mock_system):
422432
"azure.monitor.opentelemetry.exporter._utils.environ",
423433
{
424434
"FUNCTIONS_WORKER_RUNTIME": TEST_WEBSITE_SITE_NAME,
435+
"WEBSITE_SITE_NAME": TEST_WEBSITE_SITE_NAME,
425436
"PYTHON_APPLICATIONINSIGHTS_ENABLE_TELEMETRY": "true",
426437
},
427438
clear=True,
@@ -435,6 +446,7 @@ def test_get_sdk_version_prefix_function_linux_attach(self, mock_system):
435446
"azure.monitor.opentelemetry.exporter._utils.environ",
436447
{
437448
"FUNCTIONS_WORKER_RUNTIME": TEST_WEBSITE_SITE_NAME,
449+
"WEBSITE_SITE_NAME": TEST_WEBSITE_SITE_NAME,
438450
"PYTHON_APPLICATIONINSIGHTS_ENABLE_TELEMETRY": "true",
439451
},
440452
clear=True,

0 commit comments

Comments
 (0)