From e1f3f1ca3b8a658e7a407a900cd2e5eaafffd6c7 Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Sun, 5 Jul 2026 21:36:59 -0400 Subject: [PATCH] Select FastMCP client span by component key in session-id telemetry tests (SDK v2) --- tests/client/telemetry/test_client_tracing.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/client/telemetry/test_client_tracing.py b/tests/client/telemetry/test_client_tracing.py index 54c4c08f3..908fcc789 100644 --- a/tests/client/telemetry/test_client_tracing.py +++ b/tests/client/telemetry/test_client_tracing.py @@ -571,13 +571,16 @@ class TestSessionIdOnSpans: spans = trace_exporter.get_finished_spans() - # Find client-side span + # Find the FastMCP client-side span. SDK v2 emits its own native OTel + # spans (also lacking `fastmcp.server.name`), so select on the + # `fastmcp.component.key` attribute that only our client_span sets. client_span = next( ( s for s in spans if s.name == "tools/call echo" and s.attributes is not None + and "fastmcp.component.key" in s.attributes and "fastmcp.server.name" not in s.attributes ), None, @@ -635,13 +638,15 @@ class TestSessionIdOnSpans: spans = trace_exporter.get_finished_spans() - # Find both spans + # Find both spans. Select the FastMCP client span on + # `fastmcp.component.key` to avoid matching SDK v2's native OTel span. client_span = next( ( s for s in spans if s.name == "tools/call echo" and s.attributes is not None + and "fastmcp.component.key" in s.attributes and "fastmcp.server.name" not in s.attributes ), None,