-
-
Notifications
You must be signed in to change notification settings - Fork 101
Add response time to logs in talker_dio_logger #351
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
Conversation
The changes add the response time to the logs generated by the talker_dio_logger package. The `DioRequestLog` and `DioErrorLog` classes now display the response time.
Reviewer's Guide by SourceryThis pull request adds the response time to the logs generated by the Sequence diagram for logging HTTP response timesequenceDiagram
participant DI as Dio Interceptor
participant TDL as TalkerDioLogger
participant API as API Server
participant DL as DioRequestLog/DioErrorLog
TDL->>DI: onRequest(options, handler)
activate DI
DI->>DI: options.extra[kDioLogsTimeStampKey] = DateTime.now()
DI->>API: Request
deactivate DI
API-->>DI: Response
activate DI
DI->>DI: _getResponseTime(options)
DI->>DL: Log data with response time
deactivate DI
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @troyanskiy - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider adding a configuration option to disable the response time logging, as it might not be desired in all cases.
- The
_getResponseTime
function returns -1 if the timestamp is missing; consider logging this case for debugging purposes.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @troyanskiy !
Thank you for this contribution 👍🏻
I will be happy to merge it, but please fix the review issues first
var msg = '[$title] [${dioException.requestOptions.method}] $message'; | ||
final responseTime = _getResponseTime(dioException.requestOptions); | ||
|
||
var msg = '[$title] [${dioException.requestOptions.method}] [$responseTime ms] $message'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add new field print Response Time
for TalkerDioLoggerSettings
with false default value
|
||
const kDioLogsTimeStampKey = '_talker_dio_logger_ts_'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make kDioLogsTimeStampKey
static const field of TalkerDioLogger
Exporting global constants is not good practice for dart packages
/// | ||
/// Get response time | ||
/// | ||
int _getResponseTime(RequestOptions options) { | ||
final triggerTime = options.extra[kDioLogsTimeStampKey]; | ||
|
||
if (triggerTime is int) { | ||
return DateTime.now().millisecondsSinceEpoch - triggerTime; | ||
} | ||
|
||
return -1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make the return value nullable integer (int?)
If triggerTime does not exist in the options.extra
field, return null
- Response time moved to main message body line `Time: <TIME> ms` - Constant moved to static
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #351 +/- ##
==========================================
+ Coverage 98.45% 98.49% +0.03%
==========================================
Files 28 3 -25
Lines 583 133 -450
==========================================
- Hits 574 131 -443
+ Misses 9 2 -7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Hello @troyanskiy ! |
Adds the ability to include response time in Dio logs, controlled by the `printResponseTime` setting. - Adds tests for response time inclusion in logs based on the `printResponseTime` setting. - Updates `DioResponseLog` and `DioErrorLog` to include response time if the `printResponseTime` setting is true. - Adds response time in format "Time: X ms" to log message.
The changes add the response time to the logs generated by the talker_dio_logger package.
The
DioRequestLog
andDioErrorLog
classes now display the response time.Example:
[http-response] [GET] [137 ms] https://domain.com/api/users
Summary by Sourcery
Add response time tracking to Dio logger logs
New Features:
Enhancements: