Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/anubis/server/session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ defmodule Anubis.Server.Session do
tool_name = get_in(request, ["params", "name"])

:telemetry.span(
Telemetry.event_server_tool_call(),
[:anubis_mcp | Telemetry.event_server_tool_call()],
%{tool: tool_name},
fn -> {module.handle_request(request, frame), %{tool: tool_name}} end
)
Expand Down
25 changes: 25 additions & 0 deletions test/anubis/server/session_async_dispatch_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,31 @@ defmodule Anubis.Server.SessionAsyncDispatchTest do
end
end

describe "tool_call telemetry" do
test "stop event fires under the :anubis_mcp namespace", %{session: session} do
handler_id = "test-tool-call-telemetry-#{System.unique_integer([:positive])}"
test_pid = self()

:telemetry.attach(
handler_id,
[:anubis_mcp, :server, :tool_call, :stop],
fn _event, measurements, metadata, _config ->
send(test_pid, {:tool_call_stop, measurements, metadata})
end,
nil
)

on_exit(fn -> :telemetry.detach(handler_id) end)

ctx = with_test_pid()
req = tool_call_request("echo", %{"value" => "telemetry"}, "tel-1")
assert {:ok, _encoded} = GenServer.call(session, {:mcp_request, req, ctx}, 5_000)

assert_receive {:tool_call_stop, %{duration: duration}, %{tool: "echo"}}, 1_000
assert is_integer(duration) and duration >= 0
end
end

defp start_async_session(_ctx) do
session_id = "async-#{System.unique_integer([:positive])}"
transport_name = Registry.transport_name(AsyncDispatchTestServer, StubTransport)
Expand Down
Loading