feat: Add telemetry interop mode for FastMCP#4046
Conversation
0d4639f to
79382bf
Compare
|
tl;dr: A pre-existing test, (Edited to reflect latest CI failure — this replaces the earlier ruff format report.) Root Cause: In # line 1128 — None is falsy → fastmcp_refresh_token stays None
if refresh_jti and refresh_expires_in:
fastmcp_refresh_token = self.jwt_issuer.issue_refresh_token(...)
# line 1159 — fastmcp_refresh_token is None → no metadata stored
if fastmcp_refresh_token and refresh_expires_in:
await self._refresh_token_store.put(...)
Fix: In the # Before (PR's new code — broken):
if raw_value == 0:
refresh_expires_in = None
refresh_token_expires_at = None
# After (correct):
if raw_value == 0:
refresh_expires_in = self._fallback_refresh_token_expiry_seconds
refresh_token_expires_at = time.time() + refresh_expires_inLog excerptReproduced across all failing matrix jobs (Python 3.10 / 3.13 on ubuntu and windows, plus lowest-direct-deps). Related files
|
fe9b3fb to
118a5a6
Compare
118a5a6 to
0a34ebd
Compare
🤖 Generated with Claude Code Co-Authored-By: Claude Opus 4.7 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3d90859a4d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…4046) 🤖 Generated with Claude Code Co-Authored-By: Claude Opus 4.7 <[email protected]>
Add propagation_only telemetry mode and suppress_fastmcp_telemetry() context manager. When active, FastMCP skips its own MCP spans but still propagates trace context through _meta so an external instrumentation layer can own the span hierarchy. Scope reduced from ~370 lines to ~130 lines by removing: - Client-side _meta injection on list_* calls - Custom _initialize_session_with_meta() using private SDK APIs - Ambient span context ASGI scope plumbing - Complex Link-based parent context resolution Co-authored-by: Copilot <[email protected]>
🤖 Generated with Claude Code Co-Authored-By: Claude Opus 4.7 <[email protected]>
…4046) 🤖 Generated with Claude Code Co-Authored-By: Claude Opus 4.7 <[email protected]>
…ion marker 🤖 Generated with Claude Code Co-Authored-By: Claude Opus 4.7 <[email protected]>
ac2e964 to
289150f
Compare
When another instrumentation layer (e.g. an MCP-aware OTEL library or a service mesh) already owns the MCP span hierarchy, FastMCP's native spans become duplicates. This PR adds a minimal interop mode that lets users suppress FastMCP's own spans while keeping trace context propagation through
_metafully functional.The setting (
FASTMCP_TELEMETRY_MODE) controls all three span helpers (server_span,client_span,delegate_span). Inpropagation_onlymode, incoming trace context from_metais still extracted and attached so downstream user spans inherit the correct parent—only FastMCP's own MCP operation spans are skipped.This follows the universal pattern seen in FastAPI, Django, Flask, Sentry, and gRPC instrumentation libraries: extract→attach→skip span→detach.