Subscribing my LiveView to Telemetry Metrics Reporter

Hello everyone,
I’m trying to build a Phoenix LiveView app that makes use of telemetry and telemetry metrics libraries.
I’ve set up telemetry and metrics and I’ve written a simple reporter under the MyApp directory. The reporter can send metrics and events info to the console using Logger.

I’m not sure how to send this metrics and events data to my view and liveview. I currently have a public function in my reporter that just looks up the counter value in my ets table and then I call that function in my view module and send it to my leex template as an assign. This doesn’t seem like the right way to do this and would appreciate any help on the correct way to send my metrics to my liveview.



I’m just learning about telemetry, but it would seem like the thing you want to do look at this code:

I would say do the :telemetry.attach/4 thtang and in your handler function, you should simply send your telemetry events up a Phoenix PubSub. The LiveView will subscribe to that PubSub and thereby get the information it needs.

Also I’m not 100% sure what process the :telemetry.attach/4 runs. I’m very certain it’s not the genserver that is being run in the code that I linked to.

Phoenix.PubSub and :telemetry are both ways to send data to subscribers. There’s not really a need to use both.

Oh so I should do a telemetry.attach directly to the liveview process? I guess i"m not sure what process the attached function is going to run it, and how do you send it the pid of a process that’s encapsulating state that you care about (for example assigns)