_site/cover/msc_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(msc_telemetry).
17
18
19 -export([callback_mode/0]).
20 -export([init/1]).
21 -export([start_link/0]).
22 -export([terminate/3]).
23 -include_lib("kernel/include/logger.hrl").
24
25
26 start_link() ->
27 1 gen_statem:start_link(?MODULE, [], envy_gen:options(?MODULE)).
28
29
30 init([]) ->
31 1 try
32 1 M = msc_config:telemetry(module),
33
:-(
F = msc_config:telemetry(function),
34
35
:-(
Telemetry = fun M:F/4,
36
37
:-(
case telemetry:attach_many(
38 ?MODULE,
39 phrase_file:consult(msc_config:telemetry(event_names)),
40 fun M:F/4,
41 msc_config:telemetry(config)) of
42
43 ok ->
44
:-(
{ok, ready, #{telemetry => Telemetry}, hibernate};
45
46 {error, Reason} ->
47
:-(
{stop, Reason}
48 end
49
50 catch
51 error:badarg ->
52 1 ?LOG_NOTICE(#{?MODULE => "no configuration"}),
53 1 ignore
54 end.
55
56
57 callback_mode() ->
58
:-(
handle_event_function.
59
60
61 terminate(_Reason, _State, _Data) ->
62
:-(
telemetry:detach(?MODULE).
Line Hits Source