pyquerytracker 0.1.0__tar.gz → 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. {pyquerytracker-0.1.0/pyquerytracker.egg-info → pyquerytracker-0.1.1}/PKG-INFO +93 -12
  2. pyquerytracker-0.1.1/README.md +143 -0
  3. pyquerytracker-0.1.1/examples/async_example.py +63 -0
  4. pyquerytracker-0.1.1/examples/core/async_usage.py +53 -0
  5. pyquerytracker-0.1.1/examples/core/basic_usage.py +17 -0
  6. pyquerytracker-0.1.1/examples/core/error_handling.py +24 -0
  7. pyquerytracker-0.1.1/examples/core/quick_test.py +39 -0
  8. pyquerytracker-0.1.1/examples/core/with_arguments.py +27 -0
  9. pyquerytracker-0.1.1/examples/core/with_config.py +30 -0
  10. pyquerytracker-0.1.1/examples/exporter/csv_exporter_1.py +36 -0
  11. pyquerytracker-0.1.1/examples/exporter/json_exporter.py +36 -0
  12. pyquerytracker-0.1.1/examples/fastapi_app.py +119 -0
  13. pyquerytracker-0.1.1/examples/test_endpoints.py +73 -0
  14. {pyquerytracker-0.1.0 → pyquerytracker-0.1.1}/pyproject.toml +8 -1
  15. pyquerytracker-0.1.1/pyquerytracker/__init__.py +5 -0
  16. pyquerytracker-0.1.1/pyquerytracker/api.py +72 -0
  17. {pyquerytracker-0.1.0 → pyquerytracker-0.1.1}/pyquerytracker/config.py +26 -10
  18. pyquerytracker-0.1.1/pyquerytracker/core.py +166 -0
  19. pyquerytracker-0.1.1/pyquerytracker/db/models.py +20 -0
  20. pyquerytracker-0.1.1/pyquerytracker/db/session.py +8 -0
  21. pyquerytracker-0.1.1/pyquerytracker/db/writer.py +64 -0
  22. pyquerytracker-0.1.1/pyquerytracker/exporter/__init__.py +0 -0
  23. pyquerytracker-0.1.1/pyquerytracker/exporter/base.py +25 -0
  24. pyquerytracker-0.1.1/pyquerytracker/exporter/csv_exporter.py +52 -0
  25. pyquerytracker-0.1.1/pyquerytracker/exporter/json_exporter.py +47 -0
  26. pyquerytracker-0.1.1/pyquerytracker/exporter/manager.py +32 -0
  27. pyquerytracker-0.1.1/pyquerytracker/main.py +6 -0
  28. pyquerytracker-0.1.1/pyquerytracker/tracker.py +17 -0
  29. pyquerytracker-0.1.1/pyquerytracker/utils/logger.py +18 -0
  30. pyquerytracker-0.1.1/pyquerytracker/websocket.py +33 -0
  31. {pyquerytracker-0.1.0 → pyquerytracker-0.1.1/pyquerytracker.egg-info}/PKG-INFO +93 -12
  32. pyquerytracker-0.1.1/pyquerytracker.egg-info/SOURCES.txt +41 -0
  33. pyquerytracker-0.1.1/pyquerytracker.egg-info/top_level.txt +5 -0
  34. pyquerytracker-0.1.1/tests/exporter/test_json_exporter.py +182 -0
  35. pyquerytracker-0.1.1/tests/test_async_core.py +93 -0
  36. pyquerytracker-0.1.1/tests/test_config.py +40 -0
  37. {pyquerytracker-0.1.0 → pyquerytracker-0.1.1}/tests/test_core.py +9 -9
  38. pyquerytracker-0.1.1/tests/test_dashboard.py +31 -0
  39. pyquerytracker-0.1.1/tests/test_persist.py +9 -0
  40. pyquerytracker-0.1.1/tests/test_websocket.py +58 -0
  41. pyquerytracker-0.1.0/README.md +0 -62
  42. pyquerytracker-0.1.0/pyquerytracker/__init__.py +0 -4
  43. pyquerytracker-0.1.0/pyquerytracker/core.py +0 -102
  44. pyquerytracker-0.1.0/pyquerytracker.egg-info/SOURCES.txt +0 -12
  45. pyquerytracker-0.1.0/pyquerytracker.egg-info/top_level.txt +0 -1
  46. pyquerytracker-0.1.0/tests/test_config.py +0 -44
  47. {pyquerytracker-0.1.0 → pyquerytracker-0.1.1}/LICENSE +0 -0
  48. {pyquerytracker-0.1.0 → pyquerytracker-0.1.1}/pyquerytracker.egg-info/dependency_links.txt +0 -0
  49. {pyquerytracker-0.1.0 → pyquerytracker-0.1.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyquerytracker
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: A lightweight, decorator-based query performance tracking library for Python applications. Monitor and analyze database query performance with ease.
5
5
  Author-email: MuddyHope <daktarisun@gmail.com>
6
6
  License: MIT
@@ -20,6 +20,16 @@ Description-Content-Type: text/markdown
20
20
  License-File: LICENSE
21
21
  Dynamic: license-file
22
22
 
23
+
24
+ ![GitHub Release](https://img.shields.io/github/v/release/MuddyHope/pyquerytracker)
25
+ ![GitHub Issues or Pull Requests](https://img.shields.io/github/issues/MuddyHope/pyquerytracker)
26
+
27
+ ![PyPI - Downloads](https://img.shields.io/pypi/dm/pyquerytracker)
28
+ ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/MuddyHope/pyquerytracker/.github%2Fworkflows%2Fpublish.yml)
29
+ ![GitHub forks](https://img.shields.io/github/forks/MuddyHope/pyquerytracker)
30
+
31
+ ![PyPI - License](https://img.shields.io/pypi/l/pyquerytracker)
32
+
23
33
  # 🐍 pyquerytracker
24
34
 
25
35
  **pyquerytracker** is a lightweight Python utility to **track and analyze database query performance** using simple decorators. It enables developers to gain visibility into SQL execution time, log metadata, and export insights in JSON format — with optional FastAPI integration and scheduled reporting.
@@ -46,8 +56,24 @@ Dynamic: license-file
46
56
  pip install pyquerytracker
47
57
  ```
48
58
 
49
- ## Usage
59
+ ## 🔧 Configuration
60
+
61
+ ```python
62
+ import logging
63
+ from pyquerytracker.config import configure
64
+
65
+ configure(
66
+ slow_log_threshold_ms=200, # Log queries slower than 200ms
67
+ slow_log_level=logging.DEBUG # Use DEBUG level for slow logs
68
+ )
69
+ ```
70
+
71
+ ---
72
+
73
+ ## ⚙️ Usage
74
+
50
75
  ### Basic Usage
76
+
51
77
  ```python
52
78
  import time
53
79
  from pyquerytracker import TrackQuery
@@ -59,26 +85,81 @@ def run_query():
59
85
 
60
86
  run_query()
61
87
  ```
62
- ### Output
63
- ```bash
88
+
89
+ **Output:**
90
+ ```
64
91
  2025-06-14 14:23:00,123 - pyquerytracker - INFO - Function run_query executed successfully in 305.12ms
65
92
  ```
66
93
 
67
- ### With Configure
94
+ ---
95
+
96
+ ### 🧩 Async Support
97
+
98
+ Use the same decorator with `async` functions or class methods:
99
+
100
+ ```python
101
+ import asyncio
102
+ from pyquerytracker import TrackQuery
103
+
104
+ @TrackQuery()
105
+ async def fetch_data():
106
+ await asyncio.sleep(0.2)
107
+ return "fetched"
108
+
109
+ class MyService:
110
+ @TrackQuery()
111
+ async def do_work(self, x, y):
112
+ await asyncio.sleep(0.1)
113
+ return x + y
114
+
115
+ asyncio.run(fetch_data())
68
116
  ```
69
- import logging
117
+
118
+ ---
119
+
120
+ ### 🌐 Run the FastAPI Server
121
+
122
+ To view tracked query logs via REST, WebSocket, or a Web-based dashboard, start the built-in FastAPI server:
123
+
124
+ ```bash
125
+ uvicorn pyquerytracker.api:app --reload
126
+ ```
127
+
128
+ - ⚠️ If your project or file structure is different, replace `pyquerytracker.api` with your own module path, like `<your_project_name>.<your_server(file)_name>`.
129
+
130
+ - Open docs at [http://localhost:8000/docs](http://localhost:8000/docs)
131
+ - **Query Dashboard UI:** [http://localhost:8000/dashboard](http://localhost:8000/dashboard)
132
+ - REST endpoint: `GET /queries`
133
+ - WebSocket stream: `ws://localhost:8000/ws`
134
+
135
+ Then run your tracked functions in another terminal or script:
136
+
137
+ ```python
138
+ @TrackQuery()
139
+ def insert_query():
140
+ time.sleep(0.4)
141
+ return "INSERT INTO users ..."
142
+ ```
143
+
144
+ You’ll see logs live on the server via API/WebSocket.
145
+
146
+ ---
147
+
148
+ ## 📤 Export Logs
149
+
150
+ Enable exporting to CSV or JSON by setting config:
151
+
152
+ ```python
70
153
  from pyquerytracker.config import configure
71
154
 
72
155
  configure(
73
- slow_log_threshold_ms=200, # Log queries slower than 200ms
74
- slow_log_level=logging.DEBUG # Use DEBUG level for slow logs
156
+ export_type="json",
157
+ export_path="./query_logs.json"
75
158
  )
76
159
  ```
77
160
 
78
- ### Output
79
- ```bash
80
- 2025-06-14 14:24:45,456 - pyquerytracker - WARNING - Slow execution: run_query took 501.87ms
81
- ```
161
+ ---
82
162
 
163
+ Let us know how you’re using `pyquerytracker` and feel free to contribute!
83
164
 
84
165
 
@@ -0,0 +1,143 @@
1
+
2
+ ![GitHub Release](https://img.shields.io/github/v/release/MuddyHope/pyquerytracker)
3
+ ![GitHub Issues or Pull Requests](https://img.shields.io/github/issues/MuddyHope/pyquerytracker)
4
+
5
+ ![PyPI - Downloads](https://img.shields.io/pypi/dm/pyquerytracker)
6
+ ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/MuddyHope/pyquerytracker/.github%2Fworkflows%2Fpublish.yml)
7
+ ![GitHub forks](https://img.shields.io/github/forks/MuddyHope/pyquerytracker)
8
+
9
+ ![PyPI - License](https://img.shields.io/pypi/l/pyquerytracker)
10
+
11
+ # 🐍 pyquerytracker
12
+
13
+ **pyquerytracker** is a lightweight Python utility to **track and analyze database query performance** using simple decorators. It enables developers to gain visibility into SQL execution time, log metadata, and export insights in JSON format — with optional FastAPI integration and scheduled reporting.
14
+
15
+ ---
16
+
17
+ ## 🚀 Features
18
+
19
+ - ✅ Easy-to-use decorator to track function execution (e.g., SQL queries)
20
+ - ✅ Capture runtime, function name, args, return values, and more
21
+
22
+ ## TODO Features
23
+ - ✅ Export logs to JSON or CSV
24
+ - ✅ FastAPI integration to expose tracked metrics via REST API
25
+ - ✅ Schedule periodic exports using `APScheduler`
26
+ - ✅ Plug-and-play with any Python database client (SQLAlchemy, psycopg2, etc.)
27
+ - ✅ Modular and extensible design
28
+
29
+ ---
30
+
31
+ ## 📦 Installation
32
+
33
+ ```bash
34
+ pip install pyquerytracker
35
+ ```
36
+
37
+ ## 🔧 Configuration
38
+
39
+ ```python
40
+ import logging
41
+ from pyquerytracker.config import configure
42
+
43
+ configure(
44
+ slow_log_threshold_ms=200, # Log queries slower than 200ms
45
+ slow_log_level=logging.DEBUG # Use DEBUG level for slow logs
46
+ )
47
+ ```
48
+
49
+ ---
50
+
51
+ ## ⚙️ Usage
52
+
53
+ ### Basic Usage
54
+
55
+ ```python
56
+ import time
57
+ from pyquerytracker import TrackQuery
58
+
59
+ @TrackQuery()
60
+ def run_query():
61
+ time.sleep(0.3) # Simulate SQL execution
62
+ return "SELECT * FROM users;"
63
+
64
+ run_query()
65
+ ```
66
+
67
+ **Output:**
68
+ ```
69
+ 2025-06-14 14:23:00,123 - pyquerytracker - INFO - Function run_query executed successfully in 305.12ms
70
+ ```
71
+
72
+ ---
73
+
74
+ ### 🧩 Async Support
75
+
76
+ Use the same decorator with `async` functions or class methods:
77
+
78
+ ```python
79
+ import asyncio
80
+ from pyquerytracker import TrackQuery
81
+
82
+ @TrackQuery()
83
+ async def fetch_data():
84
+ await asyncio.sleep(0.2)
85
+ return "fetched"
86
+
87
+ class MyService:
88
+ @TrackQuery()
89
+ async def do_work(self, x, y):
90
+ await asyncio.sleep(0.1)
91
+ return x + y
92
+
93
+ asyncio.run(fetch_data())
94
+ ```
95
+
96
+ ---
97
+
98
+ ### 🌐 Run the FastAPI Server
99
+
100
+ To view tracked query logs via REST, WebSocket, or a Web-based dashboard, start the built-in FastAPI server:
101
+
102
+ ```bash
103
+ uvicorn pyquerytracker.api:app --reload
104
+ ```
105
+
106
+ - ⚠️ If your project or file structure is different, replace `pyquerytracker.api` with your own module path, like `<your_project_name>.<your_server(file)_name>`.
107
+
108
+ - Open docs at [http://localhost:8000/docs](http://localhost:8000/docs)
109
+ - **Query Dashboard UI:** [http://localhost:8000/dashboard](http://localhost:8000/dashboard)
110
+ - REST endpoint: `GET /queries`
111
+ - WebSocket stream: `ws://localhost:8000/ws`
112
+
113
+ Then run your tracked functions in another terminal or script:
114
+
115
+ ```python
116
+ @TrackQuery()
117
+ def insert_query():
118
+ time.sleep(0.4)
119
+ return "INSERT INTO users ..."
120
+ ```
121
+
122
+ You’ll see logs live on the server via API/WebSocket.
123
+
124
+ ---
125
+
126
+ ## 📤 Export Logs
127
+
128
+ Enable exporting to CSV or JSON by setting config:
129
+
130
+ ```python
131
+ from pyquerytracker.config import configure
132
+
133
+ configure(
134
+ export_type="json",
135
+ export_path="./query_logs.json"
136
+ )
137
+ ```
138
+
139
+ ---
140
+
141
+ Let us know how you’re using `pyquerytracker` and feel free to contribute!
142
+
143
+
@@ -0,0 +1,63 @@
1
+ import asyncio
2
+ import os
3
+ import sys
4
+
5
+ from pyquerytracker import TrackQuery
6
+
7
+ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
8
+
9
+
10
+ # Example 1: Basic async function
11
+ @TrackQuery()
12
+ async def fetch_data():
13
+ await asyncio.sleep(0.2)
14
+ return "fetched data"
15
+
16
+
17
+ # Example 2: Async function with parameters
18
+ @TrackQuery()
19
+ async def compute_sum(a, b):
20
+ await asyncio.sleep(0.1)
21
+ return a + b
22
+
23
+
24
+ # Example 3: Class method async tracking
25
+ class DatabaseService:
26
+ @TrackQuery()
27
+ async def query_users(self):
28
+ await asyncio.sleep(0.3)
29
+ return ["Alice", "Bob", "Charlie"]
30
+
31
+
32
+ # Example 4: Async function that raises an error
33
+ @TrackQuery()
34
+ async def fail_fast():
35
+ await asyncio.sleep(0.05)
36
+ raise RuntimeError("Database failure simulation")
37
+
38
+
39
+ # Example 5: Async function with slow duration to trigger logging thresholds
40
+ @TrackQuery()
41
+ async def slow_operation():
42
+ await asyncio.sleep(0.5)
43
+ return "slow complete"
44
+
45
+
46
+ # Run all examples
47
+ async def main():
48
+ print("Example 1: fetch_data →", await fetch_data())
49
+ print("Example 2: compute_sum(5, 7) →", await compute_sum(5, 7))
50
+
51
+ service = DatabaseService()
52
+ print("Example 3: query_users →", await service.query_users())
53
+
54
+ try:
55
+ await fail_fast()
56
+ except RuntimeError as e:
57
+ print("Example 4: fail_fast → raised:", e)
58
+
59
+ print("Example 5: slow_operation →", await slow_operation())
60
+
61
+
62
+ if __name__ == "__main__":
63
+ asyncio.run(main())
@@ -0,0 +1,53 @@
1
+ import asyncio
2
+ import logging
3
+
4
+ from pyquerytracker import TrackQuery, configure
5
+
6
+ # Configure logging to see the output
7
+ logging.basicConfig(
8
+ level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
9
+ )
10
+
11
+ # Set a low threshold to easily see "slow" logs
12
+ configure(slow_log_threshold_ms=150, slow_log_level=logging.WARNING)
13
+
14
+
15
+ @TrackQuery()
16
+ async def fast_async_query():
17
+ """An async function that executes quickly."""
18
+ await asyncio.sleep(0.1)
19
+ return "Fast async query completed"
20
+
21
+
22
+ @TrackQuery()
23
+ async def slow_async_query():
24
+ """An async function that takes longer to execute."""
25
+ await asyncio.sleep(0.2)
26
+ return "Slow async query completed"
27
+
28
+
29
+ @TrackQuery()
30
+ async def failing_async_query():
31
+ """An async function that raises an error."""
32
+ await asyncio.sleep(0.1)
33
+ raise ConnectionError("Could not connect to async database")
34
+
35
+
36
+ async def main():
37
+ print("--- Testing fast async query (should be INFO log) ---")
38
+ result1 = await fast_async_query()
39
+ print(f"Result: {result1}\n")
40
+
41
+ print("--- Testing slow async query (should be WARNING log) ---")
42
+ result2 = await slow_async_query()
43
+ print(f"Result: {result2}\n")
44
+
45
+ print("--- Testing failing async query (should be ERROR log) ---")
46
+ try:
47
+ await failing_async_query()
48
+ except ConnectionError as e:
49
+ print(f"Caught expected error: {e}\n")
50
+
51
+
52
+ if __name__ == "__main__":
53
+ asyncio.run(main())
@@ -0,0 +1,17 @@
1
+ from pyquerytracker import TrackQuery, configure
2
+
3
+ configure(slow_log_threshold_ms=1000, slow_log_level=20)
4
+
5
+
6
+ @TrackQuery()
7
+ def simple_query():
8
+ """A simple function that simulates a database query."""
9
+ import time
10
+
11
+ time.sleep(0.5) # Simulate some work
12
+ return "Query completed successfully"
13
+
14
+
15
+ if __name__ == "__main__":
16
+ result = simple_query()
17
+ print(f"Result: {result}")
@@ -0,0 +1,24 @@
1
+ import logging
2
+
3
+ from pyquerytracker import TrackQuery
4
+
5
+ # Configure logging
6
+ logging.basicConfig(
7
+ level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
8
+ )
9
+
10
+
11
+ @TrackQuery()
12
+ def failing_query():
13
+ """A function that simulates a failed database query."""
14
+ import time
15
+
16
+ time.sleep(0.3) # Simulate some work
17
+ raise ValueError("Database connection failed")
18
+
19
+
20
+ if __name__ == "__main__":
21
+ try:
22
+ failing_query()
23
+ except ValueError as e:
24
+ print(f"Caught expected error: {e}")
@@ -0,0 +1,39 @@
1
+ import time
2
+
3
+ from pyquerytracker import TrackQuery
4
+
5
+
6
+ @TrackQuery()
7
+ def fast_query():
8
+ """A function that executes quickly."""
9
+ return "Fast query completed"
10
+
11
+
12
+ @TrackQuery()
13
+ def slow_query():
14
+ """A function that takes some time to execute."""
15
+ time.sleep(0.5) # Simulate some work
16
+ return "Slow query completed"
17
+
18
+
19
+ @TrackQuery()
20
+ def failing_query():
21
+ """A function that raises an error."""
22
+ time.sleep(0.2) # Simulate some work
23
+ raise ValueError("Query failed!")
24
+
25
+
26
+ if __name__ == "__main__":
27
+ print("\nTesting fast query:")
28
+ result1 = fast_query()
29
+ print(f"Result: {result1}")
30
+
31
+ print("\nTesting slow query:")
32
+ result2 = slow_query()
33
+ print(f"Result: {result2}")
34
+
35
+ print("\nTesting failing query:")
36
+ try:
37
+ failing_query()
38
+ except ValueError as e:
39
+ print(f"Caught expected error: {e}")
@@ -0,0 +1,27 @@
1
+ import logging
2
+
3
+ from pyquerytracker import TrackQuery
4
+
5
+ # Configure logging
6
+ logging.basicConfig(
7
+ level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
8
+ )
9
+
10
+
11
+ @TrackQuery()
12
+ def complex_query(user_id: int, query_type: str, limit: int = 10):
13
+ """A function that simulates a complex database query with arguments."""
14
+ import time
15
+
16
+ time.sleep(0.2) # Simulate some work
17
+ return f"Retrieved {limit} {query_type} records for user {user_id}"
18
+
19
+
20
+ if __name__ == "__main__":
21
+ # Test with positional arguments
22
+ result1 = complex_query(123, "posts")
23
+ print(f"Result 1: {result1}")
24
+
25
+ # Test with keyword arguments
26
+ result2 = complex_query(user_id=456, query_type="comments", limit=5)
27
+ print(f"Result 2: {result2}")
@@ -0,0 +1,30 @@
1
+ import logging
2
+ import time
3
+
4
+ from pyquerytracker import TrackQuery
5
+ from pyquerytracker.config import configure
6
+
7
+ configure(slow_log_threshold_ms=640, slow_log_level=logging.ERROR)
8
+
9
+
10
+ @TrackQuery()
11
+ def fast_query():
12
+ """A function that executes quickly."""
13
+ return "Fast query completed"
14
+
15
+
16
+ @TrackQuery()
17
+ def slow_query():
18
+ """A function that takes some time to execute."""
19
+ time.sleep(0.3) # Simulate some work
20
+ return "Slow query completed"
21
+
22
+
23
+ if __name__ == "__main__":
24
+ # Test with positional arguments
25
+ result1 = fast_query()
26
+ print(f"Result 1: {result1}")
27
+
28
+ # Test with keyword arguments
29
+ result2 = slow_query()
30
+ print(f"Result 2: {result2}")
@@ -0,0 +1,36 @@
1
+ import os
2
+ import time
3
+
4
+ from pyquerytracker import TrackQuery
5
+ from pyquerytracker.config import ExportType, configure
6
+
7
+ os.makedirs("logs-csv", exist_ok=True)
8
+
9
+ configure(
10
+ slow_log_threshold_ms=50.0,
11
+ slow_log_level=20, # INFO
12
+ export_type=ExportType.CSV,
13
+ export_path="logs-csv/query_logs_2.csv",
14
+ )
15
+
16
+
17
+ @TrackQuery()
18
+ def process_data(x, y):
19
+ time.sleep(8)
20
+ return x + y
21
+
22
+
23
+ @TrackQuery()
24
+ def failing_task():
25
+ time.sleep(0.03) # not slow
26
+ raise RuntimeError("This failed intentionally.")
27
+
28
+
29
+ # Run tasks
30
+ print("Result:", process_data(5, 7))
31
+ print("Result:", process_data(1, 2))
32
+
33
+ try:
34
+ failing_task()
35
+ except Exception:
36
+ pass
@@ -0,0 +1,36 @@
1
+ import os
2
+ import time
3
+
4
+ from pyquerytracker import TrackQuery
5
+ from pyquerytracker.config import ExportType, configure
6
+
7
+ os.makedirs("logs-json", exist_ok=True)
8
+
9
+ configure(
10
+ slow_log_threshold_ms=50.0,
11
+ slow_log_level=20, # INFO
12
+ export_type=ExportType.JSON,
13
+ export_path="logs-json/query_logs.json",
14
+ )
15
+
16
+
17
+ @TrackQuery()
18
+ def process_data(x, y):
19
+ time.sleep(0.08) # triggers slow log
20
+ return x + y
21
+
22
+
23
+ @TrackQuery()
24
+ def failing_task():
25
+ time.sleep(0.03) # not slow
26
+ raise RuntimeError("This failed intentionally.")
27
+
28
+
29
+ # Run tasks
30
+ print("Result:", process_data(5, 7))
31
+ print("Result:", process_data(1, 2))
32
+
33
+ try:
34
+ failing_task()
35
+ except Exception:
36
+ pass