Request and Response time

Hi All,

I have a requirement to log Request time and Response time in Apigee i used system variable called "system.timestamp" this is capturing the time but the values appears like big integer number which i had to convert it Date and time format. So here are my questions.

1. What is the best way to capture Request time

2.What is the best way to capture Response time.

Thank

Chandra

0 3 1,467
3 REPLIES 3

Not applicable

Apigee message template option is there to convert the timestamp to a particular format.

You can get the timestamp and using a python script can convert the timestamp to human readable format.

You can use javascript or java policy to convert as well.

i used system variable called "system.timestamp" this is capturing the time but the values appears like big integer number

According to the documentation, The time value you retrieve from system.timestamp is a nanoseconds-since-epoch.

i had to convert it Date and time format.

You didn't say how you performed the conversion. I'll suggest what I would do: use AssignMessage.

<AssignMessage name='AM-1'>
  <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
  <AssignVariable>
    <Name>formatString1</Name>
    <Value>yyyy-MM-dd HH:mm:ss.SSS</Value>
  </AssignVariable>
  <AssignVariable>
    <Name>formattedTime</Name>
    <Template>{timeFormatUTCMs(formatString1,client.received.end.timestamp)}</Template>
    <!-- eg, 2020-10-02 16:01:14.786 -->
  </AssignVariable>
</AssignMessage><br>

That's an easy way to convert.

And your questions were:

What is the best way to capture {Request,Response} time?

I think you have to be careful about exactly what you want to measure. The variable, client.received.end.timestamp expresses the time and date at which the client request has completely arrived in the API Proxy.

Alternatively, You might want to measure... for example,... the total latency of the TARGET, including the request and the response. This is not a time-and-date value, but a timespan value, ... something like 75ms or whatever it is. Computing that would look like this:

var start, end, delta;
start = context.getVariable('target.sent.start.timestamp');
end = context.getVariable('target.received.end.timestamp');
delta = Math.floor(end - start);
context.setVariable('time-target-elapsed', delta);

If you want to measure the time consumed in the Response pipeline, which is to say, a timespan value between the time the target has sent its response, and the time before the proxy sends the first byte of response to the client, then use something like this:

var start, end, delta;
start = context.getVariable('target.received.end.timestamp');
end = context.getVariable('client.sent.start.timestamp');
delta = Math.floor(end - start);
context.setVariable('time-response-elapsed', delta);

Check the documentation for other timestamp variables that will let you get what you want. Note: some of these variables are available only in the PostClientFlow!

Just to check, is your requirement to log and send to another system or just ensure this is captured?

Depending on what the exact actual ask is, if it's any help, keep in mind that Apigee analytics builds up a set of metrics out of the box that you can then view via the reports/custom reports or management API. This includes metrics such as proxy request processing time, response processing time, target response time, total response time etc

https://docs.apigee.com/api-platform/analytics/analytics-reference