Manual Tracing

Tracing operations

See Quick Start guide on how to install and configure Graphsignal tracer.

Python

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

To record payloads and track usage metrics, use Span.set_payload().

with graphsignal.trace('my-operation') as span:
    ...
    span.set_payload('my-data', data, usage=dict(size=my_data_size))
@graphsignal.trace_function
def my_function():
    ...

Tracing LLM calls

When tracing LLM generations, provide payloads in OpenAI format, which is supported by Graphsignal. Set model_type='chat' tag and add input and output data as input and output payloads respectively.

Python
with graphsignal.trace('generate', tags=dict(model_type='chat')) as span:
    output_data = my_llm_call(input_data)
    ...
    span.set_payload('input', input_data, usage=dict(token_count=input_token_count))
    span.set_payload('output', output_data, usage=dict(token_count=output_token_count))

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.