How to correctly log API call execution time

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.


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.

1 Like

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.

1 Like

Great tip. Thank you. It will works for me

1 Like

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)

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.