diff --git a/app/(playground)/p/[agentId]/actions.ts b/app/(playground)/p/[agentId]/actions.ts index 0d99ebeb..fa0ff663 100644 --- a/app/(playground)/p/[agentId]/actions.ts +++ b/app/(playground)/p/[agentId]/actions.ts @@ -13,7 +13,7 @@ import { anthropic } from "@ai-sdk/anthropic"; import { google } from "@ai-sdk/google"; import { openai } from "@ai-sdk/openai"; import { toJsonSchema } from "@valibot/to-json-schema"; -import { del, list, put } from "@vercel/blob"; +import { type ListBlobResult, del, list, put } from "@vercel/blob"; import { type LanguageModelV1, jsonSchema, streamObject } from "ai"; import { createStreamableValue } from "ai/rsc"; import { MockLanguageModelV1, simulateReadableStream } from "ai/test"; @@ -468,26 +468,38 @@ export async function putGraph(graph: Graph) { export async function remove(fileData: FileData) { const startTime = Date.now(); - const blobList = await list({ - prefix: buildFileFolderPath(fileData.id), - }); + function calcTotalSize(blobList: ListBlobResult): number { + return blobList.blobs.reduce((sum, blob) => sum + blob.size, 0); + } + const { blobList } = await withCountMeasurement( + createLogger("remove"), + async () => { + const result = await list({ + prefix: buildFileFolderPath(fileData.id), + }); + return { + blobList: result, + size: calcTotalSize(result), + }; + }, + ExternalServiceName.VercelBlob, + startTime, + VercelBlobOperation.List, + ); + const startTimeDel = Date.now(); if (blobList.blobs.length > 0) { await withCountMeasurement( createLogger("remove"), async () => { await del(blobList.blobs.map((blob) => blob.url)); - const totalSize = blobList.blobs.reduce( - (sum, blob) => sum + blob.size, - 0, - ); return { - size: totalSize, + size: calcTotalSize(blobList), }; }, ExternalServiceName.VercelBlob, - startTime, + startTimeDel, VercelBlobOperation.Del, ); waitForTelemetryExport(); diff --git a/app/(playground)/p/[agentId]/page.tsx b/app/(playground)/p/[agentId]/page.tsx index f9287c87..69544b45 100644 --- a/app/(playground)/p/[agentId]/page.tsx +++ b/app/(playground)/p/[agentId]/page.tsx @@ -72,6 +72,7 @@ export default async function Page({ async function persistGraph(graph: Graph) { "use server"; const startTime = Date.now(); + const logger = createLogger("persistGraph"); const { url } = await putGraph(graph); await db .update(agents) @@ -79,9 +80,22 @@ export default async function Page({ graphUrl: url, }) .where(eq(agents.id, agentId)); - const blobList = await list({ - prefix: buildGraphFolderPath(graph.id), - }); + const { blobList } = await withCountMeasurement( + logger, + async () => { + const result = await list({ + prefix: buildGraphFolderPath(graph.id), + }); + const size = result.blobs.reduce((sum, blob) => sum + blob.size, 0); + return { + blobList: result, + size, + }; + }, + ExternalServiceName.VercelBlob, + startTime, + VercelBlobOperation.List, + ); const oldBlobs = blobList.blobs .filter((blob) => blob.url !== url) @@ -91,7 +105,7 @@ export default async function Page({ })); if (oldBlobs.length > 0) { await withCountMeasurement( - createLogger("persistGraph"), + logger, async () => { await del(oldBlobs.map((blob) => blob.url)); const totalSize = oldBlobs.reduce((sum, blob) => sum + blob.size, 0); diff --git a/lib/opentelemetry/types.ts b/lib/opentelemetry/types.ts index ff693e84..89751226 100644 --- a/lib/opentelemetry/types.ts +++ b/lib/opentelemetry/types.ts @@ -80,10 +80,17 @@ const VercelBlobDelSchema = RequestCount.extend({ blobSizeStored: z.number(), // minus the size of the blob deleted }); +const VercelBlobListSchema = RequestCount.extend({ + externalServiceName: z.literal(ExternalServiceName.VercelBlob), + operationType: z.literal("list"), + blobSizeTransfered: z.number(), +}); + const VercelBlobRequestCountSchema = z.discriminatedUnion("operationType", [ VercelBlobPutSchema, VercelBlobFetchSchema, VercelBlobDelSchema, + VercelBlobListSchema, ]); const RequestCountSchema = z.union([ diff --git a/lib/opentelemetry/wrapper.ts b/lib/opentelemetry/wrapper.ts index 94057bc3..13035424 100644 --- a/lib/opentelemetry/wrapper.ts +++ b/lib/opentelemetry/wrapper.ts @@ -137,6 +137,12 @@ export const VercelBlobOperation = { blobSizeStored: -result.size, }), }, + List: { + type: "list" as const, + measure: (result: { size: number }) => ({ + blobSizeTransfered: result.size, + }), + }, } as const; type VercelBlobOperationType =