{:ok, :debug_on_production} — Elixir
How to debug the elixir-based applications on production and Why debugging at Production is not Hokum😎.
Before moving ahead, Kudos to you if you could understand this {:ok, :debug_on_production}
Why do we need the capability to debug on production?
Having a way to debug in production is an invaluable tool, as it eliminates the need to reproduce issues locally. You can find and fix the issue on the running system directly.
Developers — know the pain to keep dev, prepared, and test environment as similar to prod. It is quite time-consuming and in the practical world of microservices, your application might be running between or behind N number of micro-services and to reproduce some new scenarios which are introduced because some other applications could take time to reproduce locally.
Before moving ahead — please refer to my below article on Elixir & Phoenix-based message broadcasting application and Elixir Pattern Match.
https://medium.com/nerd-for-tech/pattern-matching-one-of-the-coolest-feature-of-elixir-dc99eafb99
Another cool feature of elixir other than Pattern match is its iEx shell, which allows you to debug running applications on production.
How to debug Elixir App — iEx
For prod applications, we are using the GKE setup. Firstly, connect to your elixir based application pod
kubectl get pods -n news-feed-dev
Connect to the pod
kubectl exec -it news-feed-dev-789bbb67df-xvwkn -n news-feed-dev sh
Run below command. Replace `bar@127.0.0.1` with the current iEx mix application name.
> iex --name "test@iex_test" --werl --hidden --cookie "$_COOKIE"
--vm-args "$_VM_ARGS"
--remsh "bar@127.0.0.1"
I am using NewsFeed Elixir Kafka integration repo which I have used for in my another article.
It will allow you to run any public function from the interactive shell on prod.
iex > Consumer.news_feed_consumer(%{key: "test", value: "test"})
You could debug at the function level on prod and find out the gap.
Here, sharing my 2 cents about the general practice which I follow while working in the functional programming language. In the MR, do make sure that functions are precise enough and ask developers to do extract function to keep it precise https://refactoring.com/catalog/extractFunction.html
This way you could get better control and could debug complete in-out.
See you in another article. Thanks For reading!
Follow on https://ritresh-girdhar.medium.com/