Skip to content
Open
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
22 changes: 18 additions & 4 deletions packages/ai/tests/integration_v7.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4162,6 +4162,7 @@ const evaluateOutput = {
const gatewayRuns = [
{
operation: "generateText",
toolCalls: 1,
start: (integ: V7Integration, callId: string) => {
integ.onStart?.({
callId,
Expand All @@ -4172,6 +4173,14 @@ const gatewayRuns = [
integ.onStepStart?.({ callId, stepNumber: 0, ...gateway("openai/gpt-4o") });
},
finish: async (integ: V7Integration, callId: string) => {
const toolCall = { toolCallId: "t-gateway", toolName: "lookup", input: { q: "otel" } };
integ.onToolExecutionStart?.({ callId, toolCall });
integ.onToolExecutionEnd?.({
callId,
toolCall,
toolExecutionMs: 50,
toolOutput: { type: "tool-result", output: { hits: 1 } },
});
integ.onStepEnd?.({
callId,
stepNumber: 0,
Expand Down Expand Up @@ -4283,7 +4292,7 @@ const gatewayRuns = [
];

const expectGatewayRootAndStep = (spans: readonly ReadableSpan[]) => {
const roots = spans.filter((s) => s.kind === SpanKind.INTERNAL);
const roots = spans.filter((s) => s.kind === SpanKind.INTERNAL && s.name !== "execute_tool");
const steps = spans.filter((s) => s.kind === SpanKind.CLIENT);
expect(roots).toHaveLength(1);
expect(steps).toHaveLength(1);
Expand All @@ -4292,8 +4301,8 @@ const expectGatewayRootAndStep = (spans: readonly ReadableSpan[]) => {
};

test.each(gatewayRuns)(
"ai@7 $operation relabels the gateway provider on the root and step spans and the step metrics",
async ({ operation, start, finish }) => {
"ai@7 $operation relabels the gateway provider on the root and step spans and the metrics",
async ({ operation, start, finish, toolCalls = 0 }) => {
const { spanBatches, metrics, overrides } = makeCapture();
const integ = telemetryDev(baseOptions, overrides);
const callId = `gateway-${operation}`;
Expand All @@ -4302,7 +4311,12 @@ test.each(gatewayRuns)(
await finish(integ, callId);

expectGatewayRootAndStep(spanBatches[0]!);
expect(metrics.filter((m) => m.metric === "duration")).toHaveLength(1);
const durations = metrics.filter((m) => m.metric === "duration");
const toolDurations = durations.filter(
(m) => m.attributes["gen_ai.operation.name"] === "execute_tool",
);
expect(durations).toHaveLength(1 + toolCalls);
expect(toolDurations).toHaveLength(toolCalls);

for (const m of metrics) {
expect(m.attributes["gen_ai.provider.name"]).toBe("Vercel AI Gateway");
Expand Down
Loading