-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[TT-7273] fix: Correct analytics timestamp to request start time #7274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
umyonghyun
wants to merge
1
commit into
TykTechnologies:master
from
umyonghyun:fix/analytics-timestamp-accuracy
Open
[TT-7273] fix: Correct analytics timestamp to request start time #7274
umyonghyun
wants to merge
1
commit into
TykTechnologies:master
from
umyonghyun:fix/analytics-timestamp-accuracy
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The analytics timestamp was previously recorded after the upstream response was received. This commit corrects the behavior to use the request's arrival time.
@umyonghyun
umyonghyun
changed the title
(削除) fix: Correct analytics timestamp to request start time (削除ここまで)
(追記) [TT-7273]fix: Correct analytics timestamp to request start time (追記ここまで)
Aug 6, 2025
@umyonghyun
umyonghyun
changed the title
(削除) [TT-7273]fix: Correct analytics timestamp to request start time (削除ここまで)
(追記) [TT-7273] fix: Correct analytics timestamp to request start time (追記ここまで)
Aug 6, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This pull request corrects an inconsistency where the analytics
TimeStamp
was recorded after the upstream response was received, rather than at the time of the initial request. This resulted in the timestamp reflecting the request's completion time, which could be misleading for analytics and did not align with the behavior implied in the official documentation.By leveraging the request context, this change ensures the
TimeStamp
accurately reflects the moment the request first arrived at the gateway.Changes Made:
ctx/ctx.go
: IntroducedRequestReceivedTime
context key and helper functions (SetRequestReceivedTime
,GetRequestReceivedTime
).gateway/reverse_proxy.go
: InServeHTTP
, the request's arrival time is now captured and stored in the request context.gateway/handler_success.go
: TheRecordHit
function now retrieves the timestamp from the context instead of callingtime.Now()
.Related Issue
#7273
Motivation and Context
The primary motivation for this change is to improve the accuracy and clarity of analytics data. The previous implementation recorded a timestamp that was skewed by the upstream processing time, making it difficult to analyze true request arrival patterns. This fix aligns the
TimeStamp
field with its expected meaning – the moment the request is received by the gateway – which is crucial for accurate logging, monitoring, and debugging.How This Has Been Tested
The changes have been tested by implementing the logic and verifying its flow through the relevant middleware components. The modifications are localized and leverage the standard request context for passing data, minimizing side effects.
reverse_proxy.go
.handler_success.go
before being written to the analytics record.The code builds successfully, and a full run of the project's test suite is recommended to ensure no regressions have been introduced.
Types of changes
Checklist