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
1 change: 1 addition & 0 deletions dev-packages/seinfeld/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
],
"scripts": {
"build": "tsup",
"check:typings": "tsc --noEmit",
"dev": "tsup --watch",
"typecheck": "tsc --noEmit"
},
Expand Down
3 changes: 0 additions & 3 deletions dev-packages/seinfeld/src/cassette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,5 @@ export interface CassetteFile {
entries: CassetteEntry[];
}

/** @deprecated Use `CassetteFile` instead. */
export type Cassette = CassetteFile;

/** The three execution modes used by the cassette server. */
export type CassetteMode = "replay" | "record" | "passthrough";
1 change: 1 addition & 0 deletions dev-packages/seinfeld/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"moduleResolution": "bundler",
"lib": ["ES2022", "DOM"],
"strict": true,
"noUnusedLocals": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
"noFallthroughCasesInSwitch": true,
Expand Down
1 change: 1 addition & 0 deletions integrations/browser-js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"target": "es2022",
"moduleResolution": "bundler",
"strict": true,
"noUnusedLocals": true,
"esModuleInterop": true,
"skipLibCheck": true,
"resolveJsonModule": true
Expand Down
964 changes: 0 additions & 964 deletions integrations/langchain-js/src/BraintrustCallbackHandler.fixtures.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion integrations/langchain-js/src/BraintrustCallbackHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
type LangChainCallbackHandlerOptions,
} from "braintrust";

export type BraintrustCallbackHandlerOptions<IsAsyncFlush extends boolean> =
type BraintrustCallbackHandlerOptions<IsAsyncFlush extends boolean> =
LangChainCallbackHandlerOptions<IsAsyncFlush>;

/**
Expand Down
1 change: 0 additions & 1 deletion integrations/langchain-js/src/test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const server = setupServer(
);

beforeAll(() => {
// comment out specific to use bypassAndLog
process.env.BRAINTRUST_API_KEY = "braintrust-api-key";
process.env.BRAINTRUST_APP_URL = "http://braintrust.local";
process.env.BRAINTRUST_ORG_NAME = "braintrustdata.com";
Expand Down
30 changes: 0 additions & 30 deletions integrations/langchain-js/src/test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,7 @@
import { mergeDicts } from "braintrust/util";
import { BaseCallbackHandler } from "@langchain/core/callbacks/base";
import { bypass, HttpResponse, JsonBodyType } from "msw";
import { TransformStream } from "stream/web";
import { LogsRequest } from "./types";

const decoder = new TextDecoder();
// comment out process.env overriding in setup.ts for this to be helpful
const bypassAndLog = async (request: Request): Promise<Response> => {
console.log(request.method, request.url);
const res = await fetch(bypass(request));

// If it's not a stream, handle as before
if (!res.body || !res.headers.get("content-type")?.includes("stream")) {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const json = (await res.json()) as JsonBodyType;
console.log(JSON.stringify(json, null, 2));
return HttpResponse.json(json);
}

const spy = new TransformStream({
transform(chunk, controller) {
console.log(decoder.decode(chunk));
controller.enqueue(chunk);
},
});

return new Response(res.body.pipeThrough(spy), {
headers: res.headers,
status: res.status,
statusText: res.statusText,
});
};

export const logsToSpans = (logs: LogsRequest[]) => {
if (logs.length === 0) {
throw new Error("No logs to convert to spans");
Expand Down
1 change: 1 addition & 0 deletions integrations/langchain-js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"target": "es2022",
"moduleResolution": "node",
"strict": true,
"noUnusedLocals": true,
"esModuleInterop": true,
"skipLibCheck": true
},
Expand Down
1 change: 1 addition & 0 deletions integrations/openai-agents-js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"target": "es2022",
"moduleResolution": "node",
"strict": true,
"noUnusedLocals": true,
"esModuleInterop": true,
"skipLibCheck": true
},
Expand Down
5 changes: 3 additions & 2 deletions integrations/otel-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"scripts": {
"build": "tsup",
"check:typings": "tsc --noEmit",
"check:typings": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
"watch": "tsup --watch",
"clean": "rm -r dist/*",
"test": "pnpm test:v1 && pnpm test:v2",
Expand All @@ -32,7 +32,8 @@
"braintrust": "workspace:*",
"tsup": "^8.5.0",
"typedoc": "^0.28.15",
"typescript": "5.5.4"
"typescript": "5.5.4",
"vitest": "4.1.5"
},
"peerDependencies": {
"@opentelemetry/api": ">=1.9.0",
Expand Down
112 changes: 65 additions & 47 deletions integrations/otel-js/src/otel-compat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe("OTEL compatibility mode", () => {
async (span1) => {
expect(currentSpan()).toBe(span1);

await tracer.startActiveSpan("otel-span-2", async (otelSpan2) => {
await tracer.startActiveSpan("otel-span-2", async (otelSpan2: any) => {
await logger.traced(
async (span3) => {
expect(currentSpan()).toBe(span3);
Expand Down Expand Up @@ -143,7 +143,7 @@ describe("OTEL compatibility mode", () => {
);
const logger = initLogger({ projectName: "mixed-tracing-otel-first" });

await tracer.startActiveSpan("otel-span-1", async (otelSpan1) => {
await tracer.startActiveSpan("otel-span-1", async (otelSpan1: any) => {
await logger.traced(
async (span2) => {
expect(currentSpan()).toBe(span2);
Expand All @@ -154,9 +154,12 @@ describe("OTEL compatibility mode", () => {

expect(span2.rootSpanId).toBe(otelTraceId);

await tracer.startActiveSpan("otel-span-3", async (otelSpan3) => {
otelSpan3.end();
});
await tracer.startActiveSpan(
"otel-span-3",
async (otelSpan3: any) => {
otelSpan3.end();
},
);
},
{ name: "bt-span-2" },
);
Expand All @@ -176,7 +179,7 @@ describe("OTEL compatibility mode", () => {
setupOtelFixture("bt-inherits-otel");
const logger = initLogger({ projectName: "bt-inherits-otel" });

await tracer.startActiveSpan("otel-parent", async (otelParent) => {
await tracer.startActiveSpan("otel-parent", async (otelParent: any) => {
const btSpan = logger.startSpan({ name: "bt-child" });

const otelContext = otelParent.spanContext();
Expand Down Expand Up @@ -212,7 +215,7 @@ describe("OTEL compatibility mode", () => {
await cm.runInContext(span1, async () => {
expect(currentSpan()).toBe(span1);

await tracer.startActiveSpan("otel-span-2", async (otelSpan2) => {
await tracer.startActiveSpan("otel-span-2", async (otelSpan2: any) => {
const span3 = logger.startSpan({ name: "bt-span-3" });

await cm.runInContext(span3, async () => {
Expand Down Expand Up @@ -295,7 +298,7 @@ describe("OTEL compatibility mode", () => {

await logger.traced(
async () => {
await tracer.startActiveSpan("otel-child", async (otelChild) => {
await tracer.startActiveSpan("otel-child", async (otelChild: any) => {
// Verify the span context is created
expect(otelChild.spanContext().traceId).toBeDefined();
otelChild.end();
Expand Down Expand Up @@ -332,29 +335,32 @@ describe("OTEL compatibility mode", () => {
);

let trace2Id: string | undefined;
await tracer.startActiveSpan("otel-trace-2", async (otelSpan2) => {
await tracer.startActiveSpan("otel-trace-2", async (otelSpan2: any) => {
const otelContext = otelSpan2.spanContext();
trace2Id = otelContext.traceId.toString().padStart(32, "0");
otelSpan2.setAttribute("test", "second_trace");
otelSpan2.end();
});

let trace3Id: string | undefined;
await tracer.startActiveSpan("otel-trace-3-root", async (otelSpan3) => {
const otelContext = otelSpan3.spanContext();
trace3Id = otelContext.traceId.toString().padStart(32, "0");

await logger.traced(
async (btSpan3) => {
// BT span inside OTEL should inherit OTEL trace ID
expect(btSpan3.rootSpanId).toBe(trace3Id);
expect(btSpan3.rootSpanId).not.toBe(trace1Id);
},
{ name: "bt-inside-otel-3" },
);

otelSpan3.end();
});
await tracer.startActiveSpan(
"otel-trace-3-root",
async (otelSpan3: any) => {
const otelContext = otelSpan3.spanContext();
trace3Id = otelContext.traceId.toString().padStart(32, "0");

await logger.traced(
async (btSpan3) => {
// BT span inside OTEL should inherit OTEL trace ID
expect(btSpan3.rootSpanId).toBe(trace3Id);
expect(btSpan3.rootSpanId).not.toBe(trace1Id);
},
{ name: "bt-inside-otel-3" },
);

otelSpan3.end();
},
);

// Verify we have 3 separate traces
expect(trace1Id).toBeDefined();
Expand Down Expand Up @@ -391,10 +397,13 @@ describe("OTEL compatibility mode", () => {
}

// Create an OTEL span inside the eval task
await tracer.startActiveSpan("otel-compute", async (otelSpan) => {
otelSpan.setAttribute("computation", input * 2);
otelSpan.end();
});
await tracer.startActiveSpan(
"otel-compute",
async (otelSpan: any) => {
otelSpan.setAttribute("computation", input * 2);
otelSpan.end();
},
);
return input * 2;
},
scores: [],
Expand Down Expand Up @@ -453,7 +462,7 @@ describe("OTEL compatibility mode", () => {

await logger.traced(
async () => {
await tracer.startActiveSpan("otel-child", async (otelSpan) => {
await tracer.startActiveSpan("otel-child", async (otelSpan: any) => {
const ctx = otelSpan.spanContext();
otelSpanCreated = true;
otelSpanHasValidContext =
Expand Down Expand Up @@ -489,7 +498,7 @@ describe("OTEL compatibility mode", () => {
btTraceId = btSpan.rootSpanId;
btSpanId = btSpan.spanId;

await tracer.startActiveSpan("otel-child", async (otelSpan) => {
await tracer.startActiveSpan("otel-child", async (otelSpan: any) => {
const ctx = otelSpan.spanContext();
otelTraceId = ctx.traceId.toString().padStart(32, "0");
otelSpan.end();
Expand Down Expand Up @@ -534,7 +543,7 @@ describe("OTEL compatibility mode", () => {
async (btSpan1) => {
spanIds.push(btSpan1.spanId);

await tracer.startActiveSpan("otel-span-1", async (otelSpan1) => {
await tracer.startActiveSpan("otel-span-1", async (otelSpan1: any) => {
spanIds.push(
otelSpan1.spanContext().spanId.toString().padStart(16, "0"),
);
Expand All @@ -543,12 +552,15 @@ describe("OTEL compatibility mode", () => {
async (btSpan2) => {
spanIds.push(btSpan2.spanId);

await tracer.startActiveSpan("otel-span-2", async (otelSpan2) => {
spanIds.push(
otelSpan2.spanContext().spanId.toString().padStart(16, "0"),
);
otelSpan2.end();
});
await tracer.startActiveSpan(
"otel-span-2",
async (otelSpan2: any) => {
spanIds.push(
otelSpan2.spanContext().spanId.toString().padStart(16, "0"),
);
otelSpan2.end();
},
);
},
{ name: "bt-span-2" },
);
Expand Down Expand Up @@ -596,10 +608,13 @@ describe("OTEL compatibility mode", () => {

await logger.traced(
async () => {
await tracer.startActiveSpan("otel-with-attrs", async (otelSpan) => {
otelSpan.setAttribute("custom.attribute", "test-value");
otelSpan.end();
});
await tracer.startActiveSpan(
"otel-with-attrs",
async (otelSpan: any) => {
otelSpan.setAttribute("custom.attribute", "test-value");
otelSpan.end();
},
);
},
{ name: "bt-parent" },
);
Expand Down Expand Up @@ -1001,10 +1016,13 @@ describe("Distributed Tracing (BT → OTEL)", () => {

// Use context.with() to run code in the imported context
await context.with(ctx, async () => {
await tracer.startActiveSpan("service_b_span", async (serviceBSpan) => {
serviceBSpan.setAttribute("service", "service_b");
serviceBSpan.end();
});
await tracer.startActiveSpan(
"service_b_span",
async (serviceBSpan: any) => {
serviceBSpan.setAttribute("service", "service_b");
serviceBSpan.end();
},
);
});

await processor.forceFlush();
Expand All @@ -1024,8 +1042,8 @@ describe("Distributed Tracing (BT → OTEL)", () => {
expect(serviceBTraceId).toBe(serviceATraceId);

// Service B span should have Service A span as parent
if (serviceBSpan.parentSpanId) {
expect(serviceBSpan.parentSpanId).toBe(serviceASpanId);
if ((serviceBSpan as any).parentSpanId) {
expect((serviceBSpan as any).parentSpanId).toBe(serviceASpanId);
}

// Note: In distributed tracing, the braintrust.parent attribute is NOT
Expand Down
2 changes: 0 additions & 2 deletions integrations/otel-js/src/otel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -768,8 +768,6 @@ export function getOtelParentFromSpan(
*/
export class BraintrustExporter {
private readonly processor: BraintrustSpanProcessor;
private readonly spans: ReadableSpan[] = [];
private readonly callbacks: Array<(result: unknown) => void> = [];

constructor(options: BraintrustSpanProcessorOptions = {}) {
// Use BraintrustSpanProcessor under the hood
Expand Down
1 change: 1 addition & 0 deletions integrations/otel-js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"target": "es2022",
"moduleResolution": "node",
"strict": true,
"noUnusedLocals": true,
"esModuleInterop": true,
"skipLibCheck": true
},
Expand Down
14 changes: 14 additions & 0 deletions integrations/otel-js/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": false,
"noEmit": true,
"types": ["node"],
"baseUrl": ".",
"paths": {
"@braintrust/otel": ["src/index.ts"]
}
},
"include": ["src/**/*.test.ts", "tests/**/*.ts"],
"exclude": ["node_modules/**", "**/dist/**", "otel-v1/**", "otel-v2/**"]
}
2 changes: 1 addition & 1 deletion integrations/templates-nunjucks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
"scripts": {
"build": "tsup",
"check:typings": "tsc --noEmit",
"check:typings": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
"watch": "tsup --watch",
"clean": "rm -r dist/*",
"test": "vitest run --exclude 'smoke/scenarios/**'",
Expand Down
Loading
Loading