| 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(mcd_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 |
|
|
| 25 |
|
|
| 26 |
|
start_link() -> |
| 27 |
11 |
?FUNCTION_NAME(#{}). |
| 28 |
|
|
| 29 |
|
|
| 30 |
|
start_link(Arg) -> |
| 31 |
11 |
gen_statem:start_link(?MODULE, [Arg], envy_gen:options(?MODULE)). |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
init([_Arg]) -> |
| 35 |
11 |
try |
| 36 |
11 |
M = mcd_config:telemetry(module), |
| 37 |
:-( |
F = mcd_config:telemetry(function), |
| 38 |
|
|
| 39 |
:-( |
Telemetry = fun M:F/4, |
| 40 |
|
|
| 41 |
:-( |
case telemetry:attach_many( |
| 42 |
|
?MODULE, |
| 43 |
|
phrase_file:consult(mcd_config:telemetry(event_names)), |
| 44 |
|
Telemetry, |
| 45 |
|
mcd_config:telemetry(config)) of |
| 46 |
|
|
| 47 |
|
ok -> |
| 48 |
:-( |
{ok, ready, #{telemetry => Telemetry}, hibernate}; |
| 49 |
|
|
| 50 |
|
{error, Reason} -> |
| 51 |
:-( |
{stop, Reason} |
| 52 |
|
end |
| 53 |
|
|
| 54 |
|
catch |
| 55 |
|
error:badarg -> |
| 56 |
11 |
ignore |
| 57 |
|
end. |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
callback_mode() -> |
| 61 |
:-( |
handle_event_function. |
| 62 |
|
|
| 63 |
|
|
| 64 |
|
terminate(_Reason, _State, _Data) -> |
| 65 |
:-( |
telemetry:detach(?MODULE). |