Manual Tracing

Tracing

See the Quick Start for instructions on installing and configuring the Graphsignal SDK.

Python

To measure and monitor code that is not automatically instrumented, e.g. tool calls, wrap the code with the trace() method or use the @trace_function decorator.

You can also record sub-spans to visualize trace timeline and latency breakdown.

with graphsignal.trace('inference') as span:
    span.set_counter('prompt_tokens', prompt_tokens)
    span.set_counter('completion_tokens', completion_tokens)

    with span.trace('model-cold-boot') as sub_span:
        ...
@graphsignal.trace_function
def my_function():
    ...

Recording exceptions

Python

For auto-instrumented libraries, or when using the @trace_function decorator, the trace() method with a with context manager, or callbacks, exceptions are automatically recorded. For other cases, use Span.add_exception.

Recording metrics

Graphsignal enables the recording of counter metrics from within the trace. All tags of the trace will be applied to the metric. The metric will be aggregated and sent automatically. Below is an illustration of how usage data can be recorded:

Python
with graphsignal.trace('my-function') as span:
    ...
    span.inc_counter_metric('call_cost', price_per_call)

See Span.inc_counter_metric() for more information.

The usage and cost data will be presented as time series on the Metrics Dashboard, allowing for aggregation by tags. Additionally, usage details will be accessible within the traces.