Skip to content

Commit

Permalink
only check that module exists since behaviour could be stripped
Browse files Browse the repository at this point in the history
  • Loading branch information
tsloughter committed Nov 2, 2020
1 parent 8122151 commit 23cc432
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions apps/opentelemetry_api/src/opentelemetry.erl
Original file line number Diff line number Diff line change
Expand Up @@ -355,30 +355,24 @@ uniform(X) ->

-spec verify_and_set_term(module() | {module(), term()}, term(), atom()) -> boolean().
verify_and_set_term(Module, TermKey, Behaviour) ->
case verify_behaviour(Module, Behaviour) of
case verify_module_exists(Module) of
true ->
persistent_term:put({?MODULE, TermKey}, Module),
true;
false ->
?LOG_WARNING("Module ~p does not implement behaviour ~p. "
"A noop ~p will be used until a module implementing "
"the behaviour is configured.",
?LOG_WARNING("Module ~p does not exist. "
"A noop ~p will be used until a module is configured.",
[Module, Behaviour, Behaviour]),
false
end.

-spec verify_behaviour(module() | {module(), term()}, atom()) -> boolean().
verify_behaviour({Module, _}, Behaviour) ->
verify_behaviour(Module, Behaviour);
verify_behaviour(Module, Behaviour) ->
try Module:module_info(attributes) of
Attributes ->
case lists:keyfind(behaviour, 1, Attributes) of
{behaviour, Behaviours} ->
lists:member(Behaviour, Behaviours);
_ ->
false
end
-spec verify_module_exists(module() | {module(), term()}) -> boolean().
verify_module_exists({Module, _}) ->
verify_module_exists(Module);
verify_module_exists(Module) ->
try Module:module_info() of
_ ->
true
catch
error:undef ->
false
Expand Down

0 comments on commit 23cc432

Please sign in to comment.