A library for tracing function calls with depth control and filtering.
Project description
call-tracer
call-tracer
is a library for tracing function calls with depth control and filtering.
Installation
pip install call-tracer
(Required: python >= 3.6)
Usage
Basic Usage
from calltracer import tracer
def add_one(n):
return n+1
def add_two(n):
n = add_one(n)
n = add_one(n)
return n
@tracer
def main():
n = add_two(4)
main()
Customizations
If you want to use tracer
to monitor the internal workings of langchain, you'll encounter a tremendous number of calls and returns, each accompanied by very long file paths. Therefore, you may need to customize the tracer
slightly:
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from calltracer import tracer
tracer.set_max_depth(3)
tracer.set_path_cuts(['python3.9'])
tracer.set_path_filters(['pydantic'])
@tracer
def main():
prompt = ChatPromptTemplate.from_messages([
("system", f"You are a helpful assistant"),
MessagesPlaceholder(variable_name="chat_history"),
("user", "{input}")
])
main()
set_max_depth
: Set the maximum depth for tracing. (printsdepth
<=max_depth
)set_path_cuts
: Specify paths to be shortened in the trace output to simplify and clean up the displayed file paths in the trace logs.- For example, if you use
trace.set_path_cuts(['PythonProjects'])
, the path/Users/your_name/PythonProjects/your_project/sample.py
will be shortened toyour_project/sample.py
.
- For example, if you use
set_path_filters
: Specify paths to be excluded from tracing, preventing the trace function from logging calls and returns for files matching these paths.
Contributing
- Pull requests are welcome.
- For major changes, please open an issue first to discuss what you would like to change.
- Please make sure to update tests as appropriate.
License
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
call-tracer-1.0.4.tar.gz
(3.7 kB
view hashes)
Built Distribution
Close
Hashes for call_tracer-1.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58823b475f166548b3a99bb48b5e90fb50618b156840abae088e7f67618faa1f |
|
MD5 | 080a1fd54c95d628e5616aabd8f15085 |
|
BLAKE2b-256 | 50c7085d8965e0e0d207db1fcd3a1a1784eab60495beb32054fa077442cf9aa9 |