diff --git a/sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md b/sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md index f7958ad65f14..b0b30f602be7 100644 --- a/sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md +++ b/sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md @@ -4,8 +4,11 @@ ### Features Added -- Default Resource Detector environment variable to allow for customization. Add App Service Resource Detector to Auto-Instrumentation. +- 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. + ([#33305](https://github.com/Azure/azure-sdk-for-python/pull/33305)) + ([#33373](https://github.com/Azure/azure-sdk-for-python/pull/33373)) ## 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 bef32797a7bb..1535c021da5f 100644 --- a/sdk/monitor/azure-monitor-opentelemetry/README.md +++ b/sdk/monitor/azure-monitor-opentelemetry/README.md @@ -73,7 +73,6 @@ 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` | Specifies OpenTelemetry Resource Detectors to be used to generate Resource Attributes. Defaults to "azure_app_service,azure_vm" to enable the [Azure Resource Detectors][ot_resource_detector_azure] for Azure App Service and Azure VM. 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 6dd2a8cbd558..f63e18e0e866 100644 --- a/sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py +++ b/sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py @@ -32,7 +32,6 @@ _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, @@ -54,7 +53,7 @@ _SUPPORTED_RESOURCE_DETECTORS = ( _AZURE_APP_SERVICE_RESOURCE_DETECTOR_NAME, - _AZURE_VM_RESOURCE_DETECTOR_NAME, + # _AZURE_VM_RESOURCE_DETECTOR_NAME, ) _logger = getLogger(__name__) @@ -104,10 +103,11 @@ def configure_azure_monitor(**kwargs) -> None: _setup_instrumentations(configurations) def _setup_resources(): - os.environ.setdefault( - OTEL_EXPERIMENTAL_RESOURCE_DETECTORS, - ",".join(_SUPPORTED_RESOURCE_DETECTORS) - ) + detectors = os.environ.get(OTEL_EXPERIMENTAL_RESOURCE_DETECTORS, "") + if detectors: + detectors = detectors + "," + detectors += ",".join(_SUPPORTED_RESOURCE_DETECTORS) + os.environ[OTEL_EXPERIMENTAL_RESOURCE_DETECTORS] = 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 bc98f3f523c6..149da170475f 100644 --- a/sdk/monitor/azure-monitor-opentelemetry/tests/configuration/test_configure.py +++ b/sdk/monitor/azure-monitor-opentelemetry/tests/configuration/test_configure.py @@ -199,23 +199,26 @@ def test_setup_resources(self): _setup_resources() self.assertEqual( os.environ["OTEL_EXPERIMENTAL_RESOURCE_DETECTORS"], - "azure_app_service,azure_vm" + # 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"}) - def test_setup_resources_existing_detectors(self): + @patch.dict("os.environ", {"OTEL_EXPERIMENTAL_RESOURCE_DETECTORS": ""}) + def test_setup_resources_empty_string(self): _setup_resources() self.assertEqual( os.environ["OTEL_EXPERIMENTAL_RESOURCE_DETECTORS"], - "test_detector" + # 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,azure_vm"}) - def test_setup_resources_existing_with_azure_detectors(self): + @patch.dict("os.environ", {"OTEL_EXPERIMENTAL_RESOURCE_DETECTORS": "test_detector"}) + def test_setup_resources_existing_detectors(self): _setup_resources() self.assertEqual( os.environ["OTEL_EXPERIMENTAL_RESOURCE_DETECTORS"], - "test_detector,azure_vm" + # 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" ) @patch(