Skip to content

peterroelants/context-tracer

Repository files navigation

Context Tracer

Package to help trace Python function call contexts. Initially developed to trace LLM Agent function calls.

Usage

To annotate a function to be traced, use the @trace decorator:

from context_tracer.trace import trace

@trace
def demo_function():
    ...

To run a function or program with tracing enabled, use a Tracing context manager. For example the TracingWithViewer will open a web browser to show a flame chart of the traced function calls:

from context_tracer.tracing_viewer.tracer_with_view import TracingWithViewer

with TracingWithViewer(
    db_path=...,
    ...
) as tracing:
    demo_function()

Other Tracing context managers are available, see src/context_tracer/trace_implementations for more details.

Full example

See notebooks/example.ipynb for a usage example.

OTEL

This library has some similarities with OTel (OpenTelemetry). OTEL is focussed on distributed tracing for microservice applications. This library is focussed on tracing function calls within a single application. OTEL is a much more mature project and has a lot more features. This library is much simpler and has a much smaller footprint.

Questions/TODO: