feat: add duration and traceId to degraded events#8455
Open
cryptodev-2s wants to merge 16 commits intomainfrom
Open
feat: add duration and traceId to degraded events#8455cryptodev-2s wants to merge 16 commits intomainfrom
duration and traceId to degraded events#8455cryptodev-2s wants to merge 16 commits intomainfrom
Conversation
e3eb1a1 to
c4cf4d5
Compare
Contributor
Author
|
@metamaskbot publish-preview |
Contributor
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
When a request succeeds but takes longer than degradedThreshold,
the onDegraded event now emits { duration } instead of void, so
higher layers can include the actual request duration in their
event payloads.
…stable onDegraded type
…ugh RpcServiceChain
b9ab587 to
e8262db
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 4fd9aed. Configure here.
Contributor
Author
|
@metamaskbot publish-preview |
Contributor
Author
|
@metamaskbot publish-preview |
Contributor
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
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.

Explanation
RPC endpoint degraded events (
NetworkController:rpcEndpointDegradedandNetworkController:rpcEndpointChainDegraded) now include two new optional properties in their payloads:duration(number | undefined): The policy execution time in milliseconds when the request succeeded but was slow (i.e., exceeded thedegradedThreshold). This isundefinedwhen the degraded event was caused by retries being exhausted.traceId(string | undefined): The value of thex-trace-idresponse header from the last request attempt. This enables correlating degraded events with backend traces for debugging RPC health issues. It isundefinedwhen no response was received or the header was not present.How it works
The
durationvalue originates from Cockatiel'sretryPolicy.onSuccesscallback increateServicePolicy. Previously, it was only used for the threshold comparison — now it is also emitted as part of the degraded event data.The
traceIdis captured inRpcServicefromresponse.headers.get('x-trace-id')in the samefinallyblock that tracksrpcMethodName, ensuring it reflects the last completed request attempt (handling concurrent request race conditions correctly).Both values are threaded through the event chain:
createServicePolicy→RpcService→RpcServiceChain→createNetworkClient→ messenger events.Breaking change
The
RpcServiceRequestabletype'sonDegradedlistener signature now includesduration?: numberandtraceId?: stringin its data parameter. Implementors of this interface will need to accept the new fields in theironDegradedcallback signature.References
Checklist
Note
Medium Risk
Introduces a breaking change to
ServicePolicy.onDegraded/RpcServiceRequestable.onDegradedpayload shapes and threads new fields through RPC service event plumbing, which may break downstream listeners and requires careful validation of event data in degraded scenarios.Overview
Degraded service events now include timing metadata:
createServicePolicyemits{ duration }for slow-success cases (removing the previousvoidpayload) while still emittingFailureReasonwhen retries are exhausted.Network degraded messenger events (
NetworkController:rpcEndpointDegradedandNetworkController:rpcEndpointChainDegraded) now include optionaldurationandtraceIdfields, withtraceIdcaptured from thex-trace-idresponse header inRpcServiceand forwarded throughRpcServiceChain/createNetworkClient.Updates types, changelogs, and tests to reflect the new payload shapes (breaking for
onDegradedlistener signatures).Reviewed by Cursor Bugbot for commit e61cfa5. Bugbot is set up for automated code reviews on this repo. Configure here.