Skip to content

Commit a2fecab

Browse files
authored
Merge 3db36a3 into 4b38bb4
2 parents 4b38bb4 + 3db36a3 commit a2fecab

File tree

5 files changed

+60
-17
lines changed

5 files changed

+60
-17
lines changed

apps/opentelemetry/src/otel_tracer_default.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ with_span(Ctx, Tracer, SpanName, Opts, Fun) ->
5656
%% in this function. If spans in `Fun()' were started and not finished properly
5757
%% they will be abandoned and it be up to the `otel_span_sweeper' to eventually remove them.
5858
_ = otel_span_ets:end_span(SpanCtx),
59-
otel_ctx:attach(Ctx)
59+
otel_ctx:detach(Ctx)
6060
end.
6161

6262
-spec b3_propagators() -> {otel_propagator:text_map_extractor(), otel_propagator:text_map_injector()}.

apps/opentelemetry_api/include/otel_tracer.hrl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
-define(start_span(SpanName, StartOpts),
1111
otel_tracer:start_span(?current_tracer, SpanName, StartOpts)).
1212

13+
-define(with_span(SpanName, Fun),
14+
otel_tracer:with_span(?current_tracer, SpanName, #{}, Fun)).
15+
1316
-define(with_span(SpanName, StartOpts, Fun),
1417
otel_tracer:with_span(?current_tracer, SpanName, StartOpts, Fun)).
1518

apps/opentelemetry_api/src/otel_ctx.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
-type t() :: map().
4242
-type key() :: term().
4343
-type value() :: term().
44-
-type token() :: reference().
44+
45+
%% at this time the "token" is actually the context map itself
46+
-type token() :: term().
4547

4648
-export_type([t/0,
4749
key/0,

apps/opentelemetry_exporter/src/opentelemetry_exporter.erl

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@
4343
%% for testing
4444
-export([to_proto_by_instrumentation_library/1,
4545
to_proto/1,
46+
endpoints/1,
4647
merge_with_environment/1]).
4748

4849
-include_lib("kernel/include/logger.hrl").
4950
-include_lib("opentelemetry_api/include/opentelemetry.hrl").
5051
-include_lib("opentelemetry/include/otel_span.hrl").
5152

52-
-define(DEFAULT_ENDPOINTS, [{http, "localhost", 9090, []}]).
53+
-define(DEFAULT_ENDPOINTS, [{https, "localhost", 4317, []}]).
54+
-define(DEFAULT_PORT, 4317).
5355

5456
-record(state, {protocol :: grpc | http_protobuf | http_json,
5557
channel_pid :: pid() | undefined,
@@ -140,24 +142,43 @@ headers(_) ->
140142
[].
141143

142144
endpoints(List) when is_list(List) ->
143-
case io_lib:printable_list(List) of
144-
true ->
145-
[endpoint(uri_string:parse(List))];
145+
Endpoints = case io_lib:printable_list(List) of
146+
true ->
147+
[List];
148+
false ->
149+
List
150+
end,
151+
152+
lists:filtermap(fun endpoint/1, Endpoints);
153+
endpoints(Endpoint) ->
154+
lists:filtermap(fun endpoint/1, [Endpoint]).
155+
156+
endpoint(Endpoint) ->
157+
case parse_endpoint(Endpoint) of
146158
false ->
147-
lists:filtermap(fun endpoint/1, List)
159+
?LOG_WARNING("Failed to parse and ignoring exporter endpoint ~p", [Endpoint]),
160+
false;
161+
Parsed ->
162+
Parsed
148163
end.
149164

150-
endpoint({_, _, _, _}=E) ->
165+
parse_endpoint({_, _, _, _}=E) ->
151166
{true, E};
152-
endpoint(#{host := Host, port := Port, scheme := Scheme}) ->
153-
{true, {Scheme, Host, Port, []}};
154-
endpoint(String) ->
155-
case io_lib:printable_list(String) of
156-
true ->
157-
endpoint(uri_string:parse(String));
158-
false ->
159-
false
160-
end.
167+
parse_endpoint(#{host := Host, port := Port, scheme := Scheme}) ->
168+
{true, {scheme(Scheme), Host, Port, []}};
169+
parse_endpoint(#{host := Host, scheme := Scheme}) ->
170+
{true, {scheme(Scheme), Host, ?DEFAULT_PORT, []}};
171+
parse_endpoint(String) when is_list(String) orelse is_binary(String) ->
172+
parse_endpoint(uri_string:parse(unicode:characters_to_list(String)));
173+
parse_endpoint(_) ->
174+
false.
175+
176+
scheme(Scheme) when Scheme =:= "https" orelse Scheme =:= <<"https">> ->
177+
https;
178+
scheme(Scheme) when Scheme =:= "http" orelse Scheme =:= <<"http">> ->
179+
http;
180+
scheme(Scheme) ->
181+
Scheme.
161182

162183
merge_with_environment(Opts) ->
163184
%% exporters are initalized by calling their `init/1' function from `opentelemetry'.

apps/opentelemetry_exporter/test/opentelemetry_exporter_SUITE.erl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,23 @@ configuration(_Config) ->
4343
?assertMatch(#{endpoints := [{http, "localhost", 9090, []}]},
4444
opentelemetry_exporter:merge_with_environment(#{endpoints => [{http, "localhost", 9090, []}]})),
4545

46+
?assertMatch([{http, "localhost", 443, []}],
47+
opentelemetry_exporter:endpoints(["http://localhost:443"])),
48+
49+
?assertMatch([{http, "localhost", 443, []}],
50+
opentelemetry_exporter:endpoints([<<"http://localhost:443">>])),
51+
52+
?assertMatch([{http, "localhost", 443, []}],
53+
opentelemetry_exporter:endpoints(<<"http://localhost:443">>)),
54+
55+
?assertMatch([{http, "localhost", 443, []}],
56+
opentelemetry_exporter:endpoints(<<"http://localhost:443/ignored/path">>)),
57+
58+
?assertMatch([{http, "localhost", 4317, []}],
59+
opentelemetry_exporter:endpoints("http://localhost")),
60+
61+
?assertMatch([], opentelemetry_exporter:endpoints("://badendpoint")),
62+
4663
application:set_env(opentelemetry_exporter, otlp_endpoint, "http://localhost:5353"),
4764
?assertMatch(#{endpoints := "http://localhost:5353"},
4865
opentelemetry_exporter:merge_with_environment(#{})),

0 commit comments

Comments
 (0)