Skip to content
Merged
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/violet-vans-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"braintrust": minor
---

feat(ai-sdk): Add Workflow Agent instrumentation
42 changes: 37 additions & 5 deletions e2e/helpers/provider-runtime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,43 @@ export async function runTracedScenario(options) {
}

export async function getInstalledPackageVersion(importMetaUrl, packageName) {
let currentDir = path.dirname(
require.resolve(packageName, {
paths: [path.dirname(fileURLToPath(importMetaUrl))],
}),
);
let currentDir;

try {
currentDir = path.dirname(
require.resolve(packageName, {
paths: [path.dirname(fileURLToPath(importMetaUrl))],
}),
);
} catch {
currentDir = path.dirname(fileURLToPath(importMetaUrl));

while (true) {
const manifestPath = path.join(
currentDir,
"node_modules",
...packageName.split("/"),
"package.json",
);

try {
const manifest = JSON.parse(await fs.readFile(manifestPath, "utf8"));
if (manifest && typeof manifest.version === "string") {
return manifest.version;
}
} catch {
// Keep walking upward until we find the package root.
}

const parentDir = path.dirname(currentDir);
if (parentDir === currentDir) {
break;
}
currentDir = parentDir;
}

throw new Error(`Could not resolve installed version for ${packageName}`);
}

while (true) {
const manifestPath = path.join(currentDir, "package.json");
Expand Down
37 changes: 36 additions & 1 deletion e2e/helpers/scenario-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { spawn } from "node:child_process";
import { promises as fs } from "node:fs";
import { createRequire } from "node:module";
import * as path from "node:path";
import { fileURLToPath } from "node:url";
import { BasicTracerProvider } from "@opentelemetry/sdk-trace-base";

export interface SubprocessResult {
Expand Down Expand Up @@ -121,7 +122,41 @@ export async function getInstalledPackageVersion(
packageName: string,
): Promise<string> {
const require = createRequire(importMetaUrl);
let currentDir = path.dirname(require.resolve(packageName));
let currentDir: string;

try {
currentDir = path.dirname(require.resolve(packageName));
} catch {
currentDir = path.dirname(fileURLToPath(importMetaUrl));

while (true) {
const manifestPath = path.join(
currentDir,
"node_modules",
...packageName.split("/"),
"package.json",
);

try {
const manifestRaw = await fs.readFile(manifestPath, "utf8");
const manifest = JSON.parse(manifestRaw) as { version?: string };

if (typeof manifest.version === "string") {
return manifest.version;
}
} catch {
// Keep walking upward until we find the package root.
}

const parentDir = path.dirname(currentDir);
if (parentDir === currentDir) {
break;
}
currentDir = parentDir;
}

throw new Error(`Could not resolve installed version for ${packageName}`);
}

while (true) {
const manifestPath = path.join(currentDir, "package.json");
Expand Down
1,300 changes: 1,100 additions & 200 deletions e2e/scenarios/ai-sdk-instrumentation/__cassettes__/ai-sdk-v7.cassette.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@
"reasoningTokens": 0
}
},
"rawResponse": {
"headers": "<omitted>"
},
"rawResponse": {},
"response": {
"modelId": "gpt-4o-mini-2024-07-18",
"timestamp": "<timestamp>"
Expand Down Expand Up @@ -93,11 +91,8 @@
}
},
"finishReason": "stop",
"rawResponse": {
"headers": "<omitted>"
},
"rawResponse": {},
"response": {
"headers": "<omitted>",
"messages": [
{
"content": [
Expand All @@ -123,7 +118,6 @@
"finishReason": "stop",
"isContinued": false,
"response": {
"headers": "<omitted>",
"messages": [
{
"content": [
Expand Down Expand Up @@ -248,9 +242,7 @@
},
"output": {
"finishReason": "stop",
"rawResponse": {
"headers": "<omitted>"
},
"rawResponse": {},
"text": "One, two, three.",
"warnings": []
},
Expand Down Expand Up @@ -380,9 +372,7 @@
"reasoningTokens": 0
}
},
"rawResponse": {
"headers": "<omitted>"
},
"rawResponse": {},
"response": {
"modelId": "gpt-4o-mini-2024-07-18",
"timestamp": "<timestamp>"
Expand Down Expand Up @@ -466,11 +456,8 @@
}
},
"finishReason": "tool-calls",
"rawResponse": {
"headers": "<omitted>"
},
"rawResponse": {},
"response": {
"headers": "<omitted>",
"messages": [
{
"content": [
Expand Down Expand Up @@ -513,7 +500,6 @@
"finishReason": "tool-calls",
"isContinued": false,
"response": {
"headers": "<omitted>",
"messages": [
{
"content": [
Expand Down Expand Up @@ -689,9 +675,7 @@
"reasoningTokens": 0
}
},
"rawResponse": {
"headers": "<omitted>"
},
"rawResponse": {},
"response": {
"modelId": "gpt-4o-mini-2024-07-18",
"timestamp": "<timestamp>"
Expand Down Expand Up @@ -762,11 +746,8 @@
"object": {
"city": "Paris"
},
"rawResponse": {
"headers": "<omitted>"
},
"rawResponse": {},
"response": {
"headers": "<omitted>",
"modelId": "gpt-4o-mini-2024-07-18",
"timestamp": "<timestamp>"
},
Expand Down Expand Up @@ -905,9 +886,7 @@
"object": {
"city": "Paris"
},
"rawResponse": {
"headers": "<omitted>"
},
"rawResponse": {},
"warnings": []
},
"metadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ span_tree:
│ }
│ },
│ "finishReason": "stop",
│ "rawResponse": {
│ "headers": "<omitted>"
│ },
│ "rawResponse": {},
│ "response": {
│ "headers": "<omitted>",
│ "messages": [
│ {
│ "content": [
Expand All @@ -62,7 +59,6 @@ span_tree:
│ "finishReason": "stop",
│ "isContinued": false,
│ "response": {
│ "headers": "<omitted>",
│ "messages": [
│ {
│ "content": [
Expand Down Expand Up @@ -135,9 +131,7 @@ span_tree:
│ "reasoningTokens": 0
│ }
│ },
│ "rawResponse": {
│ "headers": "<omitted>"
│ },
│ "rawResponse": {},
│ "response": {
│ "modelId": "gpt-4o-mini-2024-07-18",
│ "timestamp": "<timestamp>"
Expand Down Expand Up @@ -185,9 +179,7 @@ span_tree:
│ }
│ output: {
│ "finishReason": "stop",
│ "rawResponse": {
│ "headers": "<omitted>"
│ },
│ "rawResponse": {},
│ "text": "One, two, three.",
│ "warnings": []
│ }
Expand Down Expand Up @@ -328,11 +320,8 @@ span_tree:
│ }
│ },
│ "finishReason": "tool-calls",
│ "rawResponse": {
│ "headers": "<omitted>"
│ },
│ "rawResponse": {},
│ "response": {
│ "headers": "<omitted>",
│ "messages": [
│ {
│ "content": [
Expand Down Expand Up @@ -375,7 +364,6 @@ span_tree:
│ "finishReason": "tool-calls",
│ "isContinued": false,
│ "response": {
│ "headers": "<omitted>",
│ "messages": [
│ {
│ "content": [
Expand Down Expand Up @@ -544,9 +532,7 @@ span_tree:
│ │ "reasoningTokens": 0
│ │ }
│ │ },
│ │ "rawResponse": {
│ │ "headers": "<omitted>"
│ │ },
│ │ "rawResponse": {},
│ │ "response": {
│ │ "modelId": "gpt-4o-mini-2024-07-18",
│ │ "timestamp": "<timestamp>"
Expand Down Expand Up @@ -626,11 +612,8 @@ span_tree:
│ "object": {
│ "city": "Paris"
│ },
│ "rawResponse": {
│ "headers": "<omitted>"
│ },
│ "rawResponse": {},
│ "response": {
│ "headers": "<omitted>",
│ "modelId": "gpt-4o-mini-2024-07-18",
│ "timestamp": "<timestamp>"
│ },
Expand Down Expand Up @@ -695,9 +678,7 @@ span_tree:
│ "reasoningTokens": 0
│ }
│ },
│ "rawResponse": {
│ "headers": "<omitted>"
│ },
│ "rawResponse": {},
│ "response": {
│ "modelId": "gpt-4o-mini-2024-07-18",
│ "timestamp": "<timestamp>"
Expand Down Expand Up @@ -766,9 +747,7 @@ span_tree:
"object": {
"city": "Paris"
},
"rawResponse": {
"headers": "<omitted>"
},
"rawResponse": {},
"warnings": []
}
metadata: {
Expand Down
Loading
Loading