Skip to content

Send previous request latency via X-Incognia-Latency#43

Open
alangalvino wants to merge 1 commit intomainfrom
lib-latency
Open

Send previous request latency via X-Incognia-Latency#43
alangalvino wants to merge 1 commit intomainfrom
lib-latency

Conversation

@alangalvino
Copy link
Copy Markdown

Summary

  • track the latency of the last successful API request in the shared client
  • send that value in the X-Incognia-Latency header on subsequent requests without changing request bodies
  • add specs covering first-call omission, cross-request propagation, and overriding a caller-provided latency header

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds client-side tracking of the previous successful request latency and forwards it on subsequent requests via the X-Incognia-Latency header, with accompanying specs to validate omission on first call and propagation/override behavior.

Changes:

  • Introduce X-Incognia-Latency header injection based on the prior successful request’s measured latency.
  • Add thread-safe storage of the last request latency in the singleton client.
  • Add RSpec coverage for first-call omission, cross-endpoint propagation, and overriding caller-provided latency.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
lib/incognia_api/client.rb Track/store last request latency and inject it into subsequent request headers.
spec/client_spec.rb Add specs validating latency header behavior across calls/endpoints and override semantics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/incognia_api/client.rb Outdated
Comment thread lib/incognia_api/client.rb Outdated
Comment thread spec/client_spec.rb Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread spec/client_spec.rb Outdated
 Track the latency of the last successful API call in the shared client and
 send it in the X-Incognia-Latency header on subsequent requests.

 This aligns the Ruby SDK with the new metrics contract without changing
 request bodies, and adds specs covering first-call omission and propagation
 across requests.                                                                                                                             ▄
Comment on lines +25 to +28

if (latency = last_latency_ms)
request_headers[LATENCY_HEADER] = latency.to_s
end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wdyt?

Suggested change
if (latency = last_latency_ms)
request_headers[LATENCY_HEADER] = latency.to_s
end
request_headers[LATENCY_HEADER] = last_latency_ms&.to_s

And when sending the request, use a compact

response = connection.send(method, endpoint, json_data, request_headers.compact)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants