When working with Opik, it is important to be able to export traces, spans, and threads so that you can use them to fine-tune your models or run deeper analysis.
You can export the data you have logged to the Opik platform using:
Opik.search_traces, Opik.search_spans, and Opik.search_threads) or the TypeScript SDK method (client.searchTraces()) to export traces, spans, and threads./traces and /spans endpoints to export traces and spans.Export CSV button in the Actions dropdown.The recommended way to export data is to use the SDK methods in the Opik
Python SDK
(Opik.search_traces,
Opik.search_spans,
and
Opik.search_threads)
or TypeScript SDK (client.searchTraces()).
The Python SDK Opik.search_traces method and TypeScript SDK client.searchTraces() method allow you to both export all the traces in a project or search for specific traces and export them.
To export all traces, you will need to specify a max_results / maxResults value that is higher than the total number of traces in your project:
You can use the filter_string (Python) / filterString (TypeScript) parameter to search for specific traces:
All search methods (search_traces, search_spans, and search_threads) accept a filter_string (Python) / filterString (TypeScript) parameter that uses Opik Query Language (OQL):
Rules:
AND (OR is not supported)"2024-01-01T00:00:00Z")metadata.model, feedback_scores.accuracyEach entity type supports a different set of filter columns. The tables below list the available columns for each.
If your feedback_scores key contains spaces, you will need to wrap
it in double quotes:
'feedback_scores."My Score" > 0'
If the feedback_scores key contains both spaces and double quotes, you will need to escape the double quotes as "":
'feedback_scores."Score ""with"" Quotes" > 0'
or by using different quotes, surrounding in triple-quotes, like this:
'''feedback_scores.'Accuracy "Happy Index"' < 0.8'''
You can export spans using the Opik.search_spans method. This method allows you to search for spans based on trace_id or based on a filter string.
trace_idTo export all the spans associated with a specific trace, you can use the trace_id parameter:
You can use the filter_string parameter to search for specific spans:
You can export threads using the Opik.search_threads method. This method allows you to search for conversational threads in a project.
To export all threads, you will need to specify a max_results value that is higher than the total number of threads in your project:
You can use the filter_string parameter to search for specific threads:
To export traces using the Opik REST API, you can use the /traces endpoint and the /spans endpoint. These endpoints are paginated so you will need to make multiple requests to retrieve all the traces or spans you want.
To search for specific traces or spans, you can use the filter parameter. While this is a string parameter, it does not follow the same format as the filter_string parameter in the Opik SDK. Instead it is a list of json objects with the following format:
The filter parameter was designed to be used with the Opik UI and has
therefore limited flexibility. If you need more flexibility, please raise an
issue on GitHub so we can help.
To export traces as a CSV file from the UI, you can simply select the traces or spans you wish to export and click on Export CSV in the Actions dropdown:

The UI only allows you to export up to 100 traces or spans at a time as it is linked to the page size of the traces table. If you need to export more traces or spans, we recommend using the Opik SDK.