feat(otel): emit a span for every governed MCP tool call - #68
Merged
Conversation
The OTel export covered model calls but not tool calls, so allowlist
blocks and approval denials were invisible in the trace backend — the
governance that matters most for side-effecting tools left no trace next
to the model spans.
Emit one span per governed tools/call (`execute_tool {tool}`) carrying the
standard `gen_ai.tool.name` plus `riskkernel.tool.side_effect` and
`riskkernel.tool.status` (approved | blocked | denied | timeout). A refused
call gets an error span status so it stands out. This reuses the gateway's
existing per-call timing/audit path and the same nil-safe tracer the proxy
uses, so it stays a no-op when no OTLP endpoint is configured — still zero
telemetry by default.
Align api/v1/otel-genai.md to what's actually emitted: the standard
`gen_ai.tool.name` replaces the never-emitted `riskkernel.tool.name`, and
`riskkernel.tool.status` is documented; add the example and a dashboard
query for tool refusals.
Merged
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.
Emit a span for every governed MCP tool call
The OTel export gave me one span per model call, but nothing for tool calls — so when the gateway blocked a tool by the allowlist or denied it at the approval gate, that decision was invisible in my trace backend. The governance that matters most (side-effecting tools) was the part leaving no trace.
This emits one span per governed
tools/call, right next to the model-call spans:execute_tool {tool}(e.g.execute_tool write_file)gen_ai.tool.name— the standard GenAI attribute for the toolriskkernel.tool.side_effect— the classified side effect (empty = read-only)riskkernel.tool.status—approved,blocked(allowlist),denied(approval gate), ortimeoutA refused call carries an error span status so it stands out in the trace UI. It reuses the gateway's existing per-call timing + SQLite audit path and the same nil-safe tracer the proxy already uses, so it's a no-op when no OTLP endpoint is configured — still zero telemetry by default.
Contract
Aligned
api/v1/otel-genai.mdto what's actually emitted: the standardgen_ai.tool.namereplaces the placeholderriskkernel.tool.name(documented but never emitted), andriskkernel.tool.statusis now pinned. Documented theexecute_toolspan shape.Verified
go test ./...green. New unit tests assert the span + attributes at the tracer (TestRecordToolCall_Attributes) and through the gateway (TestToolCallEmitsSpan).execute_tool search→approvedexecute_tool delete_everything→blockedexecute_tool write_file→denied(side_effecttool)