feat: refactor on DBEventLogger to allow for context management#13441
feat: refactor on DBEventLogger to allow for context management#13441
Conversation
Codecov Report
@@ Coverage Diff @@
## master #13441 +/- ##
==========================================
+ Coverage 77.44% 77.61% +0.16%
==========================================
Files 906 906
Lines 45721 46440 +719
Branches 5449 5524 +75
==========================================
+ Hits 35410 36043 +633
- Misses 10184 10270 +86
Partials 127 127
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
…into hugh/event-logger-refactor
tests/event_logger_tests.py
Outdated
| *args: Any, | ||
| **kwargs: Any, | ||
| ): | ||
| self.records.append(kwargs) |
There was a problem hiding this comment.
You might want to store more stuff here, to check that user_id is set, for example.
Another cool thing you might want to do is test that duration is computed correctly. There's a nice Python module called freezegun that allows you to do that. Something like this:
from freezegun import freeze_time
# the first time datetime.now() is called returns 2020-01-14; subsequent calls
# are incremented by 15 seconds
@freeze_time("Jan 14th, 2020", auto_tick_seconds=15)
def test_context_manager_log(self):
...
# change `log()` to also store duration
assert logger.records[0]["duration"] == timedelta(seconds=15)Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
etr2460
left a comment
There was a problem hiding this comment.
double checking that this isn't a breaking change, otherwise this looks like it might solve something that we were doing with a custom logger class up until now
|
@etr2460 it won't be a breaking change since we mostly just moved some of the logic to |
betodealmeida
left a comment
There was a problem hiding this comment.
It looks great, I love that test! I just left a few comments on improving log_with_context.
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
…into hugh/event-logger-refactor
…into hugh/event-logger-refactor
…into hugh/event-logger-refactor
…he#13441) Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>

SUMMARY
Inspired the discussion in #13346 to allow us to log events with context.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TEST PLAN
ADDITIONAL INFORMATION