How to programmatically track tasks execution metadata/stats?

I want to be able to know tasks execution metadata: specifically latency, which node it was called on, start time, finish time, state (scheduled/executing/failed/finished) and ideally some optional metadata I can pass around. Is there an api for this?

You might find the state api useful

there is also CLI version you can try.

@yic thanks! Can you give an example of how to query task execution time? I’m not able to find it in the link you provided.