stacklok / stacklok/toolhive

OTEL: Add error.type and rpc.response.status_code for JSON-RPC errors

Open
#3,765 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement go telemetry
Dominant language
Go
Stars
2.2k
Forks
300
Avg merge
1d 15h
Merged PRs (30d)
184

Description

Context

Identified during the OTEL MCP semantic conventions review (parent issue: #3399). These two spec gaps are related and should be implemented together since they both require the same response-body inspection approach.

error.type missing for JSON-RPC errors and tool_error

Severity: Medium
File: pkg/telemetry/middleware.go

error.type is only set for HTTP 5xx errors. JSON-RPC errors returned in HTTP 200 responses (e.g., -32601) and failed CallToolResult ("tool_error") are invisible to telemetry. This is acknowledged in code comments as future work.

Fix: Would require response body inspection — buffer/parse the JSON-RPC response to detect error codes and tool errors.

Missing rpc.response.status_code for JSON-RPC errors

Severity: Low
File: pkg/telemetry/middleware.go

The OTEL RPC semconv includes rpc.response.status_code for error responses. Would require response body parsing for JSON-RPC error codes.

Fix: Same response-body inspection approach as above.

Implementation considerations

  • Both require intercepting/buffering the response body before it's written to the client
  • Need to parse JSON-RPC response to extract error codes (e.g., -32601, -32602) and CallToolResult.isError
  • A tee-style response writer that captures the body while still streaming to the client would be one approach
  • Should set error.type to the JSON-RPC error code string (e.g., "-32601") or "tool_error" for failed tool calls
  • High value for observability — currently JSON-RPC errors are invisible in telemetry since they return HTTP 200

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading pkg/telemetry/middleware.go, including its comments and current response handling. Trace how JSON-RPC responses and CallToolResult values can be inspected, then verify that JSON-RPC error codes and tool_error produce error.type and rpc.response.status_code while HTTP 200 responses remain available to clients.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
observability
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.