🐛 Bug Report: MCP uninstrument() keeps tracing and reinstrumentation duplicates spans
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 3/5
- 見積もり時間
- 半日
- 初心者へのやさしさ
- 76/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- python
調査の方向性
Start in packages/opentelemetry-instrumentation-mcp, reading the MCP instrumentor lifecycle, FastMCPInstrumentor.uninstrument(), and the fixture in tests/conftest.py. Run the supplied reproducer to confirm enabled → disabled → re-enabled span counts. Add a regression test covering completed sessions and ensure uninstrument removes all wrappers, while re-instrumenting produces the original span count without duplication.
索引モデルが issue の本文から書いたものです。
説明
Which component is this bug for?
All Packages (MCP is missing from the dropdown). Affected package: opentelemetry-instrumentation-mcp.
📜 Description
After McpInstrumentor().uninstrument(), completed MCP calls continue exporting spans even though is_instrumented_by_opentelemetry is False. Re-enabling instrumentation adds another tracing layer.
Reproduced against source commit 8d9c93f, using an in-memory FastMCP server. Each tool call executes once and returns the correct result. No cancellation or active-session teardown is needed.
👟 Reproduction steps
- Instrument MCP, open a client session, call a tool, and close the session.
- Uninstrument and repeat the call in another completed session.
- Re-instrument and repeat again, inspecting exported spans after each step.
Tested reproducer and environment setup
From the repository root at the commit above, create an environment:
python3.11 -m venv /tmp/openllmetry-mcp-repro
/tmp/openllmetry-mcp-repro/bin/python -m pip install \
fastmcp==2.14.3 mcp==1.26.0 wrapt==1.17.3 \
opentelemetry-sdk==1.42.1 opentelemetry-instrumentation==0.63b1
Save this as /tmp/repro_mcp_uninstrument.py:
import asyncio
from fastmcp import Client, FastMCP
from opentelemetry.instrumentation.mcp import McpInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
async def main():
exporter = InMemorySpanExporter()
provider = TracerProvider()
provider.add_span_processor(SimpleSpanProcessor(exporter))
instrumentor = McpInstrumentor()
instrumentor.instrument(tracer_provider=provider)
server = FastMCP("lifecycle-repro")
executions = 0
@server.tool()
async def add_numbers(a: int, b: int) -> int:
nonlocal executions
executions += 1
return a + b
client = Client(server)
observations = {}
try:
for phase in ("enabled", "disabled", "re-enabled"):
if phase == "disabled":
instrumentor.uninstrument()
elif phase == "re-enabled":
instrumentor.instrument(tracer_provider=provider)
exporter.clear()
before = executions
async with client:
result = await client.call_tool("add_numbers", {"a": 5, "b": 3})
assert result.content[0].text == "8"
spans = exporter.get_finished_spans()
counts = (len(spans), sum(s.name == "add_numbers.tool" for s in spans))
observations[phase] = counts
assert executions - before == 1
print(f"{phase}: enabled={instrumentor.is_instrumented_by_opentelemetry}, "
f"spans={counts[0]}, tool_spans={counts[1]}", flush=True)
finally:
instrumentor.uninstrument()
provider.shutdown()
assert observations["disabled"] == (0, 0), observations
assert observations["re-enabled"] == observations["enabled"], observations
asyncio.run(main())
Run against the unchanged source:
PYTHONDONTWRITEBYTECODE=1 \
PYTHONPATH="$PWD/packages/opentelemetry-instrumentation-mcp:$PWD/packages/opentelemetry-semantic-conventions-ai" \
/tmp/openllmetry-mcp-repro/bin/python /tmp/repro_mcp_uninstrument.py
This imports the instrumentation and project semantic conventions from the checkout, not the released wheel. The dependencies satisfy the source manifests; the older lockfile was not regenerated or used for this environment.
👍 Expected behavior
Disabled calls export no MCP spans. Re-enabling restores the original tracing behavior without multiplying spans or changing application behavior.
👎 Actual Behavior with Screenshots
| Phase | Reports enabled | Total spans | Tool spans |
|---|---|---|---|
| Enabled | True | 6 | 2 |
| Disabled | False | 6 | 2 |
| Re-enabled | True | 11 | 4 |
The script fails its disabled-span assertion. The two initial tool spans are legitimate client/server spans; the re-enabled call duplicates them. Another cycle produces 16 total spans and six tool spans.
🤖 Python Version
3.11.15, macOS on Apple Silicon. Dependency versions are in the setup above.
📃 Provide any additional context for the Bug.
_uninstrument() currently unwraps only the stdio transports; FastMCPInstrumentor.uninstrument() is a no-op. The test fixture acknowledges wrapper stacking and avoids it through session-scoped instrumentation. The author of #4103 explicitly deferred the deeper fix.
Controls produced zero spans without instrumentation and stable counts without toggling. Fresh clients reproduced the failure. The existing in-memory client/session tests still pass (24 tests).
@doronkopit5, may I take this on and submit a focused fix with regression tests? Is anyone already working on it? My initial scope would be the completed-session enable → disable → re-enable sequence above.
👀 Have you spent some time to check if this bug has been raised before?
- I checked and didn't find similar issue
This is a previously acknowledged bug. I found no dedicated MCP uninstrumentation issue or implementation in the public issues, PRs, and related discussions I checked. Please point me to existing work if I missed it.
Are you willing to submit PR?
Yes I am willing to submit a PR!
- 主要言語
- Python
- スター
- 7.5k
- フォーク
- 1.2k
- 平均マージ
- 1日 23時間
- マージ済み PR(30日)
- 3
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
traceloop/openllmetry のほかの issue
-
🐛 Bug Report: OpenAI Responses: with_raw_response.create() raises when the body can't be parsed, though the uninstrumented call returns対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンbug python
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
traceloop/openllmetry#4717 ·
メンテナーはふだん 1 日以内に返信
-
🐛 Bug Report: Incomplete cache token migration after #4243 breaks Bedrock and Groq instrumentation対応中かも @Quantum-Enigma-dot が 21 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
traceloop/openllmetry#4665 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
🐛 Bug Report: OpenAI instrumentation drops gen_ai.usage.reasoning_tokens on streamed chat completions対応中かも @jayfeng7 が 23 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
traceloop/openllmetry#4660 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Bug Report: Failed dataset deletes still remove local rows and columns対応中かも @inchang-ing が 32 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
traceloop/openllmetry#4630 ·
メンテナーはふだん 1 日以内に返信
-
🐛 Bug Report: LiteLLM instrumentation does not record seed, stop, frequency_penalty, presence_penalty対応中かも @shantam77 が 38 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
traceloop/openllmetry#4598 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
traceloop/openllmetry の issue をすべて見る
似ている issue
-
CI flake: test-windows times out spawning Node in tests/test_antigravity_node_hooks.py (develop red)オープンarea/ci P2
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 2 日以内に返信
-
benchmark
難易度 1/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
mozilla-ai/cq#601 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信