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. Requiresgenkit v1.0.0 or later.1
Initialize Braintrust and call Genkit
2
Run with the import hook
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 withwrapGenkit(). 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 andtime_to_first_token. - Embedding spans (
genkit.embedandgenkit.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.