-
Notifications
You must be signed in to change notification settings - Fork 3
/
telemetry.ex
44 lines (37 loc) · 1.03 KB
/
telemetry.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
defmodule PrimaAuth0Ex.Telemetry do
@moduledoc """
A pre-defined module which sets up telemetry with a given reporter
"""
alias PrimaAuth0Ex.Config
alias PrimaAuth0Ex.Telemetry.Handler
@auth0_handler_id "auth0-handler"
def setup do
reporter = telemetry_reporter()
if reporter != nil do
:ok =
:telemetry.attach_many(
@auth0_handler_id,
[
[:prima_auth0_ex, :retrieve_token, :failure],
[:prima_auth0_ex, :retrieve_token, :success]
],
&Handler.handle_event/4,
%{reporter: reporter}
)
end
end
defp telemetry_reporter, do: Config.telemetry_reporter()
end
defmodule PrimaAuth0Ex.Telemetry.Handler do
@moduledoc """
A pre-defined telemetry handler
"""
def handle_event(
[:prima_auth0_ex, :retrieve_token, status],
%{count: count},
%{audience: audience},
%{reporter: reporter}
) do
reporter.increment("auth0.token", count, tags: ["audience:#{audience}", "status:#{status}"])
end
end