feat: add optional Langfuse tracing for MCP tool calls#37
Open
feat: add optional Langfuse tracing for MCP tool calls#37
Conversation
Add observability to the mcp-acp server via Langfuse integration. Every MCP tool call produces a trace with tool name, filtered args, duration, and success/error status. HTTP requests to the ACP public API appear as nested child spans with method, path, and status code. Tracing is opt-in and silently no-ops when unconfigured: - Reads LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, LANGFUSE_BASE_URL - MCP_ACP_TRACING_ENABLED env var (default: true) serves as kill switch - SDK init failures are caught and logged, never break tool execution - tracing.py: Langfuse v3 SDK client singleton, trace_tool_call and trace_http_request async context managers, no-op fallbacks, lifecycle - server.py: wrap call_tool() dispatch in trace_tool_call, flush on exit - client.py: wrap _request() and _request_text() in trace_http_request - settings.py: add missing _acpctl_config_path() (pre-existing bug fix) - test_tracing.py: 25 unit tests covering all tracing paths - scripts/test_tracing_e2e.py: e2e test against live ACP cluster Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
MCP_ACP_TRACING_ENABLED=falseChanges
pyproject.tomllangfuse>=2.0.0dependencysrc/mcp_acp/tracing.pytrace_tool_call+trace_http_requestasync context managers, no-op fallbacks, flush/shutdown lifecyclesrc/mcp_acp/server.pycall_tool()intrace_tool_call, flush tracing on shutdownsrc/mcp_acp/client.py_request()and_request_text()intrace_http_requestsrc/mcp_acp/settings.py_acpctl_config_path()(pre-existing bug fix)tests/test_tracing.pyscripts/test_tracing_e2e.pyConfiguration
Opt-in via environment variables (Langfuse SDK reads these automatically):
Kill switch:
MCP_ACP_TRACING_ENABLED=falsedisables tracing even with credentials present.Test plan
uv run pytest tests/test_tracing.py)uv run pytest tests/)🤖 Generated with Claude Code