Skip to content

Commit 41eff18

Browse files
authored
Track functions attach scenario (Azure#37717)
1 parent c759481 commit 41eff18

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

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

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

55
### Features Added
66

7+
- Allow tracking of whether in a Azure Functions attach scenario
8+
([#37717](https://github.com/Azure/azure-sdk-for-python/pull/37717))
9+
710
### Breaking Changes
811

912
### Bugs Fixed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
_APPLICATIONINSIGHTS_OPENTELEMETRY_RESOURCE_METRIC_DISABLED = \
1111
"APPLICATIONINSIGHTS_OPENTELEMETRY_RESOURCE_METRIC_DISABLED"
1212
_APPLICATIONINSIGHTS_METRIC_NAMESPACE_OPT_IN = "APPLICATIONINSIGHTS_METRIC_NAMESPACE_OPT_IN"
13+
14+
# RPs
15+
1316
_WEBSITE_SITE_NAME = "WEBSITE_SITE_NAME"
1417
_WEBSITE_HOME_STAMPNAME = "WEBSITE_HOME_STAMPNAME"
1518
_WEBSITE_HOSTNAME = "WEBSITE_HOSTNAME"
1619
_FUNCTIONS_WORKER_RUNTIME = "FUNCTIONS_WORKER_RUNTIME"
20+
_PYTHON_ENABLE_OPENTELEMETRY = "PYTHON_ENABLE_OPENTELEMETRY"
1721
_AKS_ARM_NAMESPACE_ID = "AKS_ARM_NAMESPACE_ID"
1822

1923
# Network

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from azure.monitor.opentelemetry.exporter._constants import (
2424
_AKS_ARM_NAMESPACE_ID,
2525
_APPLICATION_INSIGHTS_RESOURCE_SCOPE,
26+
_PYTHON_ENABLE_OPENTELEMETRY,
2627
_INSTRUMENTATIONS_BIT_MAP,
2728
_FUNCTIONS_WORKER_RUNTIME,
2829
_WEBSITE_SITE_NAME,
@@ -49,20 +50,24 @@
4950
def _is_on_app_service():
5051
return environ.get(_WEBSITE_SITE_NAME) is not None
5152

53+
# Functions
54+
5255
def _is_on_functions():
5356
return environ.get(_FUNCTIONS_WORKER_RUNTIME) is not None
5457

55-
def _is_attach_enabled():
56-
if _is_on_app_service():
57-
return isdir("/agents/python/")
58-
return False
59-
60-
6158
# AKS
6259

6360
def _is_on_aks():
6461
return _AKS_ARM_NAMESPACE_ID in environ
6562

63+
# Attach
64+
65+
def _is_attach_enabled():
66+
if _is_on_app_service():
67+
return isdir("/agents/python/")
68+
if _is_on_functions():
69+
return environ.get(_PYTHON_ENABLE_OPENTELEMETRY) == "true"
70+
return False
6671

6772
def _get_sdk_version_prefix():
6873
sdk_version_prefix = ''

0 commit comments

Comments
 (0)