A lightweight tracing library for Python
Project description
Spantom is a python package for simple local tracing.
To get started try this example:
from spantom import SP
SP.init()
@SP.span()
def foo(x):
SP.tag({"foo_input": x})
return "foo"
print(SP.summary())
Spans are saved to a sqlite database.
The default database is /tmp/spantom.db,
but you can specify a different path at init:
SP.init("/path/to/my_spans.db")
A typical use case would be to capture metrics from a for loop:
@SP.span()
def my_slow_function(x):
...
@SP.tag({"intermediate_result": y})
...
for i in range(1000):
my_slow_function(i)
When a function is tagged with span Tracelite will record the start and end time of the function call. This allows you to measure function durations and find bottlenecks in your code.
Additionally span tags are a powerful mechanism to record arbitrary metadata about the function call. The tag keys and values can be any strings. This allows you to capture metrics, parameters, or any other relevant information.
Tracelite comes with a simple viewer to query and plot the spans. To use the viewer, install spantom with the dashboard option:
pip install spantom[dashboard]
Then launch the viewer:
spantom --db-path /path/to/my_spans.db
Or you can query the spans manually using sqlite3. This works well in combination with pandas.
import sqlite3
import pandas as pd
from spantom import DEFAULT_DB
self.conn = sqlite3.connect(DEFAULT_DB)
self.curs = self.conn.cursor()
df_spans = pd.read_sql_query("SELECT * FROM spans", self.conn)
df_tags = pd.read_sql_query("SELECT * FROM span_tags", self.conn)
A Tracelite database contains two tables:
spans: Contains the span data: id, name, start, and durationspan_tags: Contains tags associated with spans: id, span_id, key, value
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spantom-0.0.0-py3-none-any.whl.
File metadata
- Download URL: spantom-0.0.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
776f90f8fbcd8d9f87461d11794d1f2e3aa8b47966588389904adc1879d30b76
|
|
| MD5 |
0863268374d3f31fc0b4f32f57eddd7a
|
|
| BLAKE2b-256 |
e9f6513a6d95bd657df8c1d749c9a216675c20bd738b3da1848c90d2a33c6dd3
|