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:15 UTC

[couchdb-jaeger-passage] branch master updated (690c699 -> 8613f13)

This is an automated email from the ASF dual-hosted git repository.

iilyak pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb-jaeger-passage.git.


    from 690c699  v0.1.13
     new 076192b  Update thrift_protocol to 0.1.5
     new c4edcbf  Add HTTP reporter
     new 3672386  Add test case for http_reporter
     new dd36ad4  Use httpc by default
     new e080c97  Merge pull request #3 from iilyak/add-http-reporter
     new 7321632  Use default value.
     new 82f8fd0  Update documentation
     new c04ce6a  Add OTP-22 as a CI target
     new 8613f13  v0.1.14

The 9 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .travis.yml                                        |   1 +
 README.md                                          |  18 ++
 rebar.config.script                                |   2 +-
 rebar.lock                                         |   4 +-
 src/jaeger_passage.app.src                         |   3 +-
 src/jaeger_passage.erl                             |   2 +-
 src/jaeger_passage_reporter.erl                    | 132 ++-------------
 src/jaeger_passage_reporter_http.erl               | 183 +++++++++++++++++++++
 src/jaeger_passage_reporter_sup.erl                |   9 +-
 ...eporter.erl => jaeger_passage_reporter_udp.erl} |  98 ++---------
 src/jaeger_passage_thrift.erl                      |   8 +-
 test/jaeger_passage_repoter_tests.erl              |  60 ++++++-
 12 files changed, 296 insertions(+), 224 deletions(-)
 create mode 100644 src/jaeger_passage_reporter_http.erl
 copy src/{jaeger_passage_reporter.erl => jaeger_passage_reporter_udp.erl} (64%)


[couchdb-jaeger-passage] 09/09: v0.1.14

Posted by ii...@apache.org.
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 8613f138ebd14e238c4e9ef9c5c24b9ff653e8ba
Author: Takeru Ohta <ph...@gmail.com>
AuthorDate: Thu Jan 23 22:31:43 2020 +0900

    v0.1.14
---
 src/jaeger_passage.app.src | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/jaeger_passage.app.src b/src/jaeger_passage.app.src
index 0cc50ac..ad3701f 100644
--- a/src/jaeger_passage.app.src
+++ b/src/jaeger_passage.app.src
@@ -1,12 +1,11 @@
 {application,jaeger_passage,
              [{description,"Jaeger client library for Erlang"},
-              {vsn,"0.1.13"},
+              {vsn,"0.1.14"},
               {registered,[]},
               {mod,{jaeger_passage_app,[]}},
               {applications,[kernel,stdlib,inets,local,passage,
                              thrift_protocol]},
               {env,[]},
               {modules,[]},
-              {maintainers,["Takeru Ohta"]},
               {licenses,["MIT"]},
               {links,[{"GitHub","https://github.com/sile/jaeger_passage"}]}]}.


[couchdb-jaeger-passage] 06/09: Use default value.

Posted by ii...@apache.org.
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 732163262cea64b8c365e296f627ac170744e09b
Author: Takeru Ohta <ph...@gmail.com>
AuthorDate: Thu Jan 23 21:40:42 2020 +0900

    Use default value.
---
 src/jaeger_passage_reporter.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/jaeger_passage_reporter.erl b/src/jaeger_passage_reporter.erl
index 1287f48..a2a4a68 100644
--- a/src/jaeger_passage_reporter.erl
+++ b/src/jaeger_passage_reporter.erl
@@ -87,7 +87,7 @@
 -spec start(reporter_id()) -> {ok, passage_reporter:reporter()} | {error, Reason} when
       Reason :: {already_started, pid()} | term().
 start(ReporterId) ->
-    start(ReporterId, [{protocol, udp}]).
+    start(ReporterId, []).
 
 %% @doc Starts a reporter process.
 -spec start(reporter_id(), start_options()) -> {ok, Reporter} | {error, Reason} when


[couchdb-jaeger-passage] 08/09: Add OTP-22 as a CI target

Posted by ii...@apache.org.
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 c04ce6aee005e9d3633f43cf20241750d371ff3a
Author: Takeru Ohta <ph...@gmail.com>
AuthorDate: Thu Jan 23 22:29:03 2020 +0900

    Add OTP-22 as a CI target
---
 .travis.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.travis.yml b/.travis.yml
index 175deb4..72329f7 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,6 +2,7 @@ language: erlang
 
 os: linux
 otp_release:
+  - 22.0
   - 21.0
   - 20.0
   - 19.3


[couchdb-jaeger-passage] 01/09: Update thrift_protocol to 0.1.5

Posted by ii...@apache.org.
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 076192ba899dbd9b635948d7ba47ed3fb261bc78
Author: ILYA Khlopotov <ii...@apache.org>
AuthorDate: Tue Jan 21 03:32:46 2020 -0800

    Update thrift_protocol to 0.1.5
---
 rebar.config.script | 2 +-
 rebar.lock          | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/rebar.config.script b/rebar.config.script
index 4454cdc..74eb314 100644
--- a/rebar.config.script
+++ b/rebar.config.script
@@ -5,7 +5,7 @@ Rebar2Deps =
   [
    {local, ".*", {git, "https://github.com/sile/local.git", {tag, "0.2.1"}}},
    {passage, ".*", {git, "https://github.com/sile/passage.git", {tag, "0.2.6"}}},
-   {thrift_protocol, ".*", {git, "https://github.com/sile/thrift_protocol.git", {tag, "0.1.3"}}}
+   {thrift_protocol, ".*", {git, "https://github.com/sile/thrift_protocol.git", {tag, "0.1.5"}}}
   ],
 
 case IsRebar3 of
diff --git a/rebar.lock b/rebar.lock
index c9ba4ec..9d5110a 100644
--- a/rebar.lock
+++ b/rebar.lock
@@ -1,10 +1,10 @@
 {"1.1.0",
 [{<<"local">>,{pkg,<<"local">>,<<"0.2.1">>},0},
  {<<"passage">>,{pkg,<<"passage">>,<<"0.2.6">>},0},
- {<<"thrift_protocol">>,{pkg,<<"thrift_protocol">>,<<"0.1.3">>},0}]}.
+ {<<"thrift_protocol">>,{pkg,<<"thrift_protocol">>,<<"0.1.5">>},0}]}.
 [
 {pkg_hash,[
  {<<"local">>, <<"F82483CD6DB6A39B0E4C59B37C2FCCCF5B96D90A746AFC3D79A81D31E3D40963">>},
  {<<"passage">>, <<"7B0A6F0A6806B056DC3323A6A0243503642E6425F45E33B87277EA0BE88BD130">>},
- {<<"thrift_protocol">>, <<"CDD0C06BFC235159D789353CBB4F01F9FF04592F30329CB3DF2C77E28D92CCC0">>}]}
+ {<<"thrift_protocol">>, <<"300DB7CA06BED397406A4680AD3DD3A0212AC7BEABDC81FA03C3C3DADEA13673">>}]}
 ].


[couchdb-jaeger-passage] 02/09: Add HTTP reporter

Posted by ii...@apache.org.
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 c4edcbf558e939e3279dc88fc7beb528befa2be0
Author: ILYA Khlopotov <ii...@apache.org>
AuthorDate: Wed Jan 15 08:13:07 2020 -0800

    Add HTTP reporter
    
    The reporter can be configured using the following:
    
    ```
    % Define http client callback
    Client = fun(Url, Method, Headers, Body, ReporterOptions) ->
        ibrowse:send_req(Url, Headers, Method, Body, [])
    end.
    
    [
        {protocol, http},
        {endpoint, "http://127.0.0.1:14268"},
        {http_client, HttpClient}
    ]
    ```
---
 README.md                                          |  18 +++
 src/jaeger_passage.erl                             |   2 +-
 src/jaeger_passage_reporter.erl                    | 138 ++++----------------
 ...porter.erl => jaeger_passage_reporter_http.erl} | 142 ++++++---------------
 src/jaeger_passage_reporter_sup.erl                |   9 +-
 ...eporter.erl => jaeger_passage_reporter_udp.erl} |  79 +-----------
 src/jaeger_passage_thrift.erl                      |   8 +-
 7 files changed, 100 insertions(+), 296 deletions(-)

diff --git a/README.md b/README.md
index ddfd2a6..078eee6 100644
--- a/README.md
+++ b/README.md
@@ -45,6 +45,23 @@ Browses the tracing result:
 $ firefox http://localhost:16686/
 ```
 
+Selecting reporter
+------------------
+
+By default 'compact' jaeger.thrift over UDP reporter is used. However it is
+possible to select different reporter. Bellow is a configuration matrics for
+available options:
+
+| protocol | thrift_protocol | jaeger port | description                      |
+|----------|-----------------|-------------|----------------------------------|
+| udp      | compact         | 6831        | accept jaeger.thrift over compact thrift protocol (default) |
+| udp      | binary          | 6832        | accept jaeger.thrift over binary thrift protocol |
+| http     | N/A             | 14268       | accept jaeger.thrift directly from clients |
+
+The HTTP version is beneficial if you don't have jaeger agents deployed or your
+spans are greater than max udp packet size (65Kb).
+Otherwise it is better to use default.
+
 References
 -----------
 
@@ -52,3 +69,4 @@ References
 - [Jaeger](https://uber.github.io/jaeger/)
 - [jaeger-client-go/README.md](https://github.com/jaegertracing/jaeger-client-go/blob/v2.9.0/README.md)
 - [Jaeger Client Library](https://github.com/jaegertracing/jaeger/blob/master/docs/client_libraries.md)
+- [Jaeger default ports](https://www.jaegertracing.io/docs/1.8/getting-started/)
\ No newline at end of file
diff --git a/src/jaeger_passage.erl b/src/jaeger_passage.erl
index 50c5aa5..cf27120 100644
--- a/src/jaeger_passage.erl
+++ b/src/jaeger_passage.erl
@@ -33,7 +33,7 @@
       Tracer :: passage:tracer_id(),
       Sampler :: passage_sampler:sampler().
 start_tracer(Tracer, Sampler) ->
-    start_tracer(Tracer, Sampler, []).
+    start_tracer(Tracer, Sampler, [{protocol, udp}]).
 
 %% @doc Starts a tracer for Jaeger.
 %%
diff --git a/src/jaeger_passage_reporter.erl b/src/jaeger_passage_reporter.erl
index 32f537e..1287f48 100644
--- a/src/jaeger_passage_reporter.erl
+++ b/src/jaeger_passage_reporter.erl
@@ -29,7 +29,6 @@
 -module(jaeger_passage_reporter).
 
 -behaviour(passage_reporter).
--behaviour(gen_server).
 
 -include("constants.hrl").
 
@@ -45,36 +44,11 @@
 -export_type([start_option/0, start_options/0]).
 
 %%------------------------------------------------------------------------------
-%% Application Internal API
-%%------------------------------------------------------------------------------
--export([start_link/2]).
-
-%%------------------------------------------------------------------------------
 %% 'passage_reporter' Callback API
 %%------------------------------------------------------------------------------
 -export([report/2]).
 
 %%------------------------------------------------------------------------------
-%% 'gen_server' Callback API
-%%------------------------------------------------------------------------------
--export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
-
-%%------------------------------------------------------------------------------
-%% Macros & Records
-%%------------------------------------------------------------------------------
--define(STATE, ?MODULE).
-
--record(?STATE,
-        {
-          socket               :: gen_udp:socket(),
-          thrift_format        :: thrift_protocol:format(),
-          agent_host           :: inet:hostname(),
-          agent_port           :: inet:port_number(),
-          default_service_name :: atom(),
-          process_tags         :: passage:tags()
-        }).
-
-%%------------------------------------------------------------------------------
 %% Exported Types
 %%------------------------------------------------------------------------------
 -type reporter_id() :: atom().
@@ -83,28 +57,28 @@
 -type start_options() :: [start_option()].
 %% Options for {@link start/2}.
 
--type start_option() :: {thrift_format, thrift_protocol:format()}
-                      | {agent_host, inet:hostname()}
-                      | {agent_port, inet:port_number()}
+-type start_option() :: jaeger_passage_reporter_udp:start_option()
+                      | jaeger_passage_reporter_http:start_option()
+                      | {protocol, udp | http}
                       | {default_service_name, atom()}
                       | {process_tags, passage:tags()}.
+
+%% Common reporter options
+%% <ul>
+%%   <li><b>protocol</b>: Communication protocol used to connect to jaeger. The value is used to select reporter module. Possible values are: `udp' | `http'. The default value is `udp'.</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>
+%% UDP reporter specific options
 %% <ul>
 %%   <li><b>thrift_format</b>: The format for encoding thrift messages. The default value is `compact'.</li>
 %%   <li><b>agent_host</b>: The hostname of the jaeger agent. The default value is `"127.0.0.1"'.</li>
 %%   <li><b>agent_port</b>: The port of the jaeger agent. The default values for the thrift format `compact' and `binary' are `6831' and `6832' respectively.</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>
-
-%%------------------------------------------------------------------------------
-%% Application Internal Functions
-%%------------------------------------------------------------------------------
-%% @private
--spec start_link(reporter_id(), start_options()) -> {ok, pid()} | {error, Reason} when
-      Reason :: {already_started, pid()} | term().
-start_link(ReporterId, Options) ->
-    Name = jaeger_passage_local_ns:reporter_name(ReporterId),
-    gen_server:start_link(Name, ?MODULE, {ReporterId, Options}, []).
+%% HTTP reporter specific options
+%% <ul>
+%%   <li><b>endpoint</b>: The jaeger endpoint URL for sending thrift messages. The default value is `http://127.0.0.1:14268'.</li>
+%% </ul>
 
 %%------------------------------------------------------------------------------
 %% Exported Functions
@@ -113,7 +87,7 @@ start_link(ReporterId, Options) ->
 -spec start(reporter_id()) -> {ok, passage_reporter:reporter()} | {error, Reason} when
       Reason :: {already_started, pid()} | term().
 start(ReporterId) ->
-    start(ReporterId, []).
+    start(ReporterId, [{protocol, udp}]).
 
 %% @doc Starts a reporter process.
 -spec start(reporter_id(), start_options()) -> {ok, Reporter} | {error, Reason} when
@@ -123,8 +97,13 @@ start(ReporterId, Options) ->
     Args = [ReporterId, Options],
     is_atom(ReporterId) orelse error(badarg, Args),
     is_list(Options) orelse error(badarg, Args),
-
-    case jaeger_passage_reporter_sup:start_child(ReporterId, Options) of
+    ReporterModule = case proplists:get_value(protocol, Options, udp) of
+        udp -> jaeger_passage_reporter_udp;
+        http -> jaeger_passage_reporter_http;
+        _ -> error(badarg, Args)
+    end,
+    ReporterOptions = proplists:delete(protocol, Options),
+    case jaeger_passage_reporter_sup:start_child(ReporterId, ReporterModule, ReporterOptions) of
         {error, Reason} -> {error, Reason};
         {ok, _Pid}      -> {ok, passage_reporter:new(?MODULE, ReporterId)}
     end.
@@ -158,74 +137,3 @@ get_id(Reporter) ->
 report(ReporterId, Span) ->
     Server = jaeger_passage_local_ns:reporter_name(ReporterId),
     gen_server:cast(Server, {report, Span}).
-
-%%------------------------------------------------------------------------------
-%% 'gen_server' Callback Functions
-%%------------------------------------------------------------------------------
-%% @private
-init({ReporterId, Options}) ->
-    Format = proplists:get_value(thrift_format, Options, compact),
-    DefaultPort =
-        case Format of
-            compact -> 6831;
-            binary  -> 6832
-        end,
-    AgentHost = proplists:get_value(agent_host, Options, "127.0.0.1"),
-    AgentPort = proplists:get_value(agent_port, Options, DefaultPort),
-    DefaultServiceName = proplists:get_value(default_service_name, Options, ReporterId),
-    Tags0 = proplists:get_value(process_tags, Options, #{}),
-
-    {ok, Hostname} = inet:gethostname(),
-    {ok, Version} = application:get_key(vsn),
-    Tags1 =
-        maps:merge(
-          Tags0,
-          #{
-            ?JAEGER_CLIENT_VERSION_TAG_KEY => list_to_binary(["jaeger_passage-", Version]),
-            ?TRACER_HOSTNAME_TAG_KEY => list_to_binary(Hostname),
-            'erlang.node' => node()
-           }),
-    {ok, Socket} = gen_udp:open(0),
-    State =
-        #?STATE{
-            socket        = Socket,
-            thrift_format = Format,
-            agent_host    = AgentHost,
-            agent_port    = AgentPort,
-            default_service_name  = DefaultServiceName,
-            process_tags  = Tags1
-           },
-    {ok, State}.
-
-%% @private
-handle_call(_Request, _From, State) ->
-    {noreply, State}.
-
-%% @private
-handle_cast({report, Span}, State) ->
-    handle_report(Span, State);
-handle_cast(_Request, State) ->
-    {noreply, State}.
-
-%% @private
-handle_info(_Info, State) ->
-    {noreply, State}.
-
-%% @private
-terminate(_Reason, _State) ->
-    ok.
-
-%% @private
-code_change(_OldVsn, State, _Extra) ->
-    {ok, State}.
-
-%%------------------------------------------------------------------------------
-%% Internal Functions
-%%------------------------------------------------------------------------------
--spec handle_report(passage_span:span(), #?STATE{}) -> {noreply, #?STATE{}}.
-handle_report(Span, State = #?STATE{default_service_name = DefaultName, process_tags = Tags}) ->
-    Name = maps:get('location.application', passage_span:get_tags(Span), DefaultName),
-    Message = jaeger_passage_thrift:make_emit_batch_message(Name, Tags, [Span]),
-    Encoded = thrift_protocol:encode_message(Message, State#?STATE.thrift_format),
-    ok = gen_udp:send(State#?STATE.socket, State#?STATE.agent_host, State#?STATE.agent_port, Encoded),
-    {noreply, State}.
diff --git a/src/jaeger_passage_reporter.erl b/src/jaeger_passage_reporter_http.erl
similarity index 53%
copy from src/jaeger_passage_reporter.erl
copy to src/jaeger_passage_reporter_http.erl
index 32f537e..095f3a1 100644
--- a/src/jaeger_passage_reporter.erl
+++ b/src/jaeger_passage_reporter_http.erl
@@ -1,12 +1,10 @@
-%% @copyright 2017 Takeru Ohta <ph...@gmail.com>
-%%
 %% @doc A reporter that sends the spans to an jaeger agent
 %%
 %% === Examples ===
 %%
 %% ```
 %% %% Starts `example_reporter'
-%% {ok, Reporter} = jaeger_passage_reporter:start(example_reporter).
+%% {ok, Reporter} = jaeger_passage_reporter:start(example_reporter, [{protocol, http}]).
 %% [example_reporter] = jaeger_passage_reporter:which_reporters().
 %%
 %% %% Registers `example_tracer'
@@ -26,9 +24,8 @@
 %% <li><a href="http://jaeger.readthedocs.io/en/latest/architecture/#agent">Jaeger - Architecture - Agent</a></li>
 %% <li><a href="http://jaeger.readthedocs.io/en/latest/deployment/#agent">Jaeger - Deployment - Agent</a></li>
 %% </ul>
--module(jaeger_passage_reporter).
+-module(jaeger_passage_reporter_http).
 
--behaviour(passage_reporter).
 -behaviour(gen_server).
 
 -include("constants.hrl").
@@ -36,12 +33,6 @@
 %%------------------------------------------------------------------------------
 %% Exported API
 %%------------------------------------------------------------------------------
--export([start/1, start/2]).
--export([stop/1]).
--export([which_reporters/0]).
--export([get_id/1]).
-
--export_type([reporter_id/0]).
 -export_type([start_option/0, start_options/0]).
 
 %%------------------------------------------------------------------------------
@@ -50,11 +41,6 @@
 -export([start_link/2]).
 
 %%------------------------------------------------------------------------------
-%% 'passage_reporter' Callback API
-%%------------------------------------------------------------------------------
--export([report/2]).
-
-%%------------------------------------------------------------------------------
 %% 'gen_server' Callback API
 %%------------------------------------------------------------------------------
 -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
@@ -66,112 +52,69 @@
 
 -record(?STATE,
         {
-          socket               :: gen_udp:socket(),
-          thrift_format        :: thrift_protocol:format(),
-          agent_host           :: inet:hostname(),
-          agent_port           :: inet:port_number(),
+          endpoint             :: string(),
+          options              :: start_options(),
+          http_client          :: http_client(),
           default_service_name :: atom(),
           process_tags         :: passage:tags()
         }).
 
+-define(CONTENT_TYPE, {"Content-Type", "application/x-thrift"}).
+
 %%------------------------------------------------------------------------------
 %% Exported Types
 %%------------------------------------------------------------------------------
--type reporter_id() :: atom().
-%% Reporter identifier.
 
 -type start_options() :: [start_option()].
 %% Options for {@link start/2}.
 
--type start_option() :: {thrift_format, thrift_protocol:format()}
-                      | {agent_host, inet:hostname()}
-                      | {agent_port, inet:port_number()}
+-type start_option() :: {endpoint, string()}
+                      | {http_client, http_client()}
                       | {default_service_name, atom()}
                       | {process_tags, passage:tags()}.
 %% <ul>
-%%   <li><b>thrift_format</b>: The format for encoding thrift messages. The default value is `compact'.</li>
-%%   <li><b>agent_host</b>: The hostname of the jaeger agent. The default value is `"127.0.0.1"'.</li>
-%%   <li><b>agent_port</b>: The port of the jaeger agent. The default values for the thrift format `compact' and `binary' are `6831' and `6832' respectively.</li>
+%%   <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>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>
+%% Example of a http_client calback
+%% Client = fun(Url, Method, Headers, Body, ReporterOptions) ->
+%%    User = proplists:get_value(user, ReporterOptions),
+%%    Password = proplists:get_value(password, ReporterOptions),
+%%    ibrowse:send_req(Url, Headers, Method, Body, [{basic_auth, {User,  Password}}])
+%% end.
+
+
+-type http_client() :: fun((
+        Url    :: string(),
+        Method :: post,
+        Headers :: [{string(), string()}],
+        Body :: string() | binary(),
+        ReporterOptions :: start_options()) ->
+    ok).
 
 %%------------------------------------------------------------------------------
 %% Application Internal Functions
 %%------------------------------------------------------------------------------
 %% @private
--spec start_link(reporter_id(), start_options()) -> {ok, pid()} | {error, Reason} when
+-spec start_link(jaeger_passage_reporter:reporter_id(), start_options()) -> {ok, pid()} | {error, Reason} when
       Reason :: {already_started, pid()} | term().
 start_link(ReporterId, Options) ->
     Name = jaeger_passage_local_ns:reporter_name(ReporterId),
     gen_server:start_link(Name, ?MODULE, {ReporterId, Options}, []).
 
 %%------------------------------------------------------------------------------
-%% Exported Functions
-%%------------------------------------------------------------------------------
-%% @equiv start(ReporterId, [])
--spec start(reporter_id()) -> {ok, passage_reporter:reporter()} | {error, Reason} when
-      Reason :: {already_started, pid()} | term().
-start(ReporterId) ->
-    start(ReporterId, []).
-
-%% @doc Starts a reporter process.
--spec start(reporter_id(), start_options()) -> {ok, Reporter} | {error, Reason} when
-      Reporter :: passage_reporter:reporter(),
-      Reason :: {already_started, pid()} | term().
-start(ReporterId, Options) ->
-    Args = [ReporterId, Options],
-    is_atom(ReporterId) orelse error(badarg, Args),
-    is_list(Options) orelse error(badarg, Args),
-
-    case jaeger_passage_reporter_sup:start_child(ReporterId, Options) of
-        {error, Reason} -> {error, Reason};
-        {ok, _Pid}      -> {ok, passage_reporter:new(?MODULE, ReporterId)}
-    end.
-
-%% @doc Stops the reporter process.
-%%
-%% If the reporter which has the identifier `ReporterId' has not been started,
-%% it will be simply ignored.
--spec stop(reporter_id()) -> ok.
-stop(ReporterId) ->
-    jaeger_passage_reporter_sup:stop_child(ReporterId).
-
-%% @doc Returns the list of the running reporters.
--spec which_reporters() -> [reporter_id()].
-which_reporters() ->
-    jaeger_passage_reporter_sup:which_children().
-
-%% @doc Returns the identifier of `Reporter'.
-%%
-%% Note that if `Reporter' is one which has not been created by {@link start/2},
-%% this function will crash.
--spec get_id(passage_reporter:reporter()) -> reporter_id().
-get_id(Reporter) ->
-    ?MODULE = passage_reporter:get_module(Reporter),
-    passage_reporter:get_state(Reporter).
-
-%%------------------------------------------------------------------------------
-%% 'passage_reporter' Callback Functions
-%%------------------------------------------------------------------------------
-%% @private
-report(ReporterId, Span) ->
-    Server = jaeger_passage_local_ns:reporter_name(ReporterId),
-    gen_server:cast(Server, {report, Span}).
-
-%%------------------------------------------------------------------------------
 %% 'gen_server' Callback Functions
 %%------------------------------------------------------------------------------
 %% @private
 init({ReporterId, Options}) ->
-    Format = proplists:get_value(thrift_format, Options, compact),
-    DefaultPort =
-        case Format of
-            compact -> 6831;
-            binary  -> 6832
-        end,
-    AgentHost = proplists:get_value(agent_host, Options, "127.0.0.1"),
-    AgentPort = proplists:get_value(agent_port, Options, DefaultPort),
+    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]),
+
     DefaultServiceName = proplists:get_value(default_service_name, Options, ReporterId),
     Tags0 = proplists:get_value(process_tags, Options, #{}),
 
@@ -185,15 +128,13 @@ init({ReporterId, Options}) ->
             ?TRACER_HOSTNAME_TAG_KEY => list_to_binary(Hostname),
             'erlang.node' => node()
            }),
-    {ok, Socket} = gen_udp:open(0),
     State =
         #?STATE{
-            socket        = Socket,
-            thrift_format = Format,
-            agent_host    = AgentHost,
-            agent_port    = AgentPort,
+            endpoint              = EndpointURL,
+            http_client           = HttpClient,
+            options               = Options,
             default_service_name  = DefaultServiceName,
-            process_tags  = Tags1
+            process_tags          = Tags1
            },
     {ok, State}.
 
@@ -223,9 +164,10 @@ code_change(_OldVsn, State, _Extra) ->
 %% Internal Functions
 %%------------------------------------------------------------------------------
 -spec handle_report(passage_span:span(), #?STATE{}) -> {noreply, #?STATE{}}.
-handle_report(Span, State = #?STATE{default_service_name = DefaultName, process_tags = Tags}) ->
+handle_report(Span, State = #?STATE{default_service_name = DefaultName, process_tags = Tags, endpoint = URI, http_client = HttpClient, options = Options}) ->
     Name = maps:get('location.application', passage_span:get_tags(Span), DefaultName),
-    Message = jaeger_passage_thrift:make_emit_batch_message(Name, Tags, [Span]),
-    Encoded = thrift_protocol:encode_message(Message, State#?STATE.thrift_format),
-    ok = gen_udp:send(State#?STATE.socket, State#?STATE.agent_host, State#?STATE.agent_port, Encoded),
+    Message = jaeger_passage_thrift:make_batch(Name, Tags, [Span]),
+    Encoded = thrift_protocol:encode_struct(Message, binary),
+    Headers = [?CONTENT_TYPE],
+    HttpClient(URI, post, Headers, Encoded, Options),
     {noreply, State}.
diff --git a/src/jaeger_passage_reporter_sup.erl b/src/jaeger_passage_reporter_sup.erl
index 529fde3..77f23ba 100644
--- a/src/jaeger_passage_reporter_sup.erl
+++ b/src/jaeger_passage_reporter_sup.erl
@@ -9,7 +9,7 @@
 %% Application Internal API
 %%------------------------------------------------------------------------------
 -export([start_link/0]).
--export([start_child/2]).
+-export([start_child/3]).
 -export([stop_child/1]).
 -export([which_children/0]).
 
@@ -25,14 +25,15 @@
 start_link() ->
     supervisor:start_link({local, ?MODULE}, ?MODULE, []).
 
--spec start_child(ReporterId, Options) -> {ok, pid()} | {error, Reason} when
+-spec start_child(ReporterId, ReporterModule, Options) -> {ok, pid()} | {error, Reason} when
       ReporterId :: jaeger_passage_reporter:reporter_id(),
+      ReporterModule :: module(),
       Options :: jaeger_passage_reporter:start_options(),
       Reason :: {already_started, pid()} | term().
-start_child(ReporterId, Options) ->
+start_child(ReporterId, ReporterModule, Options) ->
     Child = #{
       id      => ReporterId,
-      start   => {jaeger_passage_reporter, start_link, [ReporterId, Options]},
+      start   => {ReporterModule, start_link, [ReporterId, Options]},
       restart => permanent
      },
     supervisor:start_child(?MODULE, Child).
diff --git a/src/jaeger_passage_reporter.erl b/src/jaeger_passage_reporter_udp.erl
similarity index 68%
copy from src/jaeger_passage_reporter.erl
copy to src/jaeger_passage_reporter_udp.erl
index 32f537e..485c258 100644
--- a/src/jaeger_passage_reporter.erl
+++ b/src/jaeger_passage_reporter_udp.erl
@@ -1,12 +1,10 @@
-%% @copyright 2017 Takeru Ohta <ph...@gmail.com>
-%%
 %% @doc A reporter that sends the spans to an jaeger agent
 %%
 %% === Examples ===
 %%
 %% ```
 %% %% Starts `example_reporter'
-%% {ok, Reporter} = jaeger_passage_reporter:start(example_reporter).
+%% {ok, Reporter} = jaeger_passage_reporter:start(example_reporter, [{protocol, udp}]).
 %% [example_reporter] = jaeger_passage_reporter:which_reporters().
 %%
 %% %% Registers `example_tracer'
@@ -26,9 +24,8 @@
 %% <li><a href="http://jaeger.readthedocs.io/en/latest/architecture/#agent">Jaeger - Architecture - Agent</a></li>
 %% <li><a href="http://jaeger.readthedocs.io/en/latest/deployment/#agent">Jaeger - Deployment - Agent</a></li>
 %% </ul>
--module(jaeger_passage_reporter).
+-module(jaeger_passage_reporter_udp).
 
--behaviour(passage_reporter).
 -behaviour(gen_server).
 
 -include("constants.hrl").
@@ -36,12 +33,6 @@
 %%------------------------------------------------------------------------------
 %% Exported API
 %%------------------------------------------------------------------------------
--export([start/1, start/2]).
--export([stop/1]).
--export([which_reporters/0]).
--export([get_id/1]).
-
--export_type([reporter_id/0]).
 -export_type([start_option/0, start_options/0]).
 
 %%------------------------------------------------------------------------------
@@ -50,11 +41,6 @@
 -export([start_link/2]).
 
 %%------------------------------------------------------------------------------
-%% 'passage_reporter' Callback API
-%%------------------------------------------------------------------------------
--export([report/2]).
-
-%%------------------------------------------------------------------------------
 %% 'gen_server' Callback API
 %%------------------------------------------------------------------------------
 -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
@@ -77,17 +63,13 @@
 %%------------------------------------------------------------------------------
 %% Exported Types
 %%------------------------------------------------------------------------------
--type reporter_id() :: atom().
-%% Reporter identifier.
 
 -type start_options() :: [start_option()].
 %% Options for {@link start/2}.
 
 -type start_option() :: {thrift_format, thrift_protocol:format()}
                       | {agent_host, inet:hostname()}
-                      | {agent_port, inet:port_number()}
-                      | {default_service_name, atom()}
-                      | {process_tags, passage:tags()}.
+                      | {agent_port, inet:port_number()}.
 %% <ul>
 %%   <li><b>thrift_format</b>: The format for encoding thrift messages. The default value is `compact'.</li>
 %%   <li><b>agent_host</b>: The hostname of the jaeger agent. The default value is `"127.0.0.1"'.</li>
@@ -100,66 +82,13 @@
 %% Application Internal Functions
 %%------------------------------------------------------------------------------
 %% @private
--spec start_link(reporter_id(), start_options()) -> {ok, pid()} | {error, Reason} when
+-spec start_link(jaeger_passage_reporter:reporter_id(), start_options()) -> {ok, pid()} | {error, Reason} when
       Reason :: {already_started, pid()} | term().
 start_link(ReporterId, Options) ->
     Name = jaeger_passage_local_ns:reporter_name(ReporterId),
     gen_server:start_link(Name, ?MODULE, {ReporterId, Options}, []).
 
 %%------------------------------------------------------------------------------
-%% Exported Functions
-%%------------------------------------------------------------------------------
-%% @equiv start(ReporterId, [])
--spec start(reporter_id()) -> {ok, passage_reporter:reporter()} | {error, Reason} when
-      Reason :: {already_started, pid()} | term().
-start(ReporterId) ->
-    start(ReporterId, []).
-
-%% @doc Starts a reporter process.
--spec start(reporter_id(), start_options()) -> {ok, Reporter} | {error, Reason} when
-      Reporter :: passage_reporter:reporter(),
-      Reason :: {already_started, pid()} | term().
-start(ReporterId, Options) ->
-    Args = [ReporterId, Options],
-    is_atom(ReporterId) orelse error(badarg, Args),
-    is_list(Options) orelse error(badarg, Args),
-
-    case jaeger_passage_reporter_sup:start_child(ReporterId, Options) of
-        {error, Reason} -> {error, Reason};
-        {ok, _Pid}      -> {ok, passage_reporter:new(?MODULE, ReporterId)}
-    end.
-
-%% @doc Stops the reporter process.
-%%
-%% If the reporter which has the identifier `ReporterId' has not been started,
-%% it will be simply ignored.
--spec stop(reporter_id()) -> ok.
-stop(ReporterId) ->
-    jaeger_passage_reporter_sup:stop_child(ReporterId).
-
-%% @doc Returns the list of the running reporters.
--spec which_reporters() -> [reporter_id()].
-which_reporters() ->
-    jaeger_passage_reporter_sup:which_children().
-
-%% @doc Returns the identifier of `Reporter'.
-%%
-%% Note that if `Reporter' is one which has not been created by {@link start/2},
-%% this function will crash.
--spec get_id(passage_reporter:reporter()) -> reporter_id().
-get_id(Reporter) ->
-    ?MODULE = passage_reporter:get_module(Reporter),
-    passage_reporter:get_state(Reporter).
-
-%%------------------------------------------------------------------------------
-%% 'passage_reporter' Callback Functions
-%%------------------------------------------------------------------------------
-%% @private
-report(ReporterId, Span) ->
-    Server = jaeger_passage_local_ns:reporter_name(ReporterId),
-    gen_server:cast(Server, {report, Span}).
-
-%%------------------------------------------------------------------------------
 %% 'gen_server' Callback Functions
 %%------------------------------------------------------------------------------
 %% @private
diff --git a/src/jaeger_passage_thrift.erl b/src/jaeger_passage_thrift.erl
index 28537fd..d8d81da 100644
--- a/src/jaeger_passage_thrift.erl
+++ b/src/jaeger_passage_thrift.erl
@@ -15,7 +15,7 @@
 %%------------------------------------------------------------------------------
 %% Application Internal API
 %%------------------------------------------------------------------------------
--export([make_emit_batch_message/3]).
+-export([make_emit_batch_message/3, make_batch/3]).
 
 %%------------------------------------------------------------------------------
 %% Macros
@@ -49,6 +49,12 @@ make_emit_batch_message(ServiceName, ServiceTags, Spans) ->
        body         = ?STRUCT(Batch)
       }.
 
+-spec make_batch(atom(), passage:tags(), [passage_span:span()]) ->
+                                     thrift_protocol:struct().
+make_batch(ServiceName, ServiceTags, Spans) ->
+    Process = make_process(ServiceName, ServiceTags),
+    ?STRUCT(Process, make_spans(Spans)).
+
 %%------------------------------------------------------------------------------
 %% Internal Functions
 %%------------------------------------------------------------------------------


[couchdb-jaeger-passage] 07/09: Update documentation

Posted by ii...@apache.org.
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 82f8fd037325a2ceb6695a350181e41c5331f0cc
Author: Takeru Ohta <ph...@gmail.com>
AuthorDate: Thu Jan 23 22:21:43 2020 +0900

    Update documentation
---
 src/jaeger_passage_reporter.erl      | 24 +++-------------
 src/jaeger_passage_reporter_http.erl | 56 +++++++++++++++++-------------------
 src/jaeger_passage_reporter_udp.erl  | 21 ++++++--------
 3 files changed, 40 insertions(+), 61 deletions(-)

diff --git a/src/jaeger_passage_reporter.erl b/src/jaeger_passage_reporter.erl
index a2a4a68..5054ae9 100644
--- a/src/jaeger_passage_reporter.erl
+++ b/src/jaeger_passage_reporter.erl
@@ -1,6 +1,6 @@
 %% @copyright 2017 Takeru Ohta <ph...@gmail.com>
 %%
-%% @doc A reporter that sends the spans to an jaeger agent
+%% @doc A reporter that sends the spans to an jaeger agent (UDP) or collector (HTTP).
 %%
 %% === Examples ===
 %%
@@ -57,27 +57,11 @@
 -type start_options() :: [start_option()].
 %% Options for {@link start/2}.
 
--type start_option() :: jaeger_passage_reporter_udp:start_option()
-                      | jaeger_passage_reporter_http:start_option()
-                      | {protocol, udp | http}
-                      | {default_service_name, atom()}
-                      | {process_tags, passage:tags()}.
-
-%% Common reporter options
+-type start_option() :: {protocol, udp | http}
+                      | jaeger_passage_reporter_udp:start_option()
+                      | jaeger_passage_reporter_http:start_option().
 %% <ul>
 %%   <li><b>protocol</b>: Communication protocol used to connect to jaeger. The value is used to select reporter module. Possible values are: `udp' | `http'. The default value is `udp'.</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>
-%% UDP reporter specific options
-%% <ul>
-%%   <li><b>thrift_format</b>: The format for encoding thrift messages. The default value is `compact'.</li>
-%%   <li><b>agent_host</b>: The hostname of the jaeger agent. The default value is `"127.0.0.1"'.</li>
-%%   <li><b>agent_port</b>: The port of the jaeger agent. The default values for the thrift format `compact' and `binary' are `6831' and `6832' respectively.</li>
-%% </ul>
-%% HTTP reporter specific options
-%% <ul>
-%%   <li><b>endpoint</b>: The jaeger endpoint URL for sending thrift messages. The default value is `http://127.0.0.1:14268'.</li>
 %% </ul>
 
 %%------------------------------------------------------------------------------
diff --git a/src/jaeger_passage_reporter_http.erl b/src/jaeger_passage_reporter_http.erl
index 0b0097c..e226d6c 100644
--- a/src/jaeger_passage_reporter_http.erl
+++ b/src/jaeger_passage_reporter_http.erl
@@ -1,4 +1,7 @@
-%% @doc A reporter that sends the spans to an jaeger agent
+%% @doc A reporter that sends the spans to an jaeger collector using HTTP.
+%%
+%% To start a reporter process, please use {@link jaeger_passage_reporter:start/1} or {@link jaeger_passage_reporter:start/2}.
+%%
 %%
 %% === Examples ===
 %%
@@ -15,15 +18,8 @@
 %% %% Starts and finishes a span
 %% Span = passage:start_span(example, [{tracer, example_tracer}]).
 %%
-%% passage:finish_span(Span). % The span will send to the jaeger agent on the localhost
+%% passage:finish_span(Span). % The span will send to the jaeger collector on the localhost
 %% '''
-%%
-%% === Refereces ===
-%%
-%% <ul>
-%% <li><a href="http://jaeger.readthedocs.io/en/latest/architecture/#agent">Jaeger - Architecture - Agent</a></li>
-%% <li><a href="http://jaeger.readthedocs.io/en/latest/deployment/#agent">Jaeger - Deployment - Agent</a></li>
-%% </ul>
 -module(jaeger_passage_reporter_http).
 
 -behaviour(gen_server).
@@ -33,6 +29,8 @@
 %%------------------------------------------------------------------------------
 %% Exported API
 %%------------------------------------------------------------------------------
+-export([httpc_client/5]).
+
 -export_type([start_option/0, start_options/0]).
 
 %%------------------------------------------------------------------------------
@@ -66,25 +64,28 @@
 %%------------------------------------------------------------------------------
 
 -type start_options() :: [start_option()].
-%% Options for {@link start/2}.
+%% Options for {@link jaeger_passage_reporter:start/2}.
 
--type start_option() :: {endpoint, string()}
+-type start_option() :: {default_service_name, atom()}
+                      | {process_tags, passage:tags()}
+                      | {endpoint, string()}
                       | {http_client, http_client()}
-                      | {default_service_name, atom()}
-                      | {process_tags, passage:tags()}.
+                      | (HttpClientSpecificOption :: any()).
 %% <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. 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>
+%%   <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. {@link httpc_client/5} is used by default.</li>
 %% </ul>
-%% Example of a http_client calback
+%%
+%% Example of a `http_client' calback:
+%% ```
 %% Client = fun(Url, Method, Headers, Body, ReporterOptions) ->
 %%    User = proplists:get_value(user, ReporterOptions),
 %%    Password = proplists:get_value(password, ReporterOptions),
 %%    ibrowse:send_req(Url, Headers, Method, Body, [{basic_auth, {User,  Password}}])
 %% end.
-
+%% '''
 
 -type http_client() :: fun((
         Url    :: string(),
@@ -93,6 +94,15 @@
         Body :: string() | binary(),
         ReporterOptions :: start_options()) ->
     ok).
+%% Type of HTTP client.
+
+%%------------------------------------------------------------------------------
+%% Exported Functions
+%%------------------------------------------------------------------------------
+%% @doc The default HTTP client based on the standard `httpc' module.
+httpc_client(Url, Method, _Headers, Body, _ReporterOptions) ->
+    httpc:request(Method, {Url, [], "application/x-thrift", Body}, [], []),
+    ok.
 
 %%------------------------------------------------------------------------------
 %% Application Internal Functions
@@ -171,15 +181,3 @@ 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/src/jaeger_passage_reporter_udp.erl b/src/jaeger_passage_reporter_udp.erl
index 485c258..650da52 100644
--- a/src/jaeger_passage_reporter_udp.erl
+++ b/src/jaeger_passage_reporter_udp.erl
@@ -1,4 +1,6 @@
-%% @doc A reporter that sends the spans to an jaeger agent
+%% @doc A reporter that sends the spans to an jaeger agent using UDP.
+%%
+%% To start a reporter process, please use {@link jaeger_passage_reporter:start/1} or {@link jaeger_passage_reporter:start/2}.
 %%
 %% === Examples ===
 %%
@@ -17,13 +19,6 @@
 %%
 %% passage:finish_span(Span). % The span will send to the jaeger agent on the localhost
 %% '''
-%%
-%% === Refereces ===
-%%
-%% <ul>
-%% <li><a href="http://jaeger.readthedocs.io/en/latest/architecture/#agent">Jaeger - Architecture - Agent</a></li>
-%% <li><a href="http://jaeger.readthedocs.io/en/latest/deployment/#agent">Jaeger - Deployment - Agent</a></li>
-%% </ul>
 -module(jaeger_passage_reporter_udp).
 
 -behaviour(gen_server).
@@ -65,17 +60,19 @@
 %%------------------------------------------------------------------------------
 
 -type start_options() :: [start_option()].
-%% Options for {@link start/2}.
+%% Options for {@link jaeger_passage_reporter:start/2}.
 
--type start_option() :: {thrift_format, thrift_protocol:format()}
+-type start_option() :: {default_service_name, atom()}
+                      | {process_tags, passage:tags()}
+                      | {thrift_format, thrift_protocol:format()}
                       | {agent_host, inet:hostname()}
                       | {agent_port, inet:port_number()}.
 %% <ul>
+%%   <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>
 %%   <li><b>thrift_format</b>: The format for encoding thrift messages. The default value is `compact'.</li>
 %%   <li><b>agent_host</b>: The hostname of the jaeger agent. The default value is `"127.0.0.1"'.</li>
 %%   <li><b>agent_port</b>: The port of the jaeger agent. The default values for the thrift format `compact' and `binary' are `6831' and `6832' respectively.</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>
 
 %%------------------------------------------------------------------------------


[couchdb-jaeger-passage] 04/09: Use httpc by default

Posted by ii...@apache.org.
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'


[couchdb-jaeger-passage] 05/09: Merge pull request #3 from iilyak/add-http-reporter

Posted by ii...@apache.org.
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 e080c975226e85f22b47d7fa9543d0ca45456e0e
Merge: 690c699 dd36ad4
Author: Takeru Ohta <ph...@gmail.com>
AuthorDate: Thu Jan 23 21:15:27 2020 +0900

    Merge pull request #3 from iilyak/add-http-reporter
    
    Add HTTP reporter

 README.md                                          |  18 +++
 rebar.config.script                                |   2 +-
 rebar.lock                                         |   4 +-
 src/jaeger_passage.erl                             |   2 +-
 src/jaeger_passage_reporter.erl                    | 138 +++---------------
 ...porter.erl => jaeger_passage_reporter_http.erl} | 154 ++++++++-------------
 src/jaeger_passage_reporter_sup.erl                |   9 +-
 ...eporter.erl => jaeger_passage_reporter_udp.erl} |  79 +----------
 src/jaeger_passage_thrift.erl                      |   8 +-
 test/jaeger_passage_repoter_tests.erl              |  60 +++++++-
 10 files changed, 168 insertions(+), 306 deletions(-)


[couchdb-jaeger-passage] 03/09: Add test case for http_reporter

Posted by ii...@apache.org.
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 367238681f376c3d899118806c9efb530990cff4
Author: ILYA Khlopotov <ii...@apache.org>
AuthorDate: Tue Jan 21 03:55:35 2020 -0800

    Add test case for http_reporter
---
 test/jaeger_passage_repoter_tests.erl | 59 ++++++++++++++++++++++++++++++-----
 1 file changed, 52 insertions(+), 7 deletions(-)

diff --git a/test/jaeger_passage_repoter_tests.erl b/test/jaeger_passage_repoter_tests.erl
index 7aa1dd0..7f034bb 100644
--- a/test/jaeger_passage_repoter_tests.erl
+++ b/test/jaeger_passage_repoter_tests.erl
@@ -6,27 +6,72 @@
 %%------------------------------------------------------------------------------
 %% Test Cases
 %%------------------------------------------------------------------------------
-basic_test() ->
+basic_udp_test() ->
     {ok, _} = application:ensure_all_started(jaeger_passage),
 
-    %% Starts `test_reporter'
-    {ok, Reporter} = jaeger_passage_reporter:start(test_reporter),
-    [test_reporter] = jaeger_passage_reporter:which_reporters(),
+    %% Starts `udp_reporter'
+    {ok, Reporter} = jaeger_passage_reporter:start(udp_reporter),
+    [udp_reporter] = jaeger_passage_reporter:which_reporters(),
 
     %% Registers `test_tracer'
     Context = jaeger_passage_span_context,
     Sampler = passage_sampler_all:new(),
-    ok = passage_tracer_registry:register(test_tracer, Context, Sampler, Reporter),
+    ok = passage_tracer_registry:register(udp_tracer, Context, Sampler, Reporter),
 
     %% Starts and finishes spans
-    passage_pd:start_span(test_root, [{tracer, test_tracer}]),
+    passage_pd:start_span(test_root, [{tracer, udp_tracer}]),
     passage_pd:start_span(test_child),
     passage_pd:log(#{message => "Hello World"}),
     passage_pd:finish_span(),
     passage_pd:finish_span(),
     timer:sleep(50),
 
-    ok = jaeger_passage_reporter:stop(test_reporter),
+    ok = jaeger_passage_reporter:stop(udp_reporter),
     [] = jaeger_passage_reporter:which_reporters(),
 
     ok = application:stop(jaeger_passage).
+
+basic_http_test() ->
+    {ok, _} = application:ensure_all_started(jaeger_passage),
+
+    %% Starts `http_reporter'
+    {ok, Reporter} = jaeger_passage_reporter:start(http_reporter, [
+        {protocol, http},
+        {http_client, fun http_client/5}
+    ]),
+    [http_reporter] = jaeger_passage_reporter:which_reporters(),
+
+    %% Registers `test_tracer'
+    Context = jaeger_passage_span_context,
+    Sampler = passage_sampler_all:new(),
+    ok = passage_tracer_registry:register(http_tracer, Context, Sampler, Reporter),
+
+    %% Starts and finishes spans
+    passage_pd:start_span(test_root, [{tracer, http_tracer}]),
+    passage_pd:start_span(test_child),
+    passage_pd:log(#{message => "Hello World"}),
+    passage_pd:finish_span(),
+    passage_pd:finish_span(),
+    timer:sleep(50),
+
+    ok = jaeger_passage_reporter:stop(http_reporter),
+    [] = jaeger_passage_reporter:which_reporters(),
+
+    ok = application:stop(jaeger_passage).
+
+error_http_test() ->
+    {ok, _} = application:ensure_all_started(jaeger_passage),
+
+    %% Starts `http_reporter'
+    ?assertMatch({error, {{badarg, _}, _}}, jaeger_passage_reporter:start(http_reporter, [
+        {protocol, http}
+    ])),
+
+    %% Starts `http_reporter'
+    ?assertError(badarg, jaeger_passage_reporter:start(http_reporter, [
+        {protocol, undefined}
+    ])).
+
+
+http_client(_URI, _Method, _Headers, _Encoded, _Options) ->
+    ok.
\ No newline at end of file