beam-telemetry / telemetry_metrics

Collect and aggregate Telemetry events over time
https://hexdocs.pm/telemetry_metrics
Apache License 2.0
207 stars 33 forks source link

Use function capture for attaching `handle_event/4` #107

Closed nick96 closed 1 year ago

nick96 commented 1 year ago

I hope you don't mind me making a PR without an associated issue. I couldn't find an existing one and this seemed like a relatively easy fix.

The documentation for :telemetry.attach/4 states that function capture should be used for the event handler, rather than local function capture for performance reasons. Using local function capture also leads to warnings like:

https://hexdocs.pm/telemetry/telemetry.html#attach/4
[info] The function passed as a handler with ID {Telemetry.Metrics.ConsoleReporter, [:phoenix, :router_dispatch, :start], #PID<0.576.0>} is a local function.
This means that it is either an anonymous function or a capture of a function without a module specified. That may cause a performance penalty when calling that handler. For more details see the note in `telemetry:attach/4` documentation.

Unfortunately, to allow using function capture, I've had to make handle_event/4 a public function.

codecov-commenter commented 1 year ago

Codecov Report

Merging #107 (b9a1637) into main (084a430) will not change coverage. The diff coverage is 100.00%.

:exclamation: Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/beam-telemetry/telemetry_metrics/pull/107/graphs/tree.svg?width=650&height=150&src=pr&token=RB1Tk7vxzD&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=beam-telemetry)](https://app.codecov.io/gh/beam-telemetry/telemetry_metrics/pull/107?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=beam-telemetry) ```diff @@ Coverage Diff @@ ## main #107 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 2 2 Lines 142 108 -34 ========================================= - Hits 142 108 -34 ``` | [Impacted Files](https://app.codecov.io/gh/beam-telemetry/telemetry_metrics/pull/107?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=beam-telemetry) | Coverage Δ | | |---|---|---| | [lib/telemetry\_metrics/console\_reporter.ex](https://app.codecov.io/gh/beam-telemetry/telemetry_metrics/pull/107?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=beam-telemetry#diff-bGliL3RlbGVtZXRyeV9tZXRyaWNzL2NvbnNvbGVfcmVwb3J0ZXIuZXg=) | `100.00% <100.00%> (ø)` | | ... and [1 file with indirect coverage changes](https://app.codecov.io/gh/beam-telemetry/telemetry_metrics/pull/107/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=beam-telemetry) ------ [Continue to review full report in Codecov by Sentry](https://app.codecov.io/gh/beam-telemetry/telemetry_metrics/pull/107?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=beam-telemetry). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=beam-telemetry) > `Δ = absolute (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://app.codecov.io/gh/beam-telemetry/telemetry_metrics/pull/107?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=beam-telemetry). Last update [084a430...b9a1637](https://app.codecov.io/gh/beam-telemetry/telemetry_metrics/pull/107?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=beam-telemetry). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=beam-telemetry).
josevalim commented 1 year ago

:green_heart: :blue_heart: :purple_heart: :yellow_heart: :heart: