about summary refs log tree commit diff
path: root/.venv/lib/python3.12/site-packages/azure/monitor/opentelemetry/_autoinstrumentation
diff options
context:
space:
mode:
authorS. Solomon Darnell2025-03-28 21:52:21 -0500
committerS. Solomon Darnell2025-03-28 21:52:21 -0500
commit4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch)
treeee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/azure/monitor/opentelemetry/_autoinstrumentation
parentcc961e04ba734dd72309fb548a2f97d67d578813 (diff)
downloadgn-ai-master.tar.gz
two version of R2R are here HEAD master
Diffstat (limited to '.venv/lib/python3.12/site-packages/azure/monitor/opentelemetry/_autoinstrumentation')
-rw-r--r--.venv/lib/python3.12/site-packages/azure/monitor/opentelemetry/_autoinstrumentation/__init__.py5
-rw-r--r--.venv/lib/python3.12/site-packages/azure/monitor/opentelemetry/_autoinstrumentation/configurator.py68
-rw-r--r--.venv/lib/python3.12/site-packages/azure/monitor/opentelemetry/_autoinstrumentation/distro.py64
3 files changed, 137 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/azure/monitor/opentelemetry/_autoinstrumentation/__init__.py b/.venv/lib/python3.12/site-packages/azure/monitor/opentelemetry/_autoinstrumentation/__init__.py
new file mode 100644
index 00000000..dcc72b25
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/azure/monitor/opentelemetry/_autoinstrumentation/__init__.py
@@ -0,0 +1,5 @@
+# -------------------------------------------------------------------------
+# Copyright (c) Microsoft Corporation. All rights reserved.
+# Licensed under the MIT License. See License in the project root for
+# license information.
+# -------------------------------------------------------------------------
diff --git a/.venv/lib/python3.12/site-packages/azure/monitor/opentelemetry/_autoinstrumentation/configurator.py b/.venv/lib/python3.12/site-packages/azure/monitor/opentelemetry/_autoinstrumentation/configurator.py
new file mode 100644
index 00000000..834d4765
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/azure/monitor/opentelemetry/_autoinstrumentation/configurator.py
@@ -0,0 +1,68 @@
+# -------------------------------------------------------------------------
+# Copyright (c) Microsoft Corporation. All rights reserved.
+# Licensed under the MIT License. See License in the project root for
+# license information.
+# --------------------------------------------------------------------------
+
+
+from os import environ
+from warnings import warn
+
+from opentelemetry.environment_variables import (
+    OTEL_LOGS_EXPORTER,
+    OTEL_METRICS_EXPORTER,
+    OTEL_TRACES_EXPORTER,
+)
+from opentelemetry.sdk._configuration import _OTelSDKConfigurator
+
+from azure.monitor.opentelemetry.exporter import (  # pylint: disable=import-error,no-name-in-module
+    ApplicationInsightsSampler,
+)
+from azure.monitor.opentelemetry.exporter._utils import (  # pylint: disable=import-error,no-name-in-module
+    _is_attach_enabled,
+)
+from azure.monitor.opentelemetry._constants import (
+    _PREVIEW_ENTRY_POINT_WARNING,
+    LOG_EXPORTER_NAMES_ARG,
+    METRIC_EXPORTER_NAMES_ARG,
+    SAMPLER_ARG,
+    TRACE_EXPORTER_NAMES_ARG,
+)
+from azure.monitor.opentelemetry._diagnostics.diagnostic_logging import (
+    AzureDiagnosticLogging,
+    _ATTACH_FAILURE_CONFIGURATOR,
+    _ATTACH_SUCCESS_CONFIGURATOR,
+)
+from azure.monitor.opentelemetry._diagnostics.status_logger import (
+    AzureStatusLogger,
+)
+
+
+class AzureMonitorConfigurator(_OTelSDKConfigurator):
+    def _configure(self, **kwargs):
+        if not _is_attach_enabled():
+            warn(_PREVIEW_ENTRY_POINT_WARNING)
+        try:
+            if environ.get(OTEL_TRACES_EXPORTER, "").lower().strip() != "none":
+                kwargs.setdefault(TRACE_EXPORTER_NAMES_ARG, ["azure_monitor_opentelemetry_exporter"])
+                try:
+                    sample_rate = float(environ.get("OTEL_TRACES_SAMPLER_ARG", 1.0))
+                except ValueError:
+                    sample_rate = 1.0
+                kwargs.setdefault(SAMPLER_ARG, ApplicationInsightsSampler(sample_rate))
+            if environ.get(OTEL_METRICS_EXPORTER, "").lower().strip() != "none":
+                kwargs.setdefault(METRIC_EXPORTER_NAMES_ARG, ["azure_monitor_opentelemetry_exporter"])
+            if environ.get(OTEL_LOGS_EXPORTER, "").lower().strip() != "none":
+                kwargs.setdefault(LOG_EXPORTER_NAMES_ARG, ["azure_monitor_opentelemetry_exporter"])
+            # As of OTel SDK 1.25.0, exporters passed as kwargs will be added to those specified in env vars.
+            super()._configure(**kwargs)
+            AzureStatusLogger.log_status(True)
+            AzureDiagnosticLogging.info(
+                "Azure Monitor Configurator configured successfully.", _ATTACH_SUCCESS_CONFIGURATOR
+            )
+        except Exception as e:
+            AzureDiagnosticLogging.error(  # pylint: disable=C
+                "Azure Monitor Configurator failed during configuration: %s" % str(e),
+                _ATTACH_FAILURE_CONFIGURATOR,
+            )
+            raise e
diff --git a/.venv/lib/python3.12/site-packages/azure/monitor/opentelemetry/_autoinstrumentation/distro.py b/.venv/lib/python3.12/site-packages/azure/monitor/opentelemetry/_autoinstrumentation/distro.py
new file mode 100644
index 00000000..a8d1a5b8
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/azure/monitor/opentelemetry/_autoinstrumentation/distro.py
@@ -0,0 +1,64 @@
+# -------------------------------------------------------------------------
+# Copyright (c) Microsoft Corporation. All rights reserved.
+# Licensed under the MIT License. See License in the project root for
+# license information.
+# --------------------------------------------------------------------------
+from os import environ
+from warnings import warn
+
+from opentelemetry.instrumentation.distro import (  # type: ignore
+    BaseDistro,
+)
+from opentelemetry.sdk.environment_variables import (
+    _OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED,
+    OTEL_EXPERIMENTAL_RESOURCE_DETECTORS,
+)
+
+from azure.core.settings import settings
+from azure.core.tracing.ext.opentelemetry_span import OpenTelemetrySpan
+from azure.monitor.opentelemetry.exporter._utils import (  # pylint: disable=import-error,no-name-in-module
+    _is_attach_enabled,
+)
+from azure.monitor.opentelemetry._constants import (
+    _AZURE_APP_SERVICE_RESOURCE_DETECTOR_NAME,
+    _AZURE_SDK_INSTRUMENTATION_NAME,
+    _PREVIEW_ENTRY_POINT_WARNING,
+)
+from azure.monitor.opentelemetry._diagnostics.diagnostic_logging import (
+    AzureDiagnosticLogging,
+    _ATTACH_FAILURE_DISTRO,
+    _ATTACH_SUCCESS_DISTRO,
+)
+from azure.monitor.opentelemetry._diagnostics.status_logger import (
+    AzureStatusLogger,
+)
+from azure.monitor.opentelemetry._utils.configurations import (
+    _get_otel_disabled_instrumentations,
+)
+
+
+class AzureMonitorDistro(BaseDistro):
+    def _configure(self, **kwargs) -> None:
+        if not _is_attach_enabled():
+            warn(_PREVIEW_ENTRY_POINT_WARNING)
+        try:
+            _configure_auto_instrumentation()
+            AzureStatusLogger.log_status(True)
+            AzureDiagnosticLogging.info(
+                "Azure Monitor OpenTelemetry Distro configured successfully.", _ATTACH_SUCCESS_DISTRO
+            )
+        except Exception as e:
+            AzureStatusLogger.log_status(False, reason=str(e))
+            AzureDiagnosticLogging.error(  # pylint: disable=C
+                "Azure Monitor OpenTelemetry Distro failed during configuration: %s" % str(e),
+                _ATTACH_FAILURE_DISTRO,
+            )
+            raise e
+
+
+def _configure_auto_instrumentation() -> None:
+    environ.setdefault(_OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED, "true")
+    environ.setdefault(OTEL_EXPERIMENTAL_RESOURCE_DETECTORS, _AZURE_APP_SERVICE_RESOURCE_DETECTOR_NAME)
+    otel_disabled_instrumentations = _get_otel_disabled_instrumentations()
+    if _AZURE_SDK_INSTRUMENTATION_NAME not in otel_disabled_instrumentations:
+        settings.tracing_implementation = OpenTelemetrySpan