Skip to main content
Firebase Genkit is Google’s open-source framework for building AI-powered applications. Braintrust traces Genkit calls from your application.

Setup

Install Braintrust alongside Genkit and a model plugin.

Auto-instrumentation

To trace Genkit calls without modifying your application code, initialize Braintrust normally, then run your app with Braintrust’s import hook to patch Genkit at runtime. Requires genkit v1.0.0 or later.
1

Initialize Braintrust and call Genkit

2

Run with the import hook

The auto-instrumentation example uses plain JavaScript so node --import can run the file directly. The Braintrust APIs work the same in TypeScript projects — compile your TypeScript to JavaScript, then run the compiled file with the import hook.
If you’re using a bundler, see Trace LLM calls for plugin and loader setup.

Manual instrumentation

To trace Genkit manually, wrap your Genkit instance yourself with wrapGenkit(). Use this when you want to instrument a specific instance rather than patching Genkit globally.

What Braintrust traces

Braintrust patches the Genkit SDK and captures:
  • Generate spans (genkit.generate), with the prompt and messages as input, model and request parameters in metadata, and the response as output.
  • Streaming generate spans (genkit.generateStream), with streamed text output and time_to_first_token.
  • Embedding spans (genkit.embed and genkit.embedMany), with input as input and a summarized result (embedding count and dimensions).
  • Action spans (genkit.<action_type>: <name>) for flows, tools, and other Genkit actions, with input, output, and duration, plus action type, name, and key in metadata.
  • Token usage metrics (prompt, completion, total, plus cached and reasoning tokens when reported).
  • Errors captured on every call.

Tracing resources