Select FastMCP client span by component key in session-id telemetry tests (SDK v2)

This commit is contained in:
Jeremiah Lowin 2026-07-05 21:36:59 -04:00
commit e1f3f1ca3b
No known key found for this signature in database

View file

@ -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,