Manual Tracing

Tracing operations

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

Python

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

You can also record sub-operations to visualize operation timeline and latency breakdown.

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

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

Recording exceptions

Python

For auto-instrumented libraries, or when using @trace_function decorator, trace() method with 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-operation') 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.