Skip to content

Commit

Permalink
fixup! fixup! Add telemetry support
Browse files Browse the repository at this point in the history
  • Loading branch information
kmakiela committed Feb 20, 2020
1 parent 1e6522f commit 5fb88a5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
24 changes: 24 additions & 0 deletions lib/mongoose_push.ex
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,30 @@ defmodule MongoosePush do
:timer.tc(module, :push, [notification, device_id, pool, opts])
end

:telemetry.execute(
[:mpush, :push],

This comment has been minimized.

Copy link
@rslota

rslota Feb 20, 2020

Contributor

I know it's tempting to shorten the name of this app, but I would suggest to keep this one as a "rule" - always using full application name as first element of event name.

%{time: time},
case push_result do

This comment has been minimized.

Copy link
@rslota

rslota Feb 20, 2020

Contributor

let's not use case as argument. It's better to extract that to external function if needed.

{:error, {type, reason}} ->
%{
result: :error,
type: type,
reason: reason
}

{:error, reason} ->

This comment has been minimized.

Copy link
@rslota

rslota Feb 20, 2020

Contributor

Is that actually possible? If so, we should add the type either way to the event, as the same events always should have matching metadata keys.

This comment has been minimized.

Copy link
@kmakiela

kmakiela Feb 25, 2020

Author Contributor

That way when handling the events we have to have a clause for each error type. Additionally don't we just want to pass the type and don't do anything specific based on the type error?

%{
result: :error,
reason: reason
}

other ->
%{
result: other
}
end
)

push_result
|> Metrics.update(:spiral, [:push, service, mode])
|> Metrics.update(:timer, [:push, service, mode], time)
Expand Down
20 changes: 2 additions & 18 deletions lib/mongoose_push/metrics.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,13 @@ defmodule MongoosePush.Metrics do

defmacro update_metric(:spiral, metric, value) do
quote bind_quoted: [metric: metric, value: value], unquote: true do
:telemetry.execute(
[:mpush, :metric, :spiral],
%{
value: value
},
%{
metric: metric
}
)
Elixometer.update_spiral(metric, value)
end
end

defmacro update_metric(:timer, metric, value) do
quote bind_quoted: [metric: metric, value: value], unquote: true do
:telemetry.execute(
[:mpush, :metric, :timer],
%{
value: value
},
%{
metric: metric
}
)
Elixometer.Updater.timer(metric, :microsecond, value)
end
end

Expand Down
5 changes: 2 additions & 3 deletions lib/mongoose_push/telemetry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ defmodule MongoosePush.Telemetry do
def attach_metrics do
_res =
:telemetry.attach_many(
"metrics-handler",
"handler",
[
[:mpush, :metric, :spiral],
[:mpush, :metric, :timer]
[:mpush, :push]
],
&MongoosePush.Telemetry.handle_event/4,
nil
Expand Down
10 changes: 2 additions & 8 deletions lib/mongoose_push/telemetry/handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@ defmodule MongoosePush.Telemetry.Handler do
{:ok, %{}}
end

def handle_cast({[:mpush, :metric, :spiral], measurements, metadata, _}, state) do
Elixometer.update_spiral(metadata.metric, measurements.value)

{:noreply, state}
end

def handle_cast({[:mpush, :metric, :timer], measurements, metadata, _}, state) do
Elixometer.Updater.timer(metadata.metric, :microsecond, measurements.value)
def handle_cast({[:mpush, :push], measurements, metadata, _}, state) do
IO.inspect([measurements, metadata])

{:noreply, state}
end
Expand Down

0 comments on commit 5fb88a5

Please sign in to comment.