diff --git a/sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md b/sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md index b0b30f602be7..d9beb42fe679 100644 --- a/sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md +++ b/sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md @@ -1,14 +1,15 @@ # Release History -## 1.1.1 (2023-11-30) +## 1.1.1 (2023-12-04) ### Features Added - Add App Service Resource Detector to Auto-Instrumentation. ([#33340](https://github.com/Azure/azure-sdk-for-python/pull/33340)) -- Remove VM Resource Detector while bug is investigated. +- Default Resource Detector environment variable to enable configuration. ([#33305](https://github.com/Azure/azure-sdk-for-python/pull/33305)) ([#33373](https://github.com/Azure/azure-sdk-for-python/pull/33373)) + ([#33390](https://github.com/Azure/azure-sdk-for-python/pull/33390)) ## 1.1.0 (2023-11-08) diff --git a/sdk/monitor/azure-monitor-opentelemetry/README.md b/sdk/monitor/azure-monitor-opentelemetry/README.md index 1535c021da5f..2f191e939a9a 100644 --- a/sdk/monitor/azure-monitor-opentelemetry/README.md +++ b/sdk/monitor/azure-monitor-opentelemetry/README.md @@ -73,6 +73,7 @@ You can configure further with [OpenTelemetry environment variables][ot_env_vars | `OTEL_BSP_SCHEDULE_DELAY` | Specifies the distributed tracing export interval in milliseconds. Defaults to 5000. | | `OTEL_TRACES_SAMPLER_ARG` | Specifies the ratio of distributed tracing telemetry to be [sampled][application_insights_sampling]. Accepted values are in the range [0,1]. Defaults to 1.0, meaning no telemetry is sampled out. | | `OTEL_PYTHON_DISABLED_INSTRUMENTATIONS` | Specifies which of the supported instrumentations to disable. Disabled instrumentations will not be instrumented as part of `configure_azure_monitor`. However, they can still be manually instrumented with `instrument()` directly. Accepts a comma-separated list of lowercase [Library Names](#officially-supported-instrumentations). For example, set to `"psycopg2,fastapi"` to disable the Psycopg2 and FastAPI instrumentations. Defaults to an empty list, enabling all supported instrumentations. | +| `OTEL_EXPERIMENTAL_RESOURCE_DETECTORS` | An experimental OpenTelemetry environment variable used to specify Resource Detectors to be used to generate Resource Attributes. This is an experimental feature and the name of this variable and its behavior can change in a non-backwards compatible way. Defaults to "azure_app_service,azure_vm" to enable the [Azure Resource Detectors][ot_resource_detector_azure] for Azure App Service and Azure VM. To add or remove specific resource detectors, set the environment variable accordingly. See the [OpenTelemetry Python Resource Detector Documentation][ot_python_resource_detectors] for more. | #### Azure monitor OpenTelemetry Exporter configurations diff --git a/sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py b/sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py index f63e18e0e866..6dd2a8cbd558 100644 --- a/sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py +++ b/sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py @@ -32,6 +32,7 @@ _ALL_SUPPORTED_INSTRUMENTED_LIBRARIES, _AZURE_APP_SERVICE_RESOURCE_DETECTOR_NAME, _AZURE_SDK_INSTRUMENTATION_NAME, + _AZURE_VM_RESOURCE_DETECTOR_NAME, DISABLE_LOGGING_ARG, DISABLE_METRICS_ARG, DISABLE_TRACING_ARG, @@ -53,7 +54,7 @@ _SUPPORTED_RESOURCE_DETECTORS = ( _AZURE_APP_SERVICE_RESOURCE_DETECTOR_NAME, - # _AZURE_VM_RESOURCE_DETECTOR_NAME, + _AZURE_VM_RESOURCE_DETECTOR_NAME, ) _logger = getLogger(__name__) @@ -103,11 +104,10 @@ def configure_azure_monitor(**kwargs) -> None: _setup_instrumentations(configurations) def _setup_resources(): - detectors = os.environ.get(OTEL_EXPERIMENTAL_RESOURCE_DETECTORS, "") - if detectors: - detectors = detectors + "," - detectors += ",".join(_SUPPORTED_RESOURCE_DETECTORS) - os.environ[OTEL_EXPERIMENTAL_RESOURCE_DETECTORS] = detectors + os.environ.setdefault( + OTEL_EXPERIMENTAL_RESOURCE_DETECTORS, + ",".join(_SUPPORTED_RESOURCE_DETECTORS) + ) def _setup_tracing(configurations: Dict[str, ConfigurationValue]): diff --git a/sdk/monitor/azure-monitor-opentelemetry/tests/configuration/test_configure.py b/sdk/monitor/azure-monitor-opentelemetry/tests/configuration/test_configure.py index 149da170475f..ff487be88c06 100644 --- a/sdk/monitor/azure-monitor-opentelemetry/tests/configuration/test_configure.py +++ b/sdk/monitor/azure-monitor-opentelemetry/tests/configuration/test_configure.py @@ -199,8 +199,7 @@ def test_setup_resources(self): _setup_resources() self.assertEqual( os.environ["OTEL_EXPERIMENTAL_RESOURCE_DETECTORS"], - # TODO: Change back to "azure_app_service,azure_vm" after VM Resource Detector fix for https://github.com/Azure/azure-sdk-for-python/issues/33295 - "azure_app_service" + "azure_app_service,azure_vm" ) @patch.dict("os.environ", {"OTEL_EXPERIMENTAL_RESOURCE_DETECTORS": ""}) @@ -208,8 +207,7 @@ def test_setup_resources_empty_string(self): _setup_resources() self.assertEqual( os.environ["OTEL_EXPERIMENTAL_RESOURCE_DETECTORS"], - # TODO: Change back to "azure_app_service,azure_vm" after VM Resource Detector fix for https://github.com/Azure/azure-sdk-for-python/issues/33295 - "azure_app_service" + "" ) @patch.dict("os.environ", {"OTEL_EXPERIMENTAL_RESOURCE_DETECTORS": "test_detector"}) @@ -217,8 +215,15 @@ def test_setup_resources_existing_detectors(self): _setup_resources() self.assertEqual( os.environ["OTEL_EXPERIMENTAL_RESOURCE_DETECTORS"], - # TODO: Change back to "azure_app_service,azure_vm" after VM Resource Detector fix for https://github.com/Azure/azure-sdk-for-python/issues/33295 - "test_detector,azure_app_service" + "test_detector" + ) + + @patch.dict("os.environ", {"OTEL_EXPERIMENTAL_RESOURCE_DETECTORS": "azure_vm,test_detector, azure_app_service"}) + def test_setup_resources_azure_and_existing_detectors(self): + _setup_resources() + self.assertEqual( + os.environ["OTEL_EXPERIMENTAL_RESOURCE_DETECTORS"], + "azure_vm,test_detector, azure_app_service" ) @patch(