Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/tabular_tracing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:::pytabular.tabular_tracing
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ nav:
- best_practice_analyzer: best_practice_analyzer.md
- pbi_helper: pbi_helper.md
- logic_utils: logic_utils.md
- Running Traces: tabular_tracing.md
- Documenting Model: document.md
- Contributing: CONTRIBUTING.md

Expand Down
38 changes: 30 additions & 8 deletions pytabular/tabular_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@

It also includes some pre built traces to make life easier.
Feel free to build your own.

Example:
```python title="Monitor Queries"
import pytabular as p
import logging as l
model = p.Tabular(CONNECTION_STR)
query_trace = p.QueryMonitor(model)
query_trace.start() # (1)

###

p.logger.setLevel(l.DEBUG) # (2)

###

query_trace.stop()
query_trace.drop() # (3)
```

1. You will now start to see query traces on your model get outputed to your console.
2. If you want to see the FULL query then set logging to DEBUG.
3. You can drop on your own, or will get dropped on script exit.
"""
import logging
import random
Expand Down Expand Up @@ -118,8 +140,8 @@ def update(self) -> None:
"""Runs on init. Syncs with Server.

Returns:
None: Returns None.
Unless unsuccessful then it will return the error from Server.
None: Returns None.
Unless unsuccessful then it will return the error from Server.
"""
logger.info(f"Updating {self.Name} in {self.tabular_class.Server.Name}")
if self.tabular_class.Server.Connected is False:
Expand All @@ -131,8 +153,8 @@ def start(self) -> None:
"""Call when you want to start the trace.

Returns:
None: Returns None.
Unless unsuccessful then it will return the error from Server.
None: Returns None.
Unless unsuccessful then it will return the error from Server.
"""
logger.info(f"Starting {self.Name} in {self.tabular_class.Server.Name}")
return self.Trace.Start()
Expand All @@ -141,8 +163,8 @@ def stop(self) -> None:
"""Call when you want to stop the trace.

Returns:
None: Returns None.
Unless unsuccessful then it will return the error from Server.
None: Returns None.
Unless unsuccessful then it will return the error from Server.
"""
logger.info(f"Stopping {self.Name} in {self.tabular_class.Server.Name}")
return self.Trace.Stop()
Expand All @@ -151,8 +173,8 @@ def drop(self) -> None:
"""Call when you want to drop the trace.

Returns:
None: Returns None. Unless unsuccessful,
then it will return the error from Server.
None: Returns None. Unless unsuccessful,
then it will return the error from Server.
"""
logger.info(f"Dropping {self.Name} in {self.tabular_class.Server.Name}")
atexit.unregister(self.drop)
Expand Down