Skip to main content

A lightweight tracing library for Python

Project description

logo

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"

with SP.span("bar"):
    for x in range(10):
        foo(x)

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

Sample image

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 duration
  • span_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

spantom-0.1.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spantom-0.1.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file spantom-0.1.0.tar.gz.

File metadata

  • Download URL: spantom-0.1.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.13

File hashes

Hashes for spantom-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3b96bc2f35e5c117b48d477af248593bd6c41e5b3048746938b9151cece6e6ab
MD5 3fbf0e77b471a91acadcd9e681d3060a
BLAKE2b-256 25c943a8241f9b435d5019879a97df8cd3dd4426b8d72ae7bb4b9d48746c3c27

See more details on using hashes here.

File details

Details for the file spantom-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: spantom-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.13

File hashes

Hashes for spantom-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 753727a90c4cd81cf30bbc14d23c8e6d8b054db0b13cacdd9ef8092ce5257550
MD5 c26c674970235822fa8e882fadc8fb8d
BLAKE2b-256 6df9578e4d45d34a66d21a7e38d876bff4133db8990d924a6f4193d675883bd6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page