Skip to content

feat(core): expose request duration on the response - #11214

Merged
jasonsaayman merged 3 commits into
axios:v1.xfrom
Adityagarg2712:feat/response-duration
Oct 15, 2026
Merged

jasonsaayman merged 3 commits into
axios:v1.xfrom
Adityagarg2712:feat/response-duration

Conversation

@Adityagarg2712

@Adityagarg2712 Adityagarg2712 commented Sep 8, 2026 •

Copy link
Copy Markdown

Summary

Expose elapsed adapter time as response.duration, in milliseconds, on successful responses and on error.response when present. Applications can inspect response latency without installing their own timing interceptors.

const response = await axios.get('/users');
console.log(response.duration);

try {
  await axios.get('/boom');
} catch (error) {
  if (axios.isAxiosError(error) && error.response) {
    console.log(error.response.duration);
  }
}

Linked issue

Related to request/response timing #695 and the metrics item in feature suggestions #6984. This implements a single elapsed-time value; it does not implement per-phase network metrics.

Changes

  • Measure time in the shared dispatch path immediately before invoking the adapter and in its settlement handler, before response transformation. Both response outcomes receive the same measurement.
  • Use Date.now() with two clock reads for a response receiving timing metadata. Clamp backward clock adjustments to zero; forward adjustments can inflate the result.
  • Keep the optional duration?: number property and timing documentation aligned in ESM and CommonJS declarations.
  • Add exact clock-controlled coverage for success/rejection, backward clock changes, exclusion of interceptors/transforms, strict JSON failures, overlapping requests, errors without responses, AbortSignal/CancelToken cancellation, and custom-adapter metadata replacement.
  • Cover buffered and streamed responses through real local HTTP/Fetch adapters, plus XHR and Fetch browser paths. Add matching CJS/ESM consumer type checks.
  • Record the feature in PRE_RELEASE_CHANGELOG.md and deferred release documentation in PRE_RELEASE_DOCS.md.
  • Include current v1.x at 790b2ca8b6d8486dde3ce54cda20990ba91b0831; the PR diff contains no dependency, workflow, version, or generated-bundle changes.

Validation

Validated on 14 October 2026, macOS 27.0.1 ARM64. Source/build/browser/ESM checks used Node 26.8.1 and npm 11.19.0. CommonJS module checks used the supported Node 18.20.8 runtime, npm 10.8.2, and TypeScript 4.9.5; ESM types used TypeScript 5.9.3.

  • npm ci --ignore-scripts: passed. Package manifests and lockfiles are unchanged.
  • npm run lint: passed. Focused ESLint checks for the four changed/new JavaScript test files also passed.
  • npm run build: passed.
  • npm run test:vitest:unit -- tests/unit/core/dispatchRequest.test.js tests/unit/adapters/responseDuration.test.js: 25 passed. Removing the two duration assignments makes 14 timing checks fail; the implementation was restored before the full suite.
  • npm run test:vitest:unit: 1,682 passed, 74 files, with default settings.
  • npx playwright install, followed by npm run test:vitest:browser:headless: 1,053 passed, three existing skips, 81 files across Chromium, Firefox, and WebKit, with default settings.
  • npm pack --json: passed. Installed that tarball into both module packages after npm ci --ignore-scripts, using npm install --no-save --package-lock=false --ignore-scripts <tarball>. Verified installed declarations and dispatch source match the validated files.
  • npm run test:module:cjs: 8 passed against the packed package. Removing the installed CommonJS duration declaration makes the new consumer assertions fail with TS2339; restoring it passes.
  • npm run test:module:esm: 9 passed against the same packed package.
  • Prettier checks for the changed/new JavaScript tests and prerelease records, plus git diff --check: passed. Existing declaration formatting was preserved to avoid unrelated changes.

Latest published head: 36bb79cd1774008f2e557a9c23b111f0c115fe97. GitHub Actions currently requires maintainer authorization for Continuous integration, build reproducibility, Bundle Size, and zizmor. These workflows have not executed for this head. Review/security bots are separate from build and test evidence. The full hosted runtime matrix and smoke suites remain unverified; the results above are local validation.

Compatibility and documentation

Semver: minor. The new enumerable response field requires no migration for built-in-adapter users. Both declaration formats keep it optional so existing custom adapters and manually constructed responses remain type-compatible. Dispatch replaces any custom adapter's existing duration value.

Timing excludes request/response interceptors and transforms. Buffered responses include body reception; streaming responses stop timing when the stream becomes available, and later stream consumption or failure does not update the duration. Adapter work such as connection queuing and redirects is included. This is approximate wall-clock elapsed time, not a monotonic measurement, server-processing time, or a DNS/TCP/TLS/TTFB breakdown. Errors without a response have no duration.

Required documentation is recorded in PRE_RELEASE_DOCS.md for response-schema and error-handling examples, including timing boundaries and guarded error access. README/docs-site updates remain deferred to release preparation. No runtime export or packaging configuration changes are needed; both public declaration formats and packed module suites are covered.

AI assistance was used for review, implementation, tests, and this description; the ai-assisted label is applied.

Checklist

  • Scope, supported target branch, and issue/rationale checked
  • Committed PRE_RELEASE_CHANGELOG.md entry describes the final feature
  • Regression tests and relevant negative/platform cases covered
  • Applicable local checks completed with commands, results, and runtime versions recorded above
  • Deferred release docs and matching ESM/CJS declarations and tests updated
  • Semver impact and custom-adapter metadata behavior stated
  • Final diff checked for scope, security, dependencies, generated artifacts, and test/debug leftovers
  • Latest GitHub Actions authorization status recorded separately from local results and review/security bots

Adds `response.duration`: milliseconds from dispatch to response,
present on successful responses and on `error.response` when the server
replied.

Timing a request currently requires an interceptor pair plus a Map keyed
by config to correlate request and response, which every consumer
reimplements. This is one clock read at the single adapter-agnostic
choke point, so it works identically for the http, xhr and fetch
adapters with no per-adapter code.

`Date.now()` rather than `performance.now()` to match the existing
convention in speedometer.js, throttle.js, cookies.js and
AxiosTransformStream.js. The result is clamped at zero so a backwards
clock adjustment mid-request cannot yield a negative duration.

Additive and opt-out-free: no config, no behaviour change for existing
callers.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread lib/core/dispatchRequest.js Resolved
@greptile-apps

greptile-apps Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] Safe to merge; there are no outstanding blocking issues.

Summary

This change exposes adapter execution time through the optional AxiosResponse.duration property for successful and failed requests. The ESM and CommonJS TypeScript declarations are synchronized, and the public API release metadata is recorded. No new actionable issues remain.

Reviews (2) · Last reviewed commit: "fix(core): complete response duration ty..." · Reviewed by Greptile

Comment thread index.d.ts Resolved
Comment thread index.d.ts Resolved
@jasonsaayman jasonsaayman added commit::feat The PR is related to a feature v1x Version 1 labels Oct 7, 2026
@jasonsaayman
jasonsaayman marked this pull request as ready for review October 9, 2026 16:55
@jasonsaayman
jasonsaayman self-requested a review as a code owner October 9, 2026 16:55
@jasonsaayman jasonsaayman added the ai-assisted This PR was created with or in conjunction with AI label Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted This PR was created with or in conjunction with AI commit::feat The PR is related to a feature v1x Version 1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants