From a34c0252af4afaee6ccb0211edcaeb35a0fb7355 Mon Sep 17 00:00:00 2001 From: Akira Hayashi Date: Tue, 17 Dec 2024 17:31:21 +0900 Subject: [PATCH] Use `Date.now()` instead of `performance.now()` Because `performance.now()` returns the time elapsed since Performance.timeOrigin ref: https://arc.net/l/quote/bhkrvbbd --- app/(playground)/p/[agentId]/actions.ts | 2 +- app/(playground)/p/[agentId]/lib/execution.ts | 2 +- .../p/[agentId]/prev/beta-proto/artifact/server-actions.ts | 2 +- .../p/[agentId]/prev/beta-proto/files/server-actions.ts | 4 ++-- .../p/[agentId]/prev/beta-proto/web-search/server-action.ts | 2 +- lib/opentelemetry/wrapper.ts | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/(playground)/p/[agentId]/actions.ts b/app/(playground)/p/[agentId]/actions.ts index fa0ff663..10594435 100644 --- a/app/(playground)/p/[agentId]/actions.ts +++ b/app/(playground)/p/[agentId]/actions.ts @@ -121,7 +121,7 @@ export async function action( agentId: AgentId, nodeId: NodeId, ) { - const startTime = performance.now(); + const startTime = Date.now(); const lf = new Langfuse(); const trace = lf.trace({ sessionId: artifactId, diff --git a/app/(playground)/p/[agentId]/lib/execution.ts b/app/(playground)/p/[agentId]/lib/execution.ts index 4cb3bfe8..6d410c5b 100644 --- a/app/(playground)/p/[agentId]/lib/execution.ts +++ b/app/(playground)/p/[agentId]/lib/execution.ts @@ -235,7 +235,7 @@ export async function executeStep( stepId: StepId, artifacts: Artifact[], ) { - const startTime = performance.now(); + const startTime = Date.now(); const lf = new Langfuse(); const trace = lf.trace({ sessionId: executionId, diff --git a/app/(playground)/p/[agentId]/prev/beta-proto/artifact/server-actions.ts b/app/(playground)/p/[agentId]/prev/beta-proto/artifact/server-actions.ts index a8945b46..4bf6f2b8 100644 --- a/app/(playground)/p/[agentId]/prev/beta-proto/artifact/server-actions.ts +++ b/app/(playground)/p/[agentId]/prev/beta-proto/artifact/server-actions.ts @@ -27,7 +27,7 @@ type GenerateArtifactStreamParams = { export async function generateArtifactStream( params: GenerateArtifactStreamParams, ) { - const startTime = performance.now(); + const startTime = Date.now(); const lf = new Langfuse(); const currentUser = await fetchCurrentUser(); const trace = lf.trace({ diff --git a/app/(playground)/p/[agentId]/prev/beta-proto/files/server-actions.ts b/app/(playground)/p/[agentId]/prev/beta-proto/files/server-actions.ts index b016518f..d208271e 100644 --- a/app/(playground)/p/[agentId]/prev/beta-proto/files/server-actions.ts +++ b/app/(playground)/p/[agentId]/prev/beta-proto/files/server-actions.ts @@ -18,7 +18,7 @@ type UploadFileInput = { file: File; }; export async function uploadFile({ input }: { input: UploadFileInput }) { - const startTime = performance.now(); + const startTime = Date.now(); const logger = createLogger("files"); const result = await withCountMeasurement( logger, @@ -51,7 +51,7 @@ type ParseFileInput = { blobUrl: string; }; export async function parseFile(args: ParseFileInput) { - const startTime = performance.now(); + const startTime = Date.now(); const logger = createLogger("files"); if (process.env.UNSTRUCTURED_API_KEY === undefined) { throw new Error("UNSTRUCTURED_API_KEY is not set"); diff --git a/app/(playground)/p/[agentId]/prev/beta-proto/web-search/server-action.ts b/app/(playground)/p/[agentId]/prev/beta-proto/web-search/server-action.ts index 006ad87f..ef1fc470 100644 --- a/app/(playground)/p/[agentId]/prev/beta-proto/web-search/server-action.ts +++ b/app/(playground)/p/[agentId]/prev/beta-proto/web-search/server-action.ts @@ -40,7 +40,7 @@ interface GenerateWebSearchStreamInputs { export async function generateWebSearchStream( inputs: GenerateWebSearchStreamInputs, ) { - const startTime = performance.now(); + const startTime = Date.now(); const lf = new Langfuse(); const currentUser = await fetchCurrentUser(); const trace = lf.trace({ diff --git a/lib/opentelemetry/wrapper.ts b/lib/opentelemetry/wrapper.ts index 13035424..82596fbc 100644 --- a/lib/opentelemetry/wrapper.ts +++ b/lib/opentelemetry/wrapper.ts @@ -73,14 +73,14 @@ async function withMeasurement( measurement: MeasurementSchema, measurementStartTime?: number, ): Promise { - const startTime = measurementStartTime ?? performance.now(); // set `startTime` for each call in parallel process + const startTime = measurementStartTime ?? Date.now(); // set `startTime` for each call in parallel process try { // business logic: error should be thrown const result = await operation(); try { // instrumentation: error must not be thrown to avoid interfering with the business logic - const duration = performance.now() - startTime; + const duration = Date.now() - startTime; Promise.all([getCurrentMeasurementScope(), isRoute06User()]) .then(([measurementScope, isR06User]) => { const metrics = measurement(