graphile / crystal

🔮 Graphile's Crystal Monorepo; home to Grafast, PostGraphile, pg-introspection, pg-sql2 and much more!
https://graphile.org/
Other
12.58k stars 569 forks source link

Add Optional Server-Timing Headers to the HTTP Response #1579

Open miles-po opened 2 years ago

miles-po commented 2 years ago

Feature description

When debugging latency issues, it can be difficult to distinguish between geographical latency, VPN latency, and the individual GraphQL query latency itself.

Motivating example

It was really hard to determine proper socket timeout values for tests vs live vs development, knowing how long the actual queries took rather than figuring out how much my VPN and cross-country latency were adding to the total.

Server metrics such as AWS X-Ray, AppDynamics, etc. allow for aggregate timing over a longer period with analytics, but lacking per-request timing lengthens the feedback cycle for developers calling the GraphQL endpoint.

If Server-Timing headers were added to responses when enabled, it would effectively solve this problem. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server-Timing

For example on a GraphQL query like this:

query HeroNameAndFriends {
  hero {
    name
    friends {
      name
    }
  }
}

mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) {
  createReview(episode: $ep, review: $review) {
    stars
    commentary
  }
}
Server-Timing: HeroNameAndFriends;dur=1.4, CreateReviewForEpisode;dur=5.7

Supporting development

I [tick all that apply]:

benjie commented 8 months ago

This could be added post v5.0.0 if needed.