Skip to content

Add X-Incognia-Latency header with previous request latency#100

Open
alangalvino wants to merge 2 commits intomainfrom
lib/metrics
Open

Add X-Incognia-Latency header with previous request latency#100
alangalvino wants to merge 2 commits intomainfrom
lib/metrics

Conversation

@alangalvino
Copy link
Copy Markdown

@alangalvino alangalvino commented Apr 15, 2026

Summary

  • send X-Incognia-Latency on API calls using the latency from the previous successful request
  • keep the first request without the header and update the stored latency after each call
  • add tests covering signup-to-signup, payment-to-feedback, and feedback-to-signup flows

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 API call latency and sends it on subsequent Incognia API requests via the X-Incognia-Latency header.

Changes:

  • Introduces latency measurement/state in IncogniaAPI and injects X-Incognia-Latency on requests after the first successful call.
  • Routes existing API POST calls through a new internal __post wrapper to centralize header injection + timing.
  • Adds unit tests for first-call/second-call and cross-endpoint sequencing, resetting the singleton per test.

Reviewed changes

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

File Description
incognia/api.py Adds latency tracking and a centralized POST wrapper that conditionally adds X-Incognia-Latency.
tests/test_api.py Adds tests asserting presence/absence of the latency header across request flows and resets singleton state in setUp.

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

Comment thread incognia/api.py Outdated
Comment thread tests/test_api.py
Copy link
Copy Markdown
Contributor

@figueredo figueredo left a comment

Choose a reason for hiding this comment

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

Deixando aprovado, mas vale ver as sugestão do Copilot

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 last successful request duration and sends it on subsequent API calls via the X-Incognia-Latency header, with tests validating cross-endpoint flows and ensuring the first call omits the header.

Changes:

  • Introduce a latency-tracking __post wrapper in IncogniaAPI that injects X-Incognia-Latency from the previous successful call.
  • Route existing API methods through __post (including consistently passing params=None where applicable).
  • Add unit tests for first-call behavior and for latency propagation across signup/payment/feedback sequences.

Reviewed changes

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

File Description
incognia/api.py Adds latency state + mutex and wraps POST requests to attach X-Incognia-Latency based on the previous call.
tests/test_api.py Adds tests asserting header absence on first call and presence on subsequent calls; updates expectations to include params=None.

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

Comment thread incognia/api.py Outdated
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.

3 participants