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"

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.0.1.tar.gz (9.2 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.0.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for spantom-0.0.1.tar.gz
Algorithm Hash digest
SHA256 d71e8f55031072506c25aa3d3f51717e0d1e31602131fc5ef9d5c86c15ce3395
MD5 76e905967b8f439d234c7fc090b73d1e
BLAKE2b-256 a2c132ec3e0d1ea9d814ebf4a43e6c797f5dda1b055f24e32dafff623473adae

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spantom-0.0.1-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

Hashes for spantom-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c7b0f28c72a6ed3bc65b7043fdadd15791517bd8a49eb7eea4b0aac31f5f0569
MD5 1b1d383896410b97dfdbaca176235f92
BLAKE2b-256 3b8dc71596d6a83fee90f4422a2461d8d310da0778212f5b7f52fb7e048bd3b4

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