Skip to content

Commit 3f852df

Browse files
committed
put model_validate in a try-except block.
1 parent 96c6c10 commit 3f852df

File tree

1 file changed

+7
-6
lines changed
  • instrumentation-genai/opentelemetry-instrumentation-mcp/src/opentelemetry/instrumentation/mcp

1 file changed

+7
-6
lines changed

instrumentation-genai/opentelemetry-instrumentation-mcp/src/opentelemetry/instrumentation/mcp/instrumentor.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,9 @@ class McpInstrumentor(BaseInstrumentor):
4242
See: https://modelcontextprotocol.io/overview
4343
"""
4444

45-
# Span naming constants
4645
_CLIENT_SPAN_NAME = "mcp.client"
4746
_SERVER_SPAN_NAME = "mcp.server"
48-
49-
# HTTP header for session tracking
5047
_SESSION_ID_HEADER = "mcp-session-id"
51-
52-
# Instrumentation targets
5348
_SESSION_MODULE = "mcp.shared.session"
5449
_SERVER_MODULE = "mcp.server.lowlevel.server"
5550

@@ -193,7 +188,13 @@ async def async_wrapper() -> Any:
193188
)
194189

195190
# Reconstruct message with injected context
196-
modified_message = message.model_validate(message_json)
191+
try:
192+
modified_message = message.model_validate(message_json)
193+
except Exception as exc: # pylint: disable=broad-exception-caught
194+
_LOG.warning(
195+
"Failed to reconstruct message for tracing: %s", exc
196+
)
197+
return await wrapped(*args, **kwargs)
197198
new_args = (modified_message,) + args[1:]
198199

199200
try:

0 commit comments

Comments
 (0)