Skip to main content

Tracepulse

[Version] [Python]

Lightweight execution tracing and performance observability for synchronous and asynchronous Python code.

Table of Contents

  • Features
  • Quickstart
  • Usage
    • Sync example
    • Async example
  • Configuration & Context
  • Advanced
  • Suggested features
  • License
  • Release / PyPI

Tracepulse provides a simple decorator-based tracer that records function start/end, duration (ms precision), exceptions, and structured logs compatible with Loguru. It's intentionally minimal and safe for production use.

Highlights

  • Zero configuration decorator: @trace
  • Works with sync and async callables
  • Structured, minimal overhead logs
  • Integrates with loguru for flexible output

Features

  • Sync and Async tracing
  • Structured execution logs (function name, args summary, duration)
  • Failure telemetry capture (exception type, message, traceback)
  • Duration measurement (millisecond precision)
  • Loguru-backed logging integration (fallbacks to stdlib logging if loguru is unavailable)
  • Minimal surface area and runtime overhead

Quickstart

Install (from PyPI after publishing):

# once published to PyPI
pip install tracepulse

Then add the tracer to a function:

from tracepulse import trace

@trace
def compute():
    return sum(range(1_000_000))

compute()

Usage

Sync example

from tracepulse import trace

@trace
def heavy_work(x):
    # your work here
    return x * 2

heavy_work(10)

Async example

import asyncio
from tracepulse import trace

@trace
async def fetch():
    await asyncio.sleep(1)

asyncio.run(fetch())

Notes:

  • @trace can be applied to any callable; it preserves function signature and return value.
  • For heavy throughput code, prefer adding @trace at higher-level boundaries (handlers, tasks) rather than inner hot loops.

Configuration & Context

  • set_level(level_str) — programmatically adjust console logging level (e.g., set_level("DEBUG")).
  • set_context(dict) — attach context tags to subsequent traces (returns a token). Example:
from tracepulse import set_context, clear_context

token = set_context({"request_id": "abcd-1234"})
# traces will include `request_id`
clear_context(token)  # reset

These helpers let you add lightweight, application-level context to trace events without a heavy propagation system.

New helpers

  • enable_file_backend(path) — write trace events as newline-delimited JSON to path.
  • trace_block(name, tags=None, sample_rate=1.0) — context manager for tracing arbitrary code blocks.
  • trace(..., sample_rate=0.1) — decorator now supports sampling via sample_rate (0.0-1.0).

Advanced

  • Logging: Tracepulse uses loguru internally by default; if loguru is not installed the package falls back to the stdlib logging module so basic demos and imports still work.
  • Data captured: function name, arg summary (optional), start timestamp, end timestamp, duration_ms, exception info (if any), and optional context tags.

Suggested / Future Features

  • Pluggable backends (send traces to file/HTTP/OTel)
  • Context propagation across threads/processes
  • Sampled tracing to reduce overhead for very high throughput
  • Richer argument serialization and PII scrubbing hooks
  • CLI tooling to visualize recent traces locally

Release / PyPI

Steps:

python -m build
python -m twine upload dist/*

## Changelog

- v0.1.1 — Documentation improvements, README refresh, version bump
- v0.1.2 — Added context helpers, runtime `set_level`, and demo CLI
- v0.1.3 — Added backend exporter (file), `trace_block`, sampling support, and README beautification

Metadata

Release files for tracepulse 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tracepulse 0.1.7
File Size Uploaded
tracepulse-0.1.7.tar.gz 8.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tracepulse 0.1.7
File Interpreter ABI Platform
tracepulse-0.1.7-py3-none-any.whl Python 3 none any Details

Total release size: 16.2 kB

Release files / tracepulse-0.1.7.tar.gz

Download URL tracepulse-0.1.7.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d9379fe4fd5b276a7b2cac4bb0f90ac0e7b931746ddb2aa3fe8e38994b471565
BLAKE2b-256 checksum
How to use checksums
54d8ab77ea88f01a0e6c40d3d9d08532bf8eddeb3a309aa0e202e6c72983dcf0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.19

Release files / tracepulse-0.1.7-py3-none-any.whl

Download URL tracepulse-0.1.7-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
566c2af731df924aa0e859f59abd92d0ab994c655256a47cf7cf3c48a8a4c227
BLAKE2b-256 checksum
How to use checksums
91361bb20ff099af1da9b2f62531651fc39b6b6d17fd4fa2176ec36581a56b2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.19

Release history Release notifications | RSS feed

This release

0.1.7 This release

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page