Skip to content

feat(jsonrpc): implement middleware pipeline and OpenTelemetry tracing#3922

Merged
jknack merged 9 commits intomainfrom
oteljsonrpc
Apr 23, 2026
Merged

feat(jsonrpc): implement middleware pipeline and OpenTelemetry tracing#3922
jknack merged 9 commits intomainfrom
oteljsonrpc

Conversation

@jknack
Copy link
Copy Markdown
Member

@jknack jknack commented Apr 23, 2026

Introduce a robust, JSON-RPC 2.0 compliant middleware pipeline and
execution engine, alongside OpenTelemetry instrumentation.

The new pipeline relies on a chain of JsonRpcInvoker instances. To
strictly adhere to the JSON-RPC 2.0 spec, the pipeline suppresses raw
exceptions, wrapping all application and protocol errors (e.g., Parse
Error, Invalid Request) inside a JsonRpcResponse. It also leverages
Optional<JsonRpcResponse> to properly handle fire-and-forget
Notifications (which require no response) versus standard Method Calls.

Key additions:

  • JsonRpcInvoker: Middleware interface using Optional<JsonRpcResponse>
    to support both standard calls and notifications. Enforces an exception-
    safe architecture by requiring errors to be returned in the response.
  • JsonRpcExecutor: The terminal invoker that routes requests to target
    services. Acts as the ultimate safety net, safely translating uncaught
    exceptions and protocol faults into valid JSON-RPC error objects.
  • OtelJsonRcpTracing: OpenTelemetry middleware that traces RPC spans.
    It integrates perfectly with the exception-less pipeline by inspecting
    the response envelope for ErrorDetail to accurately report span
    success or failure, logging semantic attributes like rpc.method and
    rpc.jsonrpc.request_id.

fix #3921 #3920

jknack added 7 commits April 18, 2026 20:10
- fix lifecycle of request
- add tracing
Introduce a robust, JSON-RPC 2.0 compliant middleware pipeline and
execution engine, alongside OpenTelemetry instrumentation.

The new pipeline relies on a chain of `JsonRpcInvoker` instances. To
strictly adhere to the JSON-RPC 2.0 spec, the pipeline suppresses raw
exceptions, wrapping all application and protocol errors (e.g., Parse
Error, Invalid Request) inside a `JsonRpcResponse`. It also leverages
`Optional<JsonRpcResponse>` to properly handle fire-and-forget
Notifications (which require no response) versus standard Method Calls.

Key additions:
- `JsonRpcInvoker`: Middleware interface using `Optional<JsonRpcResponse>`
  to support both standard calls and notifications. Enforces an exception-
  safe architecture by requiring errors to be returned in the response.
- `JsonRpcExecutor`: The terminal invoker that routes requests to target
  services. Acts as the ultimate safety net, safely translating uncaught
  exceptions and protocol faults into valid JSON-RPC error objects.
- `OtelJsonRcpTracing`: OpenTelemetry middleware that traces RPC spans.
  It integrates perfectly with the exception-less pipeline by inspecting
  the response envelope for `ErrorDetail` to accurately report span
  success or failure, logging semantic attributes like `rpc.method` and
  `rpc.jsonrpc.request_id`.
@jknack jknack merged commit 27f6406 into main Apr 23, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

json-rpc: add json-rpc invoker

1 participant