Commit d4d4dfa
authored
feat: forward duration and traceId to RPC Service Degraded segment events (#29964)
## **Description**
Bumps `@metamask/network-controller` to `^31.0.0` and
`@metamask/controller-utils` to `^12.0.0`, which introduce two new
optional payload fields on `NetworkController:rpcEndpointDegraded` (and
`…ChainDegraded`):
- `duration` (`number | undefined`): the policy execution time in
milliseconds when the request succeeded but exceeded the degraded
threshold. `undefined` when retries were exhausted.
- `traceId` (`string | undefined`): the value of the `X-Trace-Id`
response header from the last request attempt. `undefined` when no
response was received or the header was absent.
This PR threads both fields through `onRpcEndpointDegraded` →
`trackRpcEndpointEvent` and emits them on the `RPC Service Degraded`
Segment event as `duration_ms` and `trace_id` (snake_case, to match
existing properties such as `rpc_method_name` and `retry_reason`). Both
keys are conditionally omitted from the event when the upstream value is
`undefined`, so we don't pollute Segment with empty values.
A `resolutions` entry pins `@metamask/network-controller` to `31.0.0`
repo-wide to dedupe the nested copy that
`@metamask/multichain-network-controller@^3.1.0` still pulls in at
`^30.1.0`. Without this dedupe, TypeScript reports nominal-type
mismatches across packages that consume `NetworkConfiguration` /
`NetworkState` (e.g. `transaction-controller-init.ts`,
`assets-list.ts`). The runtime change in 31.0.0 is additive only (two
optional payload fields), so forcing the multichain dep onto the newer
version is safe.
This enables correlating degraded RPC events with backend traces for
debugging RPC health, and surfaces the actual slow-success latency.
See core PR
[MetaMask/core#8455](MetaMask/core#8455) for the
upstream change.
## **Changelog**
CHANGELOG entry: null
## **Related issues**
Fixes: [WPC-963](https://consensyssoftware.atlassian.net/browse/WPC-963)
## **Manual testing steps**
\`\`\`gherkin
Feature: RPC degraded events carry duration and trace ID
Scenario: slow but successful RPC request emits duration_ms and trace_id
Given a network whose RPC endpoint responds slowly (>5s) and returns an
X-Trace-Id header
And MetaMetrics is enabled
When the user performs an action that issues a JSON-RPC call (e.g.
switching chains, refreshing balances)
Then the outgoing "RPC Service Degraded" Segment event contains numeric
duration_ms
And the event contains trace_id equal to the response's X-Trace-Id
header
Scenario: retries-exhausted RPC request omits duration_ms
Given a network whose RPC endpoint returns retriable errors (e.g. 503)
for every attempt
And MetaMetrics is enabled
When the user performs an action that issues a JSON-RPC call
Then the outgoing "RPC Service Degraded" Segment event omits the
duration_ms property
And the event includes trace_id only if a response with X-Trace-Id was
received before failing
\`\`\`
## **Screenshots/Recordings**
N/A — no UI change.
### **Before**
### **After**
## **Pre-merge author checklist**
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I've included tests if applicable
- [x] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
#### Performance checks (if applicable)
- [ ] I've tested on Android
- [ ] I've tested with a power user scenario
- [ ] I've instrumented key operations with Sentry traces for production
performance metrics
## **Pre-merge reviewer checklist**
- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
[WPC-963]:
https://consensyssoftware.atlassian.net/browse/WPC-963?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Touches network telemetry wiring and analytics event payloads; low
functional impact, but mistakes could break/alter Segment schema and
degrade monitoring quality.
>
> **Overview**
> **RPC degraded telemetry now includes more context.** The
`NetworkController:rpcEndpointDegraded` subscription forwards optional
`duration` and `traceId` into
`onRpcEndpointDegraded`/`trackRpcEndpointEvent`, emitting them to
Segment as `duration_ms` and `trace_id` only when defined, with new unit
tests covering both presence and omission.
>
> **Dependency + fixture updates.** Bumps/pins
`@metamask/network-controller` to `31.0.0` (plus `controller-utils` and
`remote-feature-flag-controller`), adds new default network entries
(Avalanche, Monad Mainnet, MegaETH Mainnet, ZKsync Era) to test
background state and updates Infura API mocks and AddressSelector
sorting expectations accordingly.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
73534c4. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 520fa22 commit d4d4dfa
8 files changed
Lines changed: 169 additions & 43 deletions
File tree
- app
- components/Views/AddressSelector
- core/Engine/controllers
- network-controller
- util/test
- tests/api-mocking/mock-responses
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
| 143 | + | |
143 | 144 | | |
144 | 145 | | |
| 146 | + | |
| 147 | + | |
145 | 148 | | |
146 | 149 | | |
| 150 | + | |
147 | 151 | | |
148 | 152 | | |
149 | 153 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
| 222 | + | |
222 | 223 | | |
223 | 224 | | |
224 | 225 | | |
| 226 | + | |
225 | 227 | | |
226 | 228 | | |
227 | 229 | | |
228 | 230 | | |
229 | 231 | | |
| 232 | + | |
230 | 233 | | |
231 | 234 | | |
232 | 235 | | |
233 | 236 | | |
234 | 237 | | |
| 238 | + | |
235 | 239 | | |
236 | 240 | | |
237 | 241 | | |
| |||
Lines changed: 61 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
322 | 322 | | |
323 | 323 | | |
324 | 324 | | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
325 | 386 | | |
326 | 387 | | |
327 | 388 | | |
| |||
Lines changed: 21 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
| 75 | + | |
74 | 76 | | |
75 | 77 | | |
76 | 78 | | |
| |||
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
| 84 | + | |
| 85 | + | |
82 | 86 | | |
83 | 87 | | |
84 | 88 | | |
85 | 89 | | |
86 | 90 | | |
87 | 91 | | |
| 92 | + | |
88 | 93 | | |
89 | 94 | | |
90 | 95 | | |
91 | 96 | | |
92 | 97 | | |
93 | 98 | | |
| 99 | + | |
94 | 100 | | |
95 | 101 | | |
96 | 102 | | |
97 | 103 | | |
| 104 | + | |
98 | 105 | | |
99 | 106 | | |
100 | 107 | | |
101 | 108 | | |
102 | 109 | | |
103 | 110 | | |
| 111 | + | |
104 | 112 | | |
105 | 113 | | |
106 | 114 | | |
| |||
109 | 117 | | |
110 | 118 | | |
111 | 119 | | |
| 120 | + | |
112 | 121 | | |
113 | 122 | | |
114 | 123 | | |
115 | 124 | | |
116 | 125 | | |
117 | 126 | | |
| 127 | + | |
118 | 128 | | |
119 | 129 | | |
120 | 130 | | |
| |||
127 | 137 | | |
128 | 138 | | |
129 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
130 | 143 | | |
131 | 144 | | |
132 | 145 | | |
| |||
136 | 149 | | |
137 | 150 | | |
138 | 151 | | |
| 152 | + | |
| 153 | + | |
139 | 154 | | |
140 | 155 | | |
141 | 156 | | |
| |||
144 | 159 | | |
145 | 160 | | |
146 | 161 | | |
| 162 | + | |
147 | 163 | | |
148 | 164 | | |
149 | 165 | | |
150 | 166 | | |
151 | 167 | | |
| 168 | + | |
152 | 169 | | |
153 | 170 | | |
154 | 171 | | |
155 | 172 | | |
156 | 173 | | |
| 174 | + | |
157 | 175 | | |
158 | 176 | | |
159 | 177 | | |
160 | 178 | | |
161 | 179 | | |
| 180 | + | |
162 | 181 | | |
163 | 182 | | |
164 | 183 | | |
| |||
188 | 207 | | |
189 | 208 | | |
190 | 209 | | |
| 210 | + | |
| 211 | + | |
191 | 212 | | |
192 | 213 | | |
193 | 214 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
237 | 237 | | |
238 | 238 | | |
239 | 239 | | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
240 | 300 | | |
241 | 301 | | |
242 | 302 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
| 168 | + | |
168 | 169 | | |
169 | 170 | | |
170 | 171 | | |
| |||
247 | 248 | | |
248 | 249 | | |
249 | 250 | | |
250 | | - | |
| 251 | + | |
251 | 252 | | |
252 | 253 | | |
253 | 254 | | |
| |||
299 | 300 | | |
300 | 301 | | |
301 | 302 | | |
302 | | - | |
| 303 | + | |
303 | 304 | | |
304 | 305 | | |
305 | 306 | | |
| |||
317 | 318 | | |
318 | 319 | | |
319 | 320 | | |
320 | | - | |
| 321 | + | |
321 | 322 | | |
322 | 323 | | |
323 | 324 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
69 | 72 | | |
70 | 73 | | |
71 | 74 | | |
| |||
0 commit comments