You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ii...@apache.org on 2020/01/23 14:39:19 UTC
[couchdb-jaeger-passage] 04/09: Use httpc by default
This is an automated email from the ASF dual-hosted git repository.
iilyak pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb-jaeger-passage.git
commit dd36ad40df5e198bda39901e1779ed1e9f51e775
Author: ILYA Khlopotov <ii...@apache.org>
AuthorDate: Wed Jan 22 02:53:16 2020 -0800
Use httpc by default
---
src/jaeger_passage_reporter_http.erl | 18 +++++++++++++++---
test/jaeger_passage_repoter_tests.erl | 3 ++-
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/src/jaeger_passage_reporter_http.erl b/src/jaeger_passage_reporter_http.erl
index 095f3a1..0b0097c 100644
--- a/src/jaeger_passage_reporter_http.erl
+++ b/src/jaeger_passage_reporter_http.erl
@@ -74,7 +74,7 @@
| {process_tags, passage:tags()}.
%% <ul>
%% <li><b>endpoint</b>: The jaeger endpoint URL for sending thrift messages. The default value is `http://127.0.0.1:14268'.</li>
-%% <li><b>http_client</b>: The callback to call to send span to jaeger.</li>
+%% <li><b>http_client</b>: The callback to call to send span to jaeger. The httpc client is used by default.</li>
%% <li><b>default_service_name</b>: The default service name. If a reporting span has `location.application' tag, the value is used as the service name instead of this. The default value is `ReporterId'.</li>
%% <li><b>process_tags</b>: The tags of the reporting process. The default value is `#{}'.</li>
%% </ul>
@@ -112,8 +112,8 @@ init({ReporterId, Options}) ->
Endpoint = proplists:get_value(endpoint, Options, "http://127.0.0.1:14268"),
EndpointURL = Endpoint ++ "/api/traces",
- HttpClient = proplists:get_value(http_client, Options),
- HttpClient =/= undefined orelse error(badarg, [ReporterId, Options]),
+ HttpClient = proplists:get_value(http_client, Options, fun httpc_client/5),
+ is_function(HttpClient, 5) orelse error(badarg, [ReporterId, Options]),
DefaultServiceName = proplists:get_value(default_service_name, Options, ReporterId),
Tags0 = proplists:get_value(process_tags, Options, #{}),
@@ -171,3 +171,15 @@ handle_report(Span, State = #?STATE{default_service_name = DefaultName, process_
Headers = [?CONTENT_TYPE],
HttpClient(URI, post, Headers, Encoded, Options),
{noreply, State}.
+
+-spec httpc_client(
+ Url :: string(),
+ Method :: post,
+ Headers :: [{string(), string()}],
+ Body :: string() | binary(),
+ ReporterOptions :: start_options()) ->
+ ok.
+
+httpc_client(Url, Method, _Headers, Body, _ReporterOptions) ->
+ httpc:request(Method, {Url, [], "application/x-thrift", Body}, [], []),
+ ok.
diff --git a/test/jaeger_passage_repoter_tests.erl b/test/jaeger_passage_repoter_tests.erl
index 7f034bb..cdc25a5 100644
--- a/test/jaeger_passage_repoter_tests.erl
+++ b/test/jaeger_passage_repoter_tests.erl
@@ -64,7 +64,8 @@ error_http_test() ->
%% Starts `http_reporter'
?assertMatch({error, {{badarg, _}, _}}, jaeger_passage_reporter:start(http_reporter, [
- {protocol, http}
+ {protocol, http},
+ {http_client, undefined}
])),
%% Starts `http_reporter'