Repository navigation
feat: http-client-requests-method - #804
caroolcanelas2 wants to merge 3 commits into
Conversation
Query metrics reads Attributes['method'] from the map this middleware emits. Without the key, http_client_requests_total comes back empty. Co-authored-by: Cursor <cursoragent@cursor.com>
http_client_requests_total must keep the outbound verb. The handler base map stays without method so that key is not overwritten. Co-authored-by: Cursor <cursoragent@cursor.com>
The outbound method is recorded on the client counter and the inbound handler map stays unchanged. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
🟢 Approval recommended
The narrow change matches the documented contract, preserves inbound behavior, stays within the attribute limit, and has focused regression coverage.
No open issues 🎉
What changed in this PR
Adds the outbound HTTP method to http_client_requests_total and related client metrics, enabling Query metrics to group and filter newly emitted samples by verb.
Changes:
- Records
ctx.config.method, defaulting togetwhen missing or empty. - Adds regression coverage for success, failure, retries, defaults, and exclusion of the inbound method.
- Updates the metrics catalog and documents the emission contract and rollout requirements.
| File | Description |
|---|---|
src/service/worker/runtime/http/middlewares/timings.test.ts |
Verifies inbound metrics do not include method. |
src/HttpClient/middlewares/metrics.ts |
Adds the outbound method to shared client attributes. |
src/HttpClient/middlewares/metrics.test.ts |
Tests method recording and fallback behavior. |
specs/http-client-requests-method.md |
Documents requirements, scope, and rollout behavior. |
docs/METRICS_CATALOG.md |
Lists method on the four affected instruments. |
Review effort: Balanced
DK Review — Audit SummaryVerdict: ✅ CLEAN
Only BLOCK and RESTRICT findings anchored to a changed line are commented inline on the diff. The 3 findings below open no review thread. Scenarios evaluated: feature-flags, general-review, quality-ratchet 📋 Findings (3)SUGGEST
DK Review v1.0.0 | To dismiss a finding: reply |

What is the purpose of this pull request?
Record the outbound HTTP verb on
http_client_requests_total, so o11y Query metrics can readAttributes['method']for calls emitted after this version of@vtex/apiis deployed.What problem is this solving?
XTNSNS-2594, split out of XTNSNS-2507.
Attributes['method']is an empty string becausemetricsMiddlewarenever writes the key. The Read API only projects the map already stored in ClickHouse. The other four Query metrics symptoms stay in the Read API subtasks and are not part of this change.How should this be manually tested?
yarn test src/HttpClient/middlewares/metrics.test.ts src/service/worker/runtime/http/middlewares/timings.test.ts --watchman=false@vtex/apiis published and an app runs it, Query metrics onhttp_client_requests_totalshould returnget,post,put,patch,delete, orheadinAttributes['method'].Screenshots or example usage
No UI change.
Types of changes
Summary
metricsMiddlewareaddsmethodfromctx.config.method, falling back togetwhen the value is missing or empty.HttpClient.getdoes not set the field. The same map feeds the latency histogram,http_client_cache_total, andhttp_client_requests_retried_total. The metrics catalog listsmethodon those rows.timings.tsis unchanged. Its inbound base attributes still omitmethod, so a handler that receivedGETdoes not overwrite an outboundpost.Tests
metricsMiddlewarerecordsposton success,putwhen the call fails,patchon the retry counter, andgetwhenmethodis omitted or empty.timingslocks the inbound base map andhttp_handler_requests_totalso they do not carrymethodeven when the incoming request method isGET.ClickHouse before the change
ClickHouse after the change
Assumptions
HttpClient(post,put, …). TheGET/POSTstrings from the local ClickHouse simulation were written by that simulation.methodandstatus: error. It does not requirestatus_codeto switch to the rejected response whenctx.response.statusis already set.Follow-ups
methodbrings the client custom attribute map to 6 keys, and to 7 whencache_stateorretry_countis also set. That is the current cap inDiagnosticsMetrics.Spec
specs/http-client-requests-method.mdMade with Cursor