Skip to main content

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()

sample_1



Alternatively, you can use tracer.start() instead of the decorator.

tracer.start()
add_two()
tracer.end()


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()

sample_1

  • set_max_depth : Set the maximum depth for tracing. (prints depth <= 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 to your_project/sample.py.
  • set_path_filters : Specify paths to be excluded from tracing, preventing the trace function from logging calls and returns for files matching these paths.
  • set_show_args : If True, the tracer displays the input arguments of the calls.


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

MIT

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.1.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

call_tracer-1.1.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file call-tracer-1.1.1.tar.gz.

File metadata

  • Download URL: call-tracer-1.1.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for call-tracer-1.1.1.tar.gz
Algorithm Hash digest
SHA256 fe2f3147d2877b7a13ee6526390d01a34c7cd5bbf267afab1f8eaaa75f723cc6
MD5 8fed6b8f49f65201e82f049e00074a18
BLAKE2b-256 0354b3690f54188d1bfbb6b80cb622dfbbc225fc570a8bf59a02cabcaeb6cb0a

See more details on using hashes here.

File details

Details for the file call_tracer-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: call_tracer-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for call_tracer-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 90f7e28ff13de3716240231da4d9451b5d8f84745fb0e055dda648eb2d8dee3e
MD5 824257828fc54bc8fc823eedb8ec2bca
BLAKE2b-256 4a1cf873273a2199d20eb0524f483089dc5db005c2e91aeab6dd8a71d13164f6

See more details on using hashes here.

Supported by

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