elixir-plug / plug

Compose web applications with functions
https://hex.pm/packages/plug
Other
2.84k stars 582 forks source link

feat: Manually emit telemetry events with measurement #1177

Closed maltoe closed 10 months ago

maltoe commented 10 months ago

Hi :wave:

I'm currently working on some library code where I'd like to be able to send arbitrary telemetry events (possibly including exceptions, but what I mostly want is the :duration) from a pipeline which uses Plug.Telemetry.

This unfinished PR is me asking whether you have any interest in changing this plug's behaviour to allow the user to take advantage of the duration measurement for custom events, by storing the start time and event prefix in the conn's private instead of in a function capture. No hard feelings if not. If yes, I'll add tests and docs.

side-note: Dropped the precalculated start_event and stop_event lists, possibly hurting performance by doing so.

josevalim commented 10 months ago

Because the code is relatively small, I'd prefer for you to have your own implementation, than exposing more of the plug implementation details. Sorry and thanks :)

maltoe commented 10 months ago

Fair enough. Thanks for taking a look! :bow: