Astarno

Astarno

Using the Interceptor library to log GenServer behavior

Hi there,

I am currently trying to add logging capabilities to GenServers. I am aware that there are existing solutions that provide insights into a GenServer’s behavior, including logging, but this is not what I am looking for. I am looking to implement a solution myself, one I can afterwards customize and expand upon (e.g. instead of logging make API calls). For this purpose, I found the Interceptor library. This seems great for what I want to do as it allows for some custom code could be executed before/after/… a specified function each time it is executed.

What I did until now is the following. First, I made my own module called GenServerViz. In this module I basically copied all of the regular GenServer code I found on GitHub, but then expanded it with the Interceptor library. I then use GenServerViz instead of the regular GenServer. Using this approach I was able to intercept all functions that are explicitly defined in GenServers, such as start, start_link, stop, call, cast, etc. However, I am currently clueless how I would go about intercepting the callbacks such as handle_cast, handle_call, init, etc as these functions are not explicitly defined in GenServers but are usually defined in the user modules themselves.

The ‘ugly’ solution would be to setup the interception for each module that makes use of my GenServerViz. This would include adding import statements, setting up configuration and either annotating or wrapping the relevant functions inside an intercept block. This would be a very cumbersome process on a bigger scale. It would also mean that one cannot easily switch from the regular GenServer to GenServerViz by just changing the use/import statements in existing projects, something I would like to be easily possible.

Any suggestions?

Where Next?

Popular in Questions Top

Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
Kagamiiiii
Student & New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement