Json Exporter (#9)#36
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a JSON exporter for query tracking logs along with associated tests and configuration updates. Key changes include:
- Integration of a new JsonExporter class in pyquerytracker for threadsafe JSON log exporting.
- Addition of tests in tests/exporter/test_json_exporter.py to validate the JSON export functionality.
- Updates in core and configuration files to support JSON export and provide a usage example.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_core.py | Duplicate import statements need cleanup. |
| tests/exporter/test_json_exporter.py | New test coverage for JSON exporting functionality. |
| pyquerytracker/exporter/json_exporter.py | New exporter class for JSON logs. |
| pyquerytracker/exporter/init.py | Updated export package initialization. |
| pyquerytracker/core.py | Integrated JsonExporter but missing log_data initialization. |
| pyquerytracker/config.py | Updated configuration docstrings for export settings. |
| examples/exporter/json_exporter.py | Usage example for JSON exporter functionality. |
Comments suppressed due to low confidence (2)
tests/test_core.py:5
- Duplicate import of 'pytest' detected; consider removing the redundant import to maintain cleaner code.
import pytest
pyquerytracker/core.py:79
- The variable 'log_data' is referenced in the successful execution branch but has not been initialized; consider defining 'log_data' with the appropriate log details before its use.
extra=log_data,
|
oh god what did i break now |
|
MuddyHope please help, I thought I did it the right way |
|
Did you cherry pick my commit also? Also where they in the same order??
…On Mon, Jun 16, 2025 at 5:48 PM Paper ***@***.***> wrote:
*ArchooD2* left a comment (MuddyHope/pyquerytracker#36)
<#36 (comment)>
MuddyHope please help, I thought I did it the right way
—
Reply to this email directly, view it on GitHub
<#36 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOKTJ263APJ5VWKDBH7GE4L3D5QUPAVCNFSM6AAAAAB7OXEIOOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSNZYGU4DAMRTGQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
|
I believe so for both cases. I can try again, but I think I did it right. 1 moment |
bf2d19c to
c3d2ff3
Compare
|
refixing this and then reopening. |
…for JSON log export
Moved json export testing to new file Changed get_config patch in test to configure() call No longer writes to os.path.dirname(None) (disables JsonExporter class entirely if None path supplied) File writes should now be thread-safe Changed export logic to use pathlib rather than os
…ort (requested changes)
|
Okay, should be fixed. |
|
Thanks I’ll test it out. Have you considered the output to be in json
format? (Not just in pytest)
Try running the example/exporter file.
…On Mon, Jun 16, 2025 at 6:04 PM Paper ***@***.***> wrote:
Reopened #36 <#36>.
—
Reply to this email directly, view it on GitHub
<#36 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOKTJ26W7O7IH4CF6JMY7B33D5SR5AVCNFSM6AAAAAB7OXEIOOVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJYGE4DANRZHA4TGMY>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
|
Found a minor bug with the json formatting |
| with _lock, self._path.open("a", encoding="utf-8") as f: | ||
| json.dump(record, f) | ||
| f.write("\n") | ||
| f.write(",\n") |
There was a problem hiding this comment.
The opening and closing brackets ?? []??
There was a problem hiding this comment.
resolved in newest push
…log export. Holy hell, making this use json instead of jsonl was tougher than expected.
|
This is embarassing... Edit: ARE YOU KIDDING ME LINT |
|
Hi @ArchooD2, can you run the examples/exporter/json_exporter.py function once, the slow_function and faulty_function aren't appearing on the json file. Can you add these also in the test module? |
|
I'm gonna have words to say with an inanimate github workflow (just the linter one, I'm mildly displeased with how often I'm forgetting to lint) |
|
Seems to be working fine now @MuddyHope |
|
Hi @ArchooD2, the previous commits were good, you changed after my last review. Also, the flush wasn't so necessary. If you can remove it, that would be good. When I ran the examples/exporter files twice, there was no appending. Which should be necessary to save these queries. Take your time and test it once, with the existing features and submit the PR. Hoping to see these changes. |
a331b2c to
5e51a84
Compare
…ssary instantiation
…es. Added sanity checks in test_json_exporter for use in the event of further bugs.
https://stackoverflow.com/questions/73568036/flake8-line-break-before-binary-operator-how-to-fix-it I may suggest a change to "extend-ignore," but for now I've simply remedied the problem at hand.
MuddyHope
left a comment
There was a problem hiding this comment.
If you are using AI to write your code, it's better to give it more context; try using Cursor.
| def flush_exported_logs() -> None: | ||
| """ | ||
| Manually flushes the JSON exporter buffer to disk. | ||
| Useful for ensuring log data is written in real-time or during tests. |
There was a problem hiding this comment.
Can all these exporter functions be put in utils?
| @@ -1,3 +1,5 @@ | |||
| # pyquerytracker/config.py | |||
| import logging | ||
| import pytest | ||
| from pyquerytracker import TrackQuery | ||
| import pytest |
There was a problem hiding this comment.
Fixed, accidentally added. ✔️
| self.config.slow_log_level, | ||
| f"{class_name}.{func.__name__} -> Slow execution: took %.2fms", | ||
| "%s.%s → Slow execution: took %.2fms", | ||
| class_name or "<module>", |
| class _ExporterManager: | ||
| _instance: JsonExporter | None = None | ||
|
|
||
| @classmethod |
There was a problem hiding this comment.
Check if it's really necessary, if it's really necessary, keep it in the utils file.
…tions to pyquerytracker/exporter/utils.py for better structure
…p whitespace in utils.py
|
Use |
|
|
|
Realized way too late that my choco wasn't installed properly, so make just didn't work... |
|
Are you done? @ArchooD2 ? |
|
Updated the flush logic so that it appends! I should note that examples/exporter/json_exporter.py is much faster |
|
I think I'm done, if there aren't any more problems. |
|
Hi @ArchooD2, there are some conflicts. There was a change made to the framework of the exporter class. |
|
I'm sorry, but how many changes to main have there been while I was working on this? FOLLOWUP, WHY DID IT NEVER TELL ME |
…??????????????????????????????????????????????????????????????????????????????? (Fix pytest fail and linting issues.)
|
Hi @ArchooD2, can you make the changes in accordance with the framework. It should be easier now with having a JsonExporter as there is already a BaseClass that have you to inherit from. |
|
@ArchooD2, are you working on this? |
|
I think I need to take some time away for a little, please allow anyone else to make a json exporter for this project 👍 |
Should be right, cherrypicked as I was expected to, I hope. (#9)