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(sdk): resolve hyphen/underscore instrumentor name spellings in disabled_instrumentors (#1451)

Tai An0bfab723adbd
diff --git a/sdk/python/src/openlit/_instrumentors.py b/sdk/python/src/openlit/_instrumentors.py
index c151f006..2b1f034a 100644
--- a/sdk/python/src/openlit/_instrumentors.py
+++ b/sdk/python/src/openlit/_instrumentors.py
@@ -83,20 +83,27 @@ MODULE_NAME_MAP = {
}
# Common aliases so users can pass intuitive names (e.g. "aiohttp") that
-# differ from the canonical hyphenated keys used in MODULE_NAME_MAP.
+# differ from the canonical keys used in MODULE_NAME_MAP. The canonical keys
+# are not consistent about hyphens versus underscores, so every key whose
+# separator can be written the other way is aliased in both directions.
INSTRUMENTOR_ALIASES = {
"aiohttp": "aiohttp-client",
+ "aiohttp_client": "aiohttp-client",
"oci_genai": "oci",
"oci-genai": "oci",
"openai_agents": "openai-agents",
"google_ai_studio": "google-ai-studio",
"azure_ai_inference": "azure-ai-inference",
"reka": "reka-api",
+ "reka_api": "reka-api",
"browser_use": "browser-use",
"google_adk": "google-adk",
"claude_agent_sdk": "claude-agent-sdk",
"agent_framework": "agent-framework",
"psycopg_pool": "psycopg-pool",
+ "llamaindex": "llama_index",
+ "llama-index": "llama_index",
+ "pydantic-ai": "pydantic_ai",
"http": "httpx",
"digitalocean": "pydo",
"digital_ocean": "pydo",
diff --git a/sdk/python/tests/test_instrumentor_names.py b/sdk/python/tests/test_instrumentor_names.py
new file mode 100644
index 00000000..de1c842c
--- /dev/null
+++ b/sdk/python/tests/test_instrumentor_names.py
@@ -0,0 +1,74 @@
+# pylint: disable=missing-function-docstring, missing-class-docstring
+"""
+Unit tests for instrumentor name resolution.
+
+``disabled_instrumentors`` is matched against the canonical keys of
+``MODULE_NAME_MAP``, and those keys are not consistent about hyphens versus
+underscores (``llama_index`` and ``pydantic_ai`` next to ``openai-agents`` and
+``google-ai-studio``). A name that does not resolve is dropped with a warning
+and the instrumentation stays enabled, so every spelling a user can reasonably
+reach for has to normalize onto its canonical key.
+"""
+
+from openlit._instrumentors import (
+ INSTRUMENTOR_ALIASES,
+ INSTRUMENTOR_MAP,
+ MODULE_NAME_MAP,
+ normalize_instrumentor_name,
+ normalize_instrumentor_names,
+)
+
+
+def test_both_separator_spellings_resolve():
+ """Every canonical key is reachable with hyphens or with underscores."""
+ unreachable = []
+ for key in MODULE_NAME_MAP:
+ for spelling in (key.replace("-", "_"), key.replace("_", "-")):
+ if normalize_instrumentor_name(spelling) not in MODULE_NAME_MAP:
+ unreachable.append(spelling)
+ assert not unreachable, f"unreachable spellings: {unreachable}"
+
+
+def test_aliases_point_at_canonical_keys():
+ """No alias may resolve to a name that is not itself an instrumentor."""
+ dangling = [
+ (alias, target)
+ for alias, target in INSTRUMENTOR_ALIASES.items()
+ if target not in MODULE_NAME_MAP
+ ]
+ assert not dangling, f"aliases pointing nowhere: {dangling}"
+
+
+def test_aliases_do_not_shadow_canonical_keys():
+ shadowing = [alias for alias in INSTRUMENTOR_ALIASES if alias in MODULE_NAME_MAP]
+ assert not shadowing, f"aliases shadowing canonical keys: {shadowing}"
+
+
+def test_the_two_registries_agree():
+ assert sorted(MODULE_NAME_MAP) == sorted(INSTRUMENTOR_MAP)
+
+
+def test_distribution_names_resolve():
+ """The names the instrumentations declare in ``_instruments`` resolve."""
+ assert normalize_instrumentor_name("llama-index") == "llama_index"
+ assert normalize_instrumentor_name("pydantic-ai") == "pydantic_ai"
+ assert normalize_instrumentor_name("reka-api") == "reka-api"
+
+
+def test_module_directory_names_resolve():
+ """``openlit/instrumentation/llamaindex`` is also spelled without a separator."""
+ assert normalize_instrumentor_name("llamaindex") == "llama_index"
+
+
+def test_normalization_is_case_insensitive():
+ assert normalize_instrumentor_names(["LlamaIndex", "Pydantic-AI", "AIOHTTP"]) == [
+ "llama_index",
+ "pydantic_ai",
+ "aiohttp-client",
+ ]
+
+
+def test_unknown_names_pass_through_unchanged():
+ assert normalize_instrumentor_name("not-an-instrumentor") == "not-an-instrumentor"
+ assert not normalize_instrumentor_names([])
+ assert not normalize_instrumentor_names(None)