Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Dialyzer issues #4

Merged
merged 5 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions lib/telemetry_metrics.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ 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)
# @enabled Application.compile_env(:membrane_telemetry_metrics, :enabled, false)
# @events Application.compile_env(:membrane_telemetry_metrics, :events, :all)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


@type label() :: list()

Expand Down Expand Up @@ -84,12 +84,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