Skip to content

Commit

Permalink
Fix Dialyzer issues (#4)
Browse files Browse the repository at this point in the history
* Fix Dialyzer issues
  • Loading branch information
FelonEkonom authored Sep 26, 2022
1 parent 7a32945 commit a46281f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
18 changes: 8 additions & 10 deletions lib/telemetry_metrics.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ defmodule Membrane.TelemetryMetrics do
Provided macros evalueates to meaningful code or to nothing, depending on config values, in order to achieve performance boost, when specific event or whole telemetry is not in use.
"""

@enabled Application.compile_env(:membrane_telemetry_metrics, :enabled, false)
@events Application.compile_env(:membrane_telemetry_metrics, :events, :all)

@type label() :: list()

@doc """
Expand Down Expand Up @@ -84,12 +81,13 @@ defmodule Membrane.TelemetryMetrics do
end
end

defp emit_event?(event) do
cond do
not @enabled -> false
@events == :all -> true
is_list(@events) -> event in @events
true -> false
end
enabled = Application.compile_env(:membrane_telemetry_metrics, :enabled, false)
events = Application.compile_env(:membrane_telemetry_metrics, :events, :all)

cond do
not enabled -> defp emit_event?(_event), do: false
events == :all -> defp emit_event?(_event), do: true
is_list(events) -> defp emit_event?(event), do: event in events
true -> defp emit_event?(_event), do: false
end
end
14 changes: 11 additions & 3 deletions lib/telemetry_metrics/utils.ex
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
defmodule Membrane.TelemetryMetrics.Utils do
@moduledoc false

@type handler_config :: %{
:ets => :ets.tid() | atom(),
optional(:measurement) => Telemetry.Metrics.measurement()
}

@cleanup_event_prefix :__membrane_telemetrymetrics_cleanup__

@spec attach_metric_handler(:telemetry.event_name(), :telemetry.handler_function(), %{
ets: :ets.tid() | atom()
}) :: [reference()]
@spec attach_metric_handler(
:telemetry.event_name(),
:telemetry.handler_function(),
handler_config()
) ::
[reference()]
def attach_metric_handler(event_name, handler_function, %{ets: ets} = config) do
handler_id = make_ref()
:telemetry.attach(handler_id, event_name, handler_function, config)
Expand Down

0 comments on commit a46281f

Please sign in to comment.