Skip to content

Commit 38264ba

Browse files
committed
Add preview warning for entry points
1 parent 11a6c8f commit 38264ba

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
([#31740](https://github.com/Azure/azure-sdk-for-python/pull/31740))
1111
- Un-vendoring instrumentations
1212
([#31744](https://github.com/Azure/azure-sdk-for-python/pull/31740))
13+
- Add preview warning for Autoinstrumentation entry points
14+
([#31767](https://github.com/Azure/azure-sdk-for-python/pull/31767))
1315

1416
### Breaking Changes
1517

sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/autoinstrumentation/__init__.py

+8
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@
33
# Licensed under the MIT License. See License in the project root for
44
# license information.
55
# -------------------------------------------------------------------------
6+
7+
from os.path import isdir
8+
9+
_PREVIEW_ENTRY_POINT_WARNING = "OpenTelemetry Autoinstrumentation is in preview."
10+
11+
12+
def _is_attach_enabled():
13+
return isdir("/agents/python/")

sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/autoinstrumentation/_configurator.py

+8
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66

77

88
import logging
9+
from warnings import warn
910

1011
from opentelemetry.sdk._configuration import _OTelSDKConfigurator
1112

13+
from azure.monitor.opentelemetry.autoinstrumentation import (
14+
_is_attach_enabled,
15+
_PREVIEW_ENTRY_POINT_WARNING,
16+
)
1217
from azure.monitor.opentelemetry.diagnostics._diagnostic_logging import (
1318
AzureDiagnosticLogging,
1419
)
@@ -18,6 +23,9 @@
1823

1924
class AzureMonitorConfigurator(_OTelSDKConfigurator):
2025
def _configure(self, **kwargs):
26+
if not _is_attach_enabled():
27+
# raise Warning(_PREVIEW_ENTRY_POINT_WARNING)
28+
warn(_PREVIEW_ENTRY_POINT_WARNING)
2129
try:
2230
AzureDiagnosticLogging.enable(_logger)
2331
super()._configure(**kwargs)

sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/autoinstrumentation/_distro.py

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# --------------------------------------------------------------------------
66
import logging
77
from os import environ
8+
from warnings import warn
89

910
from opentelemetry.environment_variables import (
1011
OTEL_LOGS_EXPORTER,
@@ -20,6 +21,10 @@
2021

2122
from azure.core.settings import settings
2223
from azure.core.tracing.ext.opentelemetry_span import OpenTelemetrySpan
24+
from azure.monitor.opentelemetry.autoinstrumentation import (
25+
_is_attach_enabled,
26+
_PREVIEW_ENTRY_POINT_WARNING,
27+
)
2328
from azure.monitor.opentelemetry.diagnostics._diagnostic_logging import (
2429
AzureDiagnosticLogging,
2530
)
@@ -37,6 +42,8 @@
3742

3843
class AzureMonitorDistro(BaseDistro):
3944
def _configure(self, **kwargs) -> None:
45+
if not _is_attach_enabled():
46+
warn(_PREVIEW_ENTRY_POINT_WARNING)
4047
try:
4148
_configure_auto_instrumentation()
4249
except Exception as ex:

sdk/monitor/azure-monitor-opentelemetry/tests/autoinstrumentation/test_distro.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import warnings
12
from unittest import TestCase
23
from unittest.mock import patch
34

@@ -8,13 +9,30 @@
89

910

1011
class TestDistro(TestCase):
12+
@patch("azure.monitor.opentelemetry.autoinstrumentation._distro._is_attach_enabled", return_value=True)
1113
@patch("azure.monitor.opentelemetry.autoinstrumentation._distro.settings")
1214
@patch(
1315
"azure.monitor.opentelemetry.autoinstrumentation._distro.AzureDiagnosticLogging.enable"
1416
)
15-
def test_configure(self, mock_diagnostics, azure_core_mock):
17+
def test_configure(self, mock_diagnostics, azure_core_mock, attach_mock):
1618
distro = AzureMonitorDistro()
17-
distro.configure()
19+
with warnings.catch_warnings():
20+
warnings.simplefilter("error")
21+
distro.configure()
22+
self.assertEqual(mock_diagnostics.call_count, 2)
23+
self.assertEqual(
24+
azure_core_mock.tracing_implementation, OpenTelemetrySpan
25+
)
26+
27+
@patch("azure.monitor.opentelemetry.autoinstrumentation._distro._is_attach_enabled", return_value=False)
28+
@patch("azure.monitor.opentelemetry.autoinstrumentation._distro.settings")
29+
@patch(
30+
"azure.monitor.opentelemetry.autoinstrumentation._distro.AzureDiagnosticLogging.enable"
31+
)
32+
def test_configure_preview(self, mock_diagnostics, azure_core_mock, attach_mock):
33+
distro = AzureMonitorDistro()
34+
with self.assertWarns(Warning):
35+
distro.configure()
1836
self.assertEqual(mock_diagnostics.call_count, 2)
1937
self.assertEqual(
2038
azure_core_mock.tracing_implementation, OpenTelemetrySpan

0 commit comments

Comments
 (0)