Crimson Tracer
Crimson Tracer is a lightweight Python tracing utility that records function call events and provides useful insights into your code execution. It captures details such as function inputs, file names, line numbers, and more, allowing you to analyze the call flow. Additionally, you can convert raw trace events into a nested tree structure and serialize them to JSON for further processing.
Features
- Function Call Tracing: Automatically capture call, line, and return events during execution.
- Tree Generation: Convert a linear list of trace events into a nested tree structure for easy visualization.
- JSON Serialization: Serialize trace data to JSON, ensuring all dictionary keys are strings.
- Frame Filtering: Include or exclude specific frames based on filename patterns using the built-in
FrameFilter. - Customizable Event Editing: Modify trace events on the fly with an optional custom event editor.
Install
pip install crimson-tracer
Example
Tracer
The TraceManager collects all called functions along with valuable details such as function inputs and execution context.
For a complete example, see tracer.ipynb.
from crimson.tracer import TraceManager
def sample_function():
# Your function logic here
return "result"
# Run the tracer on the sample function
TraceManager.run_trace(sample_function, name="sample_trace")
trace_events = TraceManager.get_trace("sample_trace")
Node
Convert the traced result into a nested tree structure for a clearer view of the call hierarchy using generate_trace_tree.
For more details, refer to node.ipynb.
from crimson.tracer import generate_trace_tree, TraceManager
trace_events = TraceManager.get_trace("sample_trace")
trace_tree = generate_trace_tree(trace_events)
API Overview
-
TraceManager:
Manages the tracing process, collects trace events, and provides methods to run and retrieve traces. -
TraceEvent:
A Pydantic model that represents a trace event with details like function name, filename, line number, event type, local variables, and more. -
generate_trace_tree:
Transforms a list of trace events into a nested tree structure to reflect the call hierarchy. -
dumps:
Serializes trace data into a JSON-formatted string with all dictionary keys as strings. -
FrameFilter:
Allows filtering of stack frames based on inclusion and exclusion rules to refine the tracing process.
Crimson Tracer offers a flexible and efficient way to monitor and analyze function calls in your Python applications. Enjoy exploring your code's execution flow with ease!
Metadata
Release files for crimson-tracer 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| crimson_tracer-0.1.5.tar.gz | 8.2 kB | Without provenance | Details for crimson_tracer-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| crimson_tracer-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for crimson_tracer-0.1.5-py3-none-any.whl |
Total release size: 16.2 kB
Release files / crimson_tracer-0.1.5.tar.gz
| Download URL | crimson_tracer-0.1.5.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7ec31ed91fe7d347d3519079564c8d2d7272e4214d45aa54a053124fcf02c94e
|
|
BLAKE2b-256 checksum How to use checksums |
cda268fb4c84d9d0b8149f39c4de8aa6f34fbf6ede940dc25550e57051bef016
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.21
|
Release files / crimson_tracer-0.1.5-py3-none-any.whl
| Download URL | crimson_tracer-0.1.5-py3-none-any.whl |
|---|---|
| Size | 8.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ed950d8ad7198aea9c830ccea6c615c8384360cf1ef1d6863b2b1cdd9c2c7d95
|
|
BLAKE2b-256 checksum How to use checksums |
dffeda373c4276b4804515ef4ab970284665ef4e028a74732aa0ece33eac03cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.21
|
Security for crimson-tracer 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.