Horkos
Horkos

Reputation: 391

Measure NextJS API metrics and response time

I built a NextJS app with SSR deployed on Vercel. Recently, the deployment broke with following error:

504: GATEWAY_TIMEOUT
Code: FUNCTION_INVOCATION_TIMEOUT

I learned that this may be caused by high initial response times from my API, but I have no tool to debug it or measure/decompose response time in order to understand where the problem comes from.

No details were provided within the logs nor in the console.

How should I proceed?

Upvotes: 0

Views: 1224

Answers (1)

Rockwell
Rockwell

Reputation: 89

For measuring any process in ms at NextJS / NodeJS:

// First define
const startTime = process.hrtime();

// To start it:
const elapsed = process.hrtime(startTime);

// To end it:
const responseTimeInMs = elapsed[0] * 1000 + elapsed[1] / 1000000;
console.log('Response Time:', responseTimeInMs, 'ms');

Hope this helps!

Upvotes: 0

Related Questions