Skip to content

Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.

[Fix]: Failed to instrument azure-ai-inference: No module named 'azure' error when it should be skipped (#420)

patcher99d78ba44c580
diff --git a/sdk/python/pyproject.toml b/sdk/python/pyproject.toml
index c24c782a..cb29a695 100644
--- a/sdk/python/pyproject.toml
+++ b/sdk/python/pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "openlit"
-version = "1.22.2"
+version = "1.22.3"
description = "OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications and GPUs, facilitating the integration of observability into your GenAI-driven projects"
authors = ["OpenLIT"]
repository = "https://github.com/openlit/openlit/tree/main/openlit/python"
diff --git a/sdk/python/src/openlit/__init__.py b/sdk/python/src/openlit/__init__.py
index 732d98aa..0d94ab31 100644
--- a/sdk/python/src/openlit/__init__.py
+++ b/sdk/python/src/openlit/__init__.py
@@ -130,6 +130,13 @@ class OpenlitConfig:
cls.trace_content = trace_content
cls.disable_metrics = disable_metrics
+def module_exists(module_name):
+ """Check if nested modules exist, addressing the dot notation issue."""
+ parts = module_name.split(".")
+ for i in range(1, len(parts) + 1):
+ if find_spec(".".join(parts[:i])) is None:
+ return False
+ return True
def instrument_if_available(
instrumentor_name,
@@ -150,7 +157,7 @@ def instrument_if_available(
return
try:
- if find_spec(module_name) is not None:
+ if module_exists(module_name):
instrumentor_instance.instrument(
environment=config.environment,
application_name=config.application_name,
@@ -167,6 +174,7 @@ def instrument_if_available(
except Exception as e:
logger.error("Failed to instrument %s: %s", instrumentor_name, e)
+
def init(environment="default", application_name="default", tracer=None, otlp_endpoint=None,
otlp_headers=None, disable_batch=False, trace_content=True, disabled_instrumentors=None,
meter=None, disable_metrics=False, pricing_json=None, collect_gpu_stats=False):