_site/cover/resp_telemetry.COVER.html

1 %% Copyright (c) 2023 Peter Morgan <peter.james.morgan@gmail.com>
2 %%
3 %% Licensed under the Apache License, Version 2.0 (the "License");
4 %% you may not use this file except in compliance with the License.
5 %% You may obtain a copy of the License at
6 %%
7 %% http://www.apache.org/licenses/LICENSE-2.0
8 %%
9 %% Unless required by applicable law or agreed to in writing, software
10 %% distributed under the License is distributed on an "AS IS" BASIS,
11 %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 %% See the License for the specific language governing permissions and
13 %% limitations under the License.
14
15
16 -module(resp_telemetry).
17
18
19 -export([callback_mode/0]).
20 -export([init/1]).
21 -export([start_link/0]).
22 -export([start_link/1]).
23 -export([terminate/3]).
24 -include_lib("kernel/include/logger.hrl").
25
26
27 start_link() ->
28
:-(
?FUNCTION_NAME(#{}).
29
30
31 start_link(Arg) ->
32
:-(
gen_statem:start_link(?MODULE, [Arg], envy_gen:options(?MODULE)).
33
34
35 init([_Arg]) ->
36
:-(
try
37
:-(
M = resp_config:telemetry(module),
38
:-(
F = resp_config:telemetry(function),
39
40
:-(
Telemetry = fun M:F/4,
41
42
:-(
case telemetry:attach_many(
43 ?MODULE,
44 phrase_file:consult(resp_config:telemetry(event_names)),
45 Telemetry,
46 resp_config:telemetry(config)) of
47 ok ->
48
:-(
{ok, ready, #{telemetry => Telemetry}, hibernate};
49
50 {error, Reason} ->
51
:-(
{stop, Reason}
52 end
53
54 catch
55 error:badarg ->
56
:-(
?LOG_NOTICE(#{?MODULE => "no configuration"}),
57
:-(
ignore
58 end.
59
60
61 callback_mode() ->
62
:-(
handle_event_function.
63
64
65 terminate(_Reason, _State, _Data) ->
66
:-(
telemetry:detach(?MODULE).
Line Hits Source