cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to correctly log API call execution time

ed_tc
New Contributor III

Hello everybody,
I want to create some metrics related to API call time.
For now, I am trying to subtract date.now and pipe.startTime using following expression (Math.trunc((Date.now() - pipe.startTime)) ) in mapper preceded by REST POST. Sceleton of pipeline attached. Capture
The issue is this solution not quite accurate. Iโ€™ve tried to compare the time that I received by expression and time for snaplogic log and they are different.
Does any body have an idea how to retrieve the correct time in mapper using some expression?
Appreciated for any help.

5 REPLIES 5

cstewart
Former Employee

If I were you, I would add a mapper before the REST POST, which adds a Date.now() field, and then after the execution pick up that value from the $original output from the POST, and subtract the value of another Date.now(). You should now have the length of time between the two.

ed_tc
New Contributor III

Great tip. Thank you. It will works for me

ed_tc
New Contributor III

The solution works fine only in case if in Execute task option Reuse executions to process documents set to false. I found strange behavior when the option set to true. Based on log every API call takes less that one second, but I observe in metric data value that exceed 80 sec ( which is impossible according timeout of API service which is 30 second)

ed_tc
New Contributor III

Finally I found the solution. The solution is instead of mapper I used script component to set up start date. After that deduction was performed in mapper component.