How to intercept db request ecto


Like we can intercept http request by creating a interceptor and the plugging it in the controller definition.
Is there a way where I can intercept ecto query and it duration and all without using any other libraries.


What do you mean by intercept?

Sorry being vague,
By intercept I mean I want to get the db query and duration once it is executed every time.
What exactly I want to monitor the execution time of each query and capture it by statsd client.

maybe callback: Ecto.Repo.prepare_query/3 ?

Have a look at Ecto.Repo’s telemetry docs section.


I think this one will do.
Stuck in other task right now once done with that I will try out this one and let you know.