Skip to content

Commit b4a85e1

Browse files
author
Tristan Sloughter
committed
clean up type specs for get_ and set_ tracer
1 parent 79f2811 commit b4a85e1

File tree

2 files changed

+40
-22
lines changed

2 files changed

+40
-22
lines changed

apps/opentelemetry_api/src/opentelemetry.erl

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,20 @@ set_default_tracer(Tracer) ->
148148

149149
-spec set_tracer(atom(), tracer()) -> boolean().
150150
set_tracer(Name, Tracer) ->
151-
verify_and_set_term(Tracer, ?TRACER_KEY(Name), otel_tracer).
151+
set_tracer(Name, <<>>, undefined, Tracer).
152152

153-
-spec set_tracer(atom(), unicode:unicode_binary(), uri_string:uri_string(), tracer()) -> boolean().
153+
-spec set_tracer(Name, Vsn, SchemaUrl, Tracer) -> boolean() when
154+
Name :: atom(),
155+
Vsn :: unicode:chardata() | undefined,
156+
SchemaUrl :: uri_string:uri_string() | undefined,
157+
Tracer:: opentelemetry:tracer().
154158
set_tracer(Name, Vsn, SchemaUrl, Tracer) ->
155159
verify_and_set_term(Tracer, ?TRACER_KEY({Name, Vsn, SchemaUrl}), otel_tracer).
156160

157-
-spec create_application_tracers([{atom(), string(), string()}]) -> ok.
161+
-spec create_application_tracers([{Application, Description, Vsn}]) -> ok when
162+
Application :: atom(),
163+
Description :: string(),
164+
Vsn :: string().
158165
create_application_tracers(Applications) ->
159166
TracerMap = lists:foldl(fun({Name, _Description, Version}, Acc) ->
160167
Vsn = vsn_to_binary(Version),
@@ -175,15 +182,23 @@ module_to_application(Name, Version, SchemaUrl) ->
175182
get_tracer() ->
176183
persistent_term:get(?DEFAULT_TRACER_KEY, {otel_tracer_noop, []}).
177184

178-
-spec get_tracer(atom() | {atom(), unicode:chardata(), uri_string:uri_string()}) -> tracer().
185+
-spec get_tracer(Name) -> Tracer when
186+
Name :: atom() | {Name, Vsn, SchemaUrl},
187+
Vsn :: unicode:chardata() | undefined,
188+
SchemaUrl :: uri_string:uri_string() | undefined,
189+
Tracer:: opentelemetry:tracer().
179190
get_tracer('$__default_tracer') ->
180191
get_tracer();
181192
get_tracer({Name, Vsn, SchemaUrl}) ->
182193
get_tracer(Name, Vsn, SchemaUrl);
183194
get_tracer(Name) ->
184195
get_tracer(Name, undefined, undefined).
185196

186-
-spec get_tracer(atom(), unicode:chardata(), uri_string:uri_string()) -> tracer().
197+
-spec get_tracer(Name, Vsn, SchemaUrl) -> Tracer when
198+
Name :: atom(),
199+
Vsn :: unicode:chardata() | undefined,
200+
SchemaUrl :: uri_string:uri_string() | undefined,
201+
Tracer:: opentelemetry:tracer().
187202
get_tracer(Name, Vsn, SchemaUrl) ->
188203
%% check cache and then use provider to get the tracer if it isn't cached yet
189204
case persistent_term:get(?TRACER_KEY({Name, Vsn, SchemaUrl}), undefined) of
@@ -203,10 +218,14 @@ get_tracer(Name, Vsn, SchemaUrl) ->
203218
get_application_tracer(ModuleName) ->
204219
get_tracer(get_application(ModuleName)).
205220

206-
%% looks up the name of the OTP Application a module is in. This name is used to
207-
%% look up a Tracer to use so if none is found for the ModuleName the key used for
208-
%% the default tracer
209-
-spec get_application(module()) -> {atom(), unicode:unicode_binary() | undefined, uri_string:uri_string() | undefined} | atom().
221+
%% looks up the name, version and schema_url used to create a Trace for the OTP
222+
%% Application a module is in. This name is used to look up a Tracer to use so
223+
%% if none is found for the ModuleName the key used for the default tracer.
224+
-spec get_application(module()) -> ApplicationTuple when
225+
ApplicationTuple :: {Name, Vsn, SchemaUrl} | atom(),
226+
Name :: atom(),
227+
Vsn :: unicode:unicode_binary() | undefined,
228+
SchemaUrl :: uri_string:uri_string() | undefined.
210229
get_application(ModuleName) ->
211230
Map = persistent_term:get(?MODULE_TO_APPLICATION_KEY, #{}),
212231
maps:get(ModuleName, Map, '$__default_tracer').

apps/opentelemetry_api/src/otel_tracer_provider.erl

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,26 @@
2121
%%%-------------------------------------------------------------------------
2222
-module(otel_tracer_provider).
2323

24-
-export([get_tracer/1,
25-
get_tracer/2,
26-
get_tracer/3,
24+
-export([get_tracer/3,
2725
resource/0,
2826
resource/1,
2927
force_flush/0,
3028
force_flush/1]).
3129

32-
-spec get_tracer(atom()) -> boolean().
33-
get_tracer(Name) ->
34-
get_tracer(?MODULE, Name, undefined, undefined).
35-
36-
-spec get_tracer(atom(), binary() | undefined) -> boolean().
37-
get_tracer(Name, Vsn) ->
38-
get_tracer(?MODULE, Name, Vsn, undefined).
39-
40-
-spec get_tracer(atom(), binary() | undefined, uri_string:uri_string() | undefined) -> boolean().
30+
-spec get_tracer(Name, Vsn, SchemaUrl) -> Tracer when
31+
Name :: atom(),
32+
Vsn :: unicode:chardata() | undefined,
33+
SchemaUrl :: uri_string:uri_string() | undefined,
34+
Tracer:: opentelemetry:tracer().
4135
get_tracer(Name, Vsn, SchemaUrl) ->
4236
get_tracer(?MODULE, Name, Vsn, SchemaUrl).
4337

44-
-spec get_tracer(atom() | pid(), atom(), binary() | undefined, uri_string:uri_string() | undefined) -> boolean().
38+
-spec get_tracer(ServerRef, Name, Vsn, SchemaUrl) -> Tracer when
39+
ServerRef :: atom() | pid(),
40+
Name :: atom(),
41+
Vsn :: unicode:chardata() | undefined,
42+
SchemaUrl :: uri_string:uri_string() | undefined,
43+
Tracer:: opentelemetry:tracer().
4544
get_tracer(ServerRef, Name, Vsn, SchemaUrl) ->
4645
try
4746
gen_server:call(ServerRef, {get_tracer, Name, Vsn, SchemaUrl})

0 commit comments

Comments
 (0)