Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/agentkit-execution-tracing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"braintrust": minor
---

Add automatic instrumentation for Inngest AgentKit 0.13.2 network, agent, model, routing and tool execution.
26 changes: 26 additions & 0 deletions js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,32 @@ BRAINTRUST_DISABLE_INSTRUMENTATION=langsmith node --import braintrust/hook.mjs a

When Braintrust LangChain/LangGraph instrumentation is enabled, LangSmith runs serialized by LangChain are ignored to avoid duplicate spans. Set `langchain: false` (and use LangSmith instrumentation) when LangSmith should be the source for those runs instead.

### Inngest AgentKit

The Node.js hook and bundler plugins support `@inngest/agent-kit@0.13.2`.
Initialize Braintrust logging as usual and load the hook before AgentKit:

```bash
node --import braintrust/hook.mjs app.js
```

Network runs contain routing and agent task spans; agents contain model-inference
and tool spans. Names stay stable across calls, with agent, network and tool names
in metadata. Model traces capture parsed output and reported OpenAI-compatible
token usage, without copying the raw provider response or model credentials.

Tools created by `createTool` are prepared when created. Plain tools, Inngest
function tools and MCP tools are also prepared immediately before invocation.
Tool objects and call receivers are retained. Already immutable handlers and
accessor-based handlers are left unchanged; those tools may lack individual spans.
Freezing a tool after `createTool` remains supported. Instrumentation uses the
published ESM chunk and CommonJS entrypoint; other versions are not enabled until
their compiled layouts are validated. This integration currently exposes automatic
instrumentation, without a separate module wrapper API.

Disable with `configureInstrumentation({ integrations: { agentKit: false } })`
before registration, or `BRAINTRUST_DISABLE_INSTRUMENTATION=agent-kit`.

## Migration Guides

### Upgrading from 3.x to 4.x
Expand Down
27 changes: 27 additions & 0 deletions js/src/auto-instrumentations/configs/agent-kit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { InstrumentationConfig } from "../orchestrion-js";
import { agentKitChannels } from "../../instrumentation/providers/agent-kit-interceptors";

// Validate new published layouts before extending this range or chunk path.
export const agentKitConfigs: InstrumentationConfig[] = [
"dist/chunk-BSWKEFTT.js",
"dist/index.cjs",
].flatMap((filePath) => [
...(
[
["Agent", "run", agentKitChannels.agentRun],
["Agent", "invokeTools", agentKitChannels.prepareTools],
["Network", "run", agentKitChannels.networkRun],
["AgenticModel", "infer", agentKitChannels.infer],
["NetworkRun", "getNextAgents", agentKitChannels.route],
] as const
).map(([className, methodName, hook]) => ({
channelName: hook.channelName,
module: { name: "@inngest/agent-kit", versionRange: "=0.13.2", filePath },
functionQuery: { className, methodName },
})),
{
channelName: agentKitChannels.createTool.channelName,
module: { name: "@inngest/agent-kit", versionRange: "=0.13.2", filePath },
functionQuery: { functionName: "createTool" },
},
]);
2 changes: 2 additions & 0 deletions js/src/auto-instrumentations/configs/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { piCodingAgentConfigs } from "./pi-coding-agent";
import { strandsAgentSDKConfigs } from "./strands-agent-sdk";
import { deepgramConfigs } from "./deepgram";
import { falConfigs } from "./fal";
import { agentKitConfigs } from "./agent-kit";
import { elevenLabsConfigs } from "./elevenlabs";
import { voyageAIConfigs } from "./voyageai";
import { mcpConfigs } from "./mcp";
Expand All @@ -50,6 +51,7 @@ interface InstrumentationConfigGroup {

const defaultInstrumentationConfigGroups: readonly InstrumentationConfigGroup[] =
[
{ integrations: ["agentKit"], configs: agentKitConfigs },
{ integrations: ["openai"], configs: openaiConfigs },
{
integrations: ["openaiCodexSDK"],
Expand Down
4 changes: 4 additions & 0 deletions js/src/instrumentation/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export interface InstrumentationIntegrationsConfig {
deepgram?: boolean;
fal?: boolean;
elevenlabs?: boolean;
agentKit?: boolean;
/** Set to false to disable, or pass options; options keep LiveKit enabled. */
livekit?: boolean | LiveKitIntegrationConfig;
/** Set to false to disable, or pass options; options keep MCP enabled. */
Expand Down Expand Up @@ -264,6 +265,9 @@ const envIntegrationAliases: Record<
fal: "fal",
"@fal-ai/client": "fal",
elevenlabs: "elevenlabs",
agentkit: "agentKit",
"agent-kit": "agentKit",
"@inngest/agent-kit": "agentKit",
"@elevenlabs/elevenlabs-js": "elevenlabs",
livekit: "livekit",
"@livekit/agents": "livekit",
Expand Down
5 changes: 5 additions & 0 deletions js/src/instrumentation/instrumentation-consumers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const registrations = vi.hoisted(() => ({
cloudflareThink: vi.fn(),
cohere: vi.fn(),
fal: vi.fn(),
agentKit: vi.fn(),
cursorSDK: vi.fn(),
genkit: vi.fn(),
gitHubCopilot: vi.fn(),
Expand Down Expand Up @@ -59,6 +60,9 @@ vi.mock("./providers/cloudflare-think-instrumentation", () => ({
vi.mock("./providers/fal-instrumentation", () => ({
registerFalInstrumentation: registrations.fal,
}));
vi.mock("./providers/agent-kit-instrumentation", () => ({
registerAgentKitInstrumentation: registrations.agentKit,
}));
vi.mock("./providers/cohere-instrumentation", () => ({
registerCohereInstrumentation: registrations.cohere,
}));
Expand Down Expand Up @@ -141,6 +145,7 @@ const integrationCases: Array<
["cloudflareThink", [registrations.cloudflareThink]],
["cohere", [registrations.cohere]],
["fal", [registrations.fal]],
["agentKit", [registrations.agentKit]],
["cursorSDK", [registrations.cursorSDK]],
["genkit", [registrations.genkit]],
["gitHubCopilot", [registrations.gitHubCopilot]],
Expand Down
2 changes: 2 additions & 0 deletions js/src/instrumentation/instrumentation-consumers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { registerInstrumentation as fal } from "./registrations/fal";
import { registerInstrumentation as agentKit } from "./registrations/agentKit";
import { registerInstrumentation as mcpHandler } from "./registrations/mcpHandler";
import { registerInstrumentation as fastmcp } from "./registrations/fastmcp";
import { registerInstrumentation as mcp } from "./registrations/mcp";
Expand Down Expand Up @@ -40,6 +41,7 @@ import { registerInstrumentation as mastra } from "./registrations/mastra";

/** Register every enabled provider. Only explicit auto setup imports this module. */
export function registerInstrumentationConsumers(): void {
agentKit();
mcp();
mcpHandler();
fastmcp();
Expand Down
Loading