jeff

jeff

Replacing Phoenix.Instrumenter with Telemetry events in AppSignal's Phoenix integration

Hey all!

I’m Jeff, from AppSignal. I’ve been working on getting our integration ready for the deprecation of Phoenix.Instrumenter in the upcoming version of Phoenix, and I could use some guidance.

Currently, we Phoenix.Instrumenter to hook into the phoenix_controller_call events to track events as they happened. Now, with the newly emitted Telemetry events, we’re moving that logic over to a new event handler that hooks into the [:phoenix, :endpoint, :start] and [:phoenix, :endpoint, :stop] events, which has been working great for our purposes.

However, we’re having some trouble getting the controller and action names out of the conn in the new events. Since the old phoenix_controller_call events were called later in the request, the pipeline was already called, meaning the :phoenix_controller and :phoenix_action` were already set in the conn. Since the Telemetry events are called right before the pipeline is started, we can’t set the controller and action names before the controller action is called. We’ve moved the logic to set the controller and action names to a before_send callback.

Again, this works. However, when an error happens that prevents the before_send callback from being called (like an unhandled exit or a timeout), we can’t determine in which controller action that error happened. We’re trying to figure out if there’s a way around that, or if this is intended behaviour.

We were excited to see this proposal to add controller events last year, which would allow us to revert to setting the action names before the action is called, but it seems like this was replaced with the endpoint events that are in master now. Are there any plans to bring something like this back?

In short; we’re able to instrument endpoint calls on Phoenix 1.5 currently, but we can’t match exits to their controller and action names, causing them to be reported as “outside of an action” in AppSignal. Would that be expected behaviour (since they’re process exits), or would there be a way around that? Any input would be greatly appreciated!

Thanks,
— Jeff

Marked As Solved

josevalim

josevalim

Creator of Elixir

TL;DR - if plug+plug_opts metadata are both atoms, you have controller+action, otherwise log only the plug.

Hi Jeff!

We moved it to the router so we instrument more cases. Previously, plugs were rarely instrumented. So in this case, the controller+action were replaced by plug+plug_opts metadata. What we do is that, if plug and plug_opts are both atoms, then we can assume they are a controller+action.

You can see what we do here:

https://github.com/phoenixframework/phoenix/blob/master/lib/phoenix/logger.ex#L160

I hope this helps!

Also Liked

jeff

jeff

Hey @josevalim! That certainly helps. Knowing I can trust the plug and plug_opts from the metadata will allow us to revert back to setting the controller and action names before the pipeline is called, thus catching those errors again.

Thanks a lot! :slight_smile:

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
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
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
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
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29703 241
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
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
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

We're in Beta

About us Mission Statement