View logs

To view logs, navigate to the Logs tab in the appropriate project in the Braintrust UI. Logs are automatically updated in real-time as new traces are logged.

Logs

Filtering logs

You can filter logs by tags, time range, and other fields using the Filter menu.

Create custom columns

Create custom columns to extract specific values from input, output, expected, or metadata fields.

Braintrust Query Language (BTQL)

You can also filter by arbitrary subfields using Braintrust Query Language syntax.

Here are a few examples of common filters:

DescriptionSyntax
Logs older than the past daycreated < CURRENT_DATE - INTERVAL 1 DAY
Logs with a user_id field equal to 1234metadata.user_id = '1234'
Logs with a Factuality score greater than 0.5scores.Factuality > 0.5

Monitor page

To monitor your logs select Go to monitor on the right-hand side of the Logs page. This page shows aggregate values for latency, token count, time to first token, cost, and scores for logs.

Monitor page

Select the Group by dropdown menu to group the data shown using metadata fields.

Monitor page with group by

Querying through the API

For basic filters and access to the logs, you can use the project logs endpoint. This endpoint supports the same query syntax as the UI, and also allows you to specify additional fields to return.

For more advanced queries, you can use BTQL endpoint.

Tags

Braintrust supports curating logs by adding tags, and then filtering on them in the UI. Tags naturally flow between logs, to datasets, and even to experiments, so you can use them to track various kinds of data across your application, and track how they change over time.

Configuring tags

Tags are configured at the project level, and in addition to a name, you can also specify a color and description. To configure tags, navigate to the Configuration tab in a project, where you can add, modify, and delete tags.

Configure tags

Adding tags in the SDK

You can also add tags to logs using the SDK. To do so, simply specify the tags field when you log data.

import { wrapOpenAI, initLogger } from "braintrust";
import { OpenAI } from "openai";
 
const logger = initLogger({
  projectName: "My Project",
  apiKey: process.env.BRAINTRUST_API_KEY,
});
const client = wrapOpenAI(new OpenAI({ apiKey: process.env.OPENAI_API_KEY }));
 
export async function POST(req: Request) {
  return logger.traced(async (span) => {
    const input = await req.text();
    const result = await client.chat.completions.create({
      model: "gpt-3.5-turbo",
      messages: [{ role: "user", content: input }],
    });
    span.log({ input, output: result, tags: ["user-action"] });
    return {
      result,
      requestId: span.id,
    };
  });
}

Tags can only be applied to top-level spans, e.g those created via traced() or logger.startSpan()/ logger.start_span(). You cannot apply tags to subspans (those created from another span), because they are properties of the whole trace, not individual spans.

You can also apply tags while capturing feedback via the logFeedback() / log_feedback() method.

import { initLogger } from "braintrust";
 
const logger = initLogger({
  projectName: "My project",
  apiKey: process.env.BRAINTRUST_API_KEY,
});
 
export async function POSTFeedback(req: Request) {
  const { spanId, comment, score, userId } = await req.json();
  logger.logFeedback({
    id: spanId, // Use the newly created span's id, instead of the original request's id
    comment,
    scores: {
      correctness: score,
    },
    metadata: {
      user_id: userId,
    },
    tags: ["user-feedback"],
  });
}

Filtering by tags

To filter by tags, simply select the tags you want to filter by in the UI.

On this page