A lightweight tracing library for Python
Project description
Spantom is a python package for simple local tracing.
Spantom spans can use a context manager. Span tags are associated with the span they are created in.
from spantom import SP
SP.init()
for x in range(10):
with SP.span("foo"):
SP.tag({"index": x})
print("foo")
print(SP.summary())
Or spans can be attached to functions.
from spantom import SP
SP.init()
@SP.span()
def foo(x):
SP.tag({"foo_input": x})
return "foo"
for x in range(10):
foo(x)
print(SP.summary())
A typical use case would be to capture metrics from a for loop.
@SP.span()
def slow_function(x):
# calculate something
...
@SP.tag({"intermediate_result": y})
#finish up
...
for i in range(1000):
with SP.span("outer_loop"):
SP.tag({"index": i})
# do something slow
...
SP.tag({"value": value})
slow_function(value)
SP.tag({"threshold_exceeded": x > threshold})
# finish up
...
Spantom will record the start and end time of each loop, and of each call to slow_function. It will record the dictionary values you tagged with SP.tag and associate them with the corresponding span. These values are stored in a sqlite database where you can analyze runtimes and correlations between tags.
Try the spantom dashboard to get started analyzing spans. It can be installed with pip options.
pip install spantom[dashboard]
To launch the dashboard:
spantom
Spans are saved to a sqlite database.
The default database is /tmp/spantom.db.
You can configure the database path by setting the SPANTOM_DB environment variable,
or by passing a path to SP.init().
You can specify a different database path for the dashboard:
spantom --db-path /path/to/my_spans.db
I use the spantom dashboard for quick analysis of spans. For more in depth analysis, you can use the sqlite database directly. 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 Spantom 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 Distribution
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.1.1.tar.gz.
File metadata
- Download URL: spantom-0.1.1.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c52749d036a8d280aa529437b1577ed11f8232420654d84fd0972595666eaf8
|
|
| MD5 |
6d56361f039816b5d99ff9e0957d3844
|
|
| BLAKE2b-256 |
7a2c956eb6c5b7c0868fea14201c55f5c1dbc15b74059e165f5fefbd4df78951
|
File details
Details for the file spantom-0.1.1-py3-none-any.whl.
File metadata
- Download URL: spantom-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.2 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 |
8111fa753f6e919f48afdb8e7dd0581cd40eafbdb6030c085110c0a54394cb2f
|
|
| MD5 |
6cb2fe43ff311001c8cf38ab6fd1eb9e
|
|
| BLAKE2b-256 |
ed1fcdd05f5622f9224f1dfd02cee2e06c97f5057cf6c41aa4fe44da2dd05458
|