Skip to content

Commit

Permalink
Use Date.now() instead of performance.now()
Browse files Browse the repository at this point in the history
Because `performance.now()` returns the time elapsed since Performance.timeOrigin
ref: https://arc.net/l/quote/bhkrvbbd
  • Loading branch information
Rindrics committed Dec 18, 2024
1 parent a0010b3 commit a34c025
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/(playground)/p/[agentId]/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/(playground)/p/[agentId]/lib/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
4 changes: 2 additions & 2 deletions lib/opentelemetry/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ async function withMeasurement<T>(
measurement: MeasurementSchema<T>,
measurementStartTime?: number,
): Promise<T> {
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(
Expand Down

0 comments on commit a34c025

Please sign in to comment.