about summary refs log tree commit diff
path: root/.venv/lib/python3.12/site-packages/azure/monitor/opentelemetry/_autoinstrumentation/configurator.py
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/configurator.py
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/configurator.py')
-rw-r--r--.venv/lib/python3.12/site-packages/azure/monitor/opentelemetry/_autoinstrumentation/configurator.py68
1 files changed, 68 insertions, 0 deletions
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