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] async MCP span naming by populating method metadata (#890)

artur-nohup30fd2820b2b5
diff --git a/sdk/python/pyproject.toml b/sdk/python/pyproject.toml
index c156f7b2..487aae14 100644
--- a/sdk/python/pyproject.toml
+++ b/sdk/python/pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "openlit"
-version = "1.35.7"
+version = "1.35.8"
description = "OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications and GPUs, facilitating the integration of observability into your GenAI-driven projects"
authors = ["OpenLIT"]
license = "Apache-2.0"
diff --git a/sdk/python/src/openlit/instrumentation/mcp/async_mcp.py b/sdk/python/src/openlit/instrumentation/mcp/async_mcp.py
index 2461d263..92098e44 100644
--- a/sdk/python/src/openlit/instrumentation/mcp/async_mcp.py
+++ b/sdk/python/src/openlit/instrumentation/mcp/async_mcp.py
@@ -18,6 +18,25 @@ from openlit.instrumentation.mcp.utils import (
)
+def _populate_context_method_metadata(ctx, wrapped, endpoint):
+ """Populate method metadata on the instrumentation context for span naming."""
+
+ try:
+ if hasattr(wrapped, "__name__"):
+ ctx._wrapped_function_name = wrapped.__name__ # cached for method detection
+ except Exception:
+ pass
+
+ if endpoint:
+ parts = endpoint.split()
+ if len(parts) >= 2:
+ ctx._endpoint_method = parts[1]
+ elif parts:
+ ctx._endpoint_method = parts[0]
+ else:
+ ctx._endpoint_method = "unknown"
+
+
def async_mcp_wrap(
gen_ai_endpoint,
version,
@@ -51,6 +70,7 @@ def async_mcp_wrap(
):
span_kind = SpanKind.SERVER
+
# Create instrumentation context for caching expensive operations
ctx = MCPInstrumentationContext(
instance=instance,
@@ -63,6 +83,8 @@ def async_mcp_wrap(
capture_message_content=capture_message_content,
)
+ _populate_context_method_metadata(ctx, wrapped, gen_ai_endpoint)
+
# Create span name following OpenLIT convention: "{operation_type} {operation_name}"
operation_type = (
gen_ai_endpoint.split()[0] if " " in gen_ai_endpoint else "mcp"
@@ -222,6 +244,8 @@ def async_mcp_tool_call_wrap(
capture_message_content=capture_message_content,
)
+ _populate_context_method_metadata(ctx, wrapped, gen_ai_endpoint)
+
# Enhanced span name for tool calls
span_name = ctx.get_enhanced_span_name("tool")
@@ -332,6 +356,8 @@ def async_mcp_resource_wrap(
capture_message_content=capture_message_content,
)
+ _populate_context_method_metadata(ctx, wrapped, gen_ai_endpoint)
+
# Enhanced span name for resource operations
span_name = ctx.get_enhanced_span_name("resource")
@@ -441,6 +467,8 @@ def async_mcp_transport_wrap(
capture_message_content=capture_message_content,
)
+ _populate_context_method_metadata(ctx, wrapped, gen_ai_endpoint)
+
# Transport-specific span name following operation_type operation_name convention
transport_type = ctx.transport_type
span_name = f"mcp transport {transport_type}"