feat(jsonrpc): implement middleware pipeline and OpenTelemetry tracing#3922
Merged
feat(jsonrpc): implement middleware pipeline and OpenTelemetry tracing#3922
Conversation
- 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`.
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.
Introduce a robust, JSON-RPC 2.0 compliant middleware pipeline and
execution engine, alongside OpenTelemetry instrumentation.
The new pipeline relies on a chain of
JsonRpcInvokerinstances. Tostrictly 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 leveragesOptional<JsonRpcResponse>to properly handle fire-and-forgetNotifications (which require no response) versus standard Method Calls.
Key additions:
JsonRpcInvoker: Middleware interface usingOptional<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 targetservices. 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
ErrorDetailto accurately report spansuccess or failure, logging semantic attributes like
rpc.methodandrpc.jsonrpc.request_id.fix #3921 #3920