Log intermediate steps
Log all the intermediate steps of your LLM app pipeline
To help you debug and deep dive into your LLM apps logs, you can set up tracing using the phospho
library.
This traces every intermediate steps of your LLM app pipeline, from the input text to the output text.
Setup
Install phospho
This feature is currently only available for Python. NodeJS version coming soon!
Make sure you have the phospho
module installed:
Install OpenTelemetry instrumentations
phospho leverages OpenTelemetry instrumentations to trace your LLM app pipeline. To trace a library, you need to install the corresponding instrumentation.
For example, here is how to trace OpenAI and Mistral API calls:
Refer to this list of available instrumentations to find the one that fits your needs.
Initialize phospho
Initialize phospho with phospho.init()
and enable tracing with tracing=True
:
Automatic tracing
All calls to the installed instrumentations are traced.
For example, when you do phospho.log
, the OpenAI API calls will be linked to this log.
You can view intermediate steps in the Phospho dashboard when reading a message transcript.
In the automatic tracing mode, the link between API calls and logs is done using the timestamps. If you want more control, you can use the context tracing or manual tracing.
Context tracing
To have more control over which instrumentations calls are linked to which logs, define a context using the phospho.tracer()
context block or @phospho.trace()
decorator syntax.
Context block
This links all calls to the instrumentations made inside the context block to the phospho log. For example, this will link the OpenAI API call to the log:
To add session_id
, task_id
and metadata
, pass them as arguments to the context block:
Decorator syntax
This works the same way as the context block.
The context is phospho.tracer
, while the decorator is phospho.trace
, without the r
.
To add session_id
, task_id
and metadata
, pass them as arguments to the decorator:
Manual tracing
Pass intermediate steps as a steps
parameter to phospho.log
to trace your pipeline:
This is useful to trace custom modules, which don’t have an Opentelemetry instrumentation available. For example, document retrieval, data augmentation, etc.
Was this page helpful?