Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
256 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,94 @@ | ||
-module(jaegerl). | ||
|
||
-export([start_span/1, start_span/2]). | ||
-export([finish_span/0, finish_span/1]). | ||
-export([current_span/0]). | ||
-export([log/1, log/2]). | ||
-export([set_tags/1]). | ||
|
||
-export_type([tracer_id/0]). | ||
-export_type([start_span_option/0, start_span_options/0]). | ||
-export_type([finish_span_option/0, finish_span_options/0]). | ||
-export_type([tags/0, tag_name/0, tag_value/0]). | ||
-export_type([span_reference/0, span_reference_type/0]). | ||
-export_type([span/0]). | ||
-export_type([operation_name/0]). | ||
-export_type([log_fields/0, log_field_name/0, log_field_value/0]). | ||
|
||
-type tracer_id() :: atom(). | ||
|
||
-type start_span_options() :: [start_span_option()]. | ||
|
||
-type start_span_option() :: {tracer, tracer_id()} | ||
| {start_time, erlang:timestamp()} | ||
| {refs, [span_reference()]} | ||
| {tags, tags()}. | ||
|
||
-type finish_span_options() :: [finish_span_option()]. | ||
|
||
-type finish_span_option() :: {finish_time, erlang:timestamp()} | ||
| {owner, pid()}. | ||
|
||
-type tags() :: #{tag_name() => tag_value()}. | ||
-type tag_name() :: atom() | binary(). | ||
-type tag_value() :: atom() | binary() | number() | boolean(). | ||
|
||
-type span_reference() :: {span_reference_type(), span()}. | ||
-type span_reference_type() :: child_of | follows_from. | ||
|
||
-type span() :: jaegerl_span:maybe_span(). | ||
|
||
-type operation_name() :: atom() | binary(). | ||
|
||
-type log_fields() :: #{log_field_name() => log_field_value()}. | ||
-type log_field_name() :: atom() | binary(). | ||
-type log_field_value() :: atom() | binary() | number() | boolean(). | ||
|
||
-spec start_span(operation_name()) -> span(). | ||
start_span(OperationName) -> | ||
start_span(OperationName, []). | ||
|
||
-spec start_span(operation_name(), start_span_options()) -> ok. | ||
start_span(OperationName, Options) -> | ||
Ancestors = get_ancestors(), | ||
Span = jaegerl_span:start_span(OperationName, Options), | ||
put_ancestors([Span | Ancestors]). | ||
|
||
-spec set_tags(tags()) -> ok. | ||
set_tags(Tags) -> | ||
error(unimplemented, [Tags]). | ||
|
||
-spec log(log_fields()) -> ok. | ||
log(Log) -> | ||
log(Log, os:timestamp()). | ||
|
||
-spec log(log_fields(), erlang:timestamp()) -> ok. | ||
log(Log, Time) -> | ||
error(unimplemented, [Log, Time]). | ||
|
||
-spec finish_span() -> ok. | ||
finish_span() -> | ||
finish_span([]). | ||
|
||
-spec finish_span(finish_span_options()) -> ok. | ||
finish_span(Options) -> | ||
error(unimplemented, [Options]). | ||
|
||
-spec current_span() -> span(). | ||
current_span() -> | ||
case get(jaegerl_ancestors) of | ||
undefined -> undefined; | ||
[Span | _] -> Span | ||
end. | ||
|
||
-spec get_ancestors() -> [span()]. | ||
get_ancestors() -> | ||
case get(jaegerl_ancestors) of | ||
undefined -> []; | ||
Ancestors -> Ancestors | ||
end. | ||
|
||
-spec put_ancestors([span()]) -> ok. | ||
put_ancestors(Ancestors) -> | ||
put(jaegerl_ancestors, Ancestors), | ||
ok. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,12 @@ | ||
-module(jaegerl_local_ns). | ||
|
||
-export([child_spec/0]). | ||
-export([tracer_name/1]). | ||
|
||
-spec child_spec() -> supervisor:child_spec(). | ||
child_spec() -> | ||
local:name_server_child_spec(?MODULE). | ||
|
||
-spec tracer_name(jaegerl:tracer_id()) -> local:otp_name(). | ||
tracer_name(TracerId) -> | ||
local:otp_name({?MODULE, {tracer, TracerId}}). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1 @@ | ||
-module(jaegerl_reporter). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1 @@ | ||
-module(jaegerl_sampler). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,29 @@ | ||
-module(jaegerl_span). | ||
|
||
-export([start_span/2]). | ||
|
||
-export_type([span/0, maybe_span/0]). | ||
|
||
-define(SPAN, ?MODULE). | ||
|
||
-record(?SPAN, | ||
{ | ||
tracer :: jaegerl:tracer_id(), | ||
operation_name :: jaegerl:operation_name(), | ||
start_time :: erlang:timestamp(), | ||
tags :: jaegerl:tags(), | ||
refs :: [jaegerl:span_reference()], | ||
baggage_items :: #{}, | ||
trace_id :: integer(), % 128-bit | ||
span_id :: integer(), % 64-bit | ||
parent_span_id :: integer(), % 64-bit | ||
flags :: non_neg_integer(), % 32-bit | ||
debug_id :: binary() | undefined | ||
}). | ||
|
||
-opaque span() :: #?SPAN{}. | ||
-type maybe_span() :: span() | undefined. | ||
|
||
-spec start_span(jaegerl:operation_name(), jaegerl:start_span_options()) -> maybe_span(). | ||
start_span(OperationName, Options) -> | ||
error(unimplemented, [OperationName, Options]). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,58 @@ | ||
-module(jaegerl_table). | ||
|
||
-export([get_tracer_info/1]). | ||
|
||
-export([start_link/0]). | ||
|
||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). | ||
|
||
-type tracer_info() :: | ||
#{ | ||
pid => pid(), | ||
sampler => module() | ||
}. | ||
|
||
-spec start_link() -> {ok, pid()} | {error, Reason :: term()}. | ||
start_link() -> | ||
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). | ||
|
||
-define(STATE, ?MODULE). | ||
|
||
-record(?STATE, | ||
{ | ||
table :: ets:tab() | ||
}). | ||
|
||
-spec get_tracer_info(jaegerl:tracer_id()) -> {ok, tracer_info()} | error. | ||
get_tracer_info(TracerId) -> | ||
try ets:lookup(?MODULE, {tracer_info, TracerId}) of | ||
[{_, Info}] -> {ok, Info}; | ||
_ -> error | ||
catch | ||
error:badarg -> error | ||
end. | ||
|
||
%% @private | ||
init([]) -> | ||
Table = ets:new(?MODULE, [named_table, protected, {read_concurrency, true}]), | ||
{ok, #?STATE{table = Table}}. | ||
|
||
%% @private | ||
handle_call(Request, From, State) -> | ||
{stop, {unknown_call, Request, From}, State}. | ||
|
||
%% @private | ||
handle_cast(Request, State) -> | ||
{stop, {unknown_cast, Request}, State}. | ||
|
||
%% @private | ||
handle_info(Info, State) -> | ||
{stop, {unknown_info, Info}, State}. | ||
|
||
%% @private | ||
terminate(_Reason, _State) -> | ||
ok. | ||
|
||
%% @private | ||
code_change(_OldVsn, State, _Extra) -> | ||
{ok, State}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters