Query traces
Before diving into this content, it might be helpful to read the following:
If you are looking to export a large volume of traces, we recommen that your use the Bulk Data Export functionality, as it will better handle large data volumes and will support automatic retries, and parallelization across partitions.
The recommended way to query runs (the span data in LangSmith traces) is to use the list_runs
method in the SDK or /runs/query
endpoint in the API.
LangSmith stores traces in a simple format that is specified in the Run (span) data format.
Use filter arguments
For simple queries, you don't have to rely on our query syntax. You can use the filter arguments specified in the filter arguments reference.
Initialize the client before running the below code snippets.
- Python
- TypeScript
from langsmith import Client
client = Client()
import { Client, Run } from "langsmith";
const client = new Client();
Below are some examples of ways to list runs using keyword arguments:
List all runs in a project
- Python
- TypeScript
project_runs = client.list_runs(project_name="<your_project>")
// Download runs in a project
const projectRuns: Run[] = [];
for await (const run of client.listRuns({
projectName: "<your_project>",
})) {
projectRuns.push(run);
};
List LLM and Chat runs in the last 24 hours
- Python
- TypeScript
todays_llm_runs = client.list_runs(
project_name="<your_project>",
start_time=datetime.now() - timedelta(days=1),
run_type="llm",
)
const todaysLlmRuns: Run[] = [];
for await (const run of client.listRuns({
projectName: "<your_project>",
startTime: new Date(Date.now() - 1000 * 60 * 60 * 24),
runType: "llm",
})) {
todaysLlmRuns.push(run);
};