Skip to content

Proposed updates to the reply.getResponseTime() documentation  #4575

@tomanagle

Description

@tomanagle

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

The .getResponseTime() portion of the docs states Note that unless this function is called in the [onResponse hook](https://www.fastify.io/docs/latest/Reference/Hooks#onresponse) it will always return 0.. However, I've tested it with onResponse and it doesn't return 0, it returns a very small number. This behaviour is expected, but is not represented in the docs.

I'd also like to add something to say that if you'd like to record route response time metrics, this is the place to do it.

What are your thoughts?

Reference: https://www.fastify.io/docs/latest/Reference/Reply/#getresponsetime

Motivation

Improve documentation & show how easy it is to response response time reliably (much harder in other frameworks)

Example

Note: To measure the ensure request response time, the function must be called in a onResponse hook. Calling the function in other hooks will result in 0 or very low numbers that do not represent the entire request response time.

If you would like to record request response time metrics, the result of .getResponseTime() in a onResponse hook is the recommended way to do that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions