Skip to content

Commit 426fc49

Browse files
committed
can record spans as summary
1 parent 86a2b3e commit 426fc49

7 files changed

Lines changed: 113 additions & 13 deletions

File tree

mix.exs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ defmodule OpencensusErlangPrometheus.Mixfile do
88
deps: deps(),
99
description: description(),
1010
package: package(),
11-
erlc_options: [:warnings_as_errors],
11+
erlc_options: [:warnings_as_errors,
12+
:warn_export_vars,
13+
:warn_shadow_vars,
14+
:warn_obsolete_guard],
1215
elixirc_options: [warnings_as_errors: true],
1316
test_coverage: [tool: ExCoveralls],
1417
preferred_cli_env: ["coveralls": :test, "coveralls.html": :test]]
@@ -23,12 +26,13 @@ defmodule OpencensusErlangPrometheus.Mixfile do
2326
defp package do
2427
[maintainers: ["Ilya Khaprov"],
2528
licenses: ["MIT"],
26-
links: %{"GitHub" => "https://github.com/deadtrickster/opencensus_erlang_prometheus"},
29+
links: %{"GitHub" => "https://github.com/deadtrickster/opencensus-erlang-prometheus"},
2730
files: ["priv", "src", "README.md", "rebar.config"]]
2831
end
2932

3033
defp deps do
31-
[{:prometheus, "~> 3.4"},
34+
[{:prometheus, "~> 3.4", manager: :rebar3},
35+
{:opencensus, git: "https://github.com/deadtrickster/opencensus-erlang", branch: "fix-mix-dep"},
3236
{:credo, "~> 0.8.7", only: [:dev, :test]},
3337
{:excoveralls, "~> 0.7.3", only: [:test]}]
3438
end

mix.lock

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
"jsx": {:hex, :jsx, "2.8.2", "7acc7d785b5abe8a6e9adbde926a24e481f29956dd8b4df49e3e4e7bcc92a018", [], [], "hexpm"},
99
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [], [], "hexpm"},
1010
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [], [], "hexpm"},
11+
"opencensus": {:git, "https://github.com/deadtrickster/opencensus-erlang", "c31853dfb1656f0d057cf69b569a8792ef5bd6c5", [branch: "fix-mix-dep"]},
1112
"prometheus": {:hex, :prometheus, "3.4.1", "90c4f37670c4dc7de9319a0c310bf12cb619715ebe285f583f3b46d955ee8f81", [], [], "hexpm"},
13+
"rebar_erl_vsn": {:hex, :rebar_erl_vsn, "0.1.3", "431667f3203f19130805a8ac7cde9666d1bff7235eb2b96e2048eb839db0ed1f", [], [], "hexpm"},
14+
"rfc3339": {:hex, :rfc3339, "0.9.0", "2075653dc9407541c84b1e15f8bda2abe95fb17c9694025e079583f2d19c1060", [], [], "hexpm"},
1215
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [], [], "hexpm"},
13-
"unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [], [], "hexpm"}}
16+
"unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [], [], "hexpm"},
17+
"wts": {:hex, :wts, "0.3.0", "5cdf22c775cb1ebae24c326a5db6074d753c42f4bd12a9aa47cc62d3e2c71ad1", [], [{:rfc3339, "~>0.9.0", [hex: :rfc3339, repo: "hexpm", optional: false]}], "hexpm"}}

rebar.config

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33

44
{post_hooks, []}.
55

6-
{deps, [{prometheus, "3.4.1"}]}.
7-
{shell, [{apps, [opencensus_erlang_prometheus]}]}.
6+
{deps, [{prometheus, "3.4.1"},
7+
{opencensus,
8+
{git, "https://github.com/census-instrumentation/opencensus-erlang",
9+
{branch, "master"}}}]}.
10+
% {shell, [{apps, [opencensus_erlang_prometheus]}]}.
811
{cover_enabled, true}.
912
{cover_export_enabled, true}.
1013
{cover_excl_mods, [
@@ -14,8 +17,11 @@
1417
{coveralls_service_name , "travis-ci"}.
1518

1619
{xref_extra_paths,[]}.
17-
{xref_checks,[undefined_function_calls,undefined_functions,locals_not_used,
18-
deprecated_function_calls,deprecated_functions]}.
20+
{xref_checks,[undefined_function_calls,
21+
undefined_functions,
22+
locals_not_used,
23+
deprecated_function_calls,
24+
deprecated_functions]}.
1925

2026
{profiles, [{docs, [{deps, [{edown, "0.8.1"}]},
2127
{edoc_opts,
@@ -27,7 +33,8 @@
2733
{"./README.md",
2834
"https://github.com/deadtrickster/opencensus-erlang-prometheus"}}]}]},
2935
{test, [{plugins, [{coveralls, "1.4.0"},
30-
{rebar3_elvis_plugin, "0.0.4"}]}]},
36+
{rebar3_elvis_plugin, "0.0.4"}]},
37+
{erl_opts, [nowarn_export_all]}]},
3138
{benchmark, [{src_dirs, ["src", "benchmark"]},
3239
{deps, [{'erlang-color',
3340
{git, "https://github.com/julianduque/erlang-color",

rebar.lock

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
{"1.1.0",
2-
[{<<"prometheus">>,{pkg,<<"prometheus">>,<<"3.4.1">>},0}]}.
2+
[{<<"opencensus">>,
3+
{git,"https://github.com/census-instrumentation/opencensus-erlang",
4+
{ref,"b8fecf303896a9bdbfe9d1f83371a5bc1e88a28a"}},
5+
0},
6+
{<<"prometheus">>,{pkg,<<"prometheus">>,<<"3.4.1">>},0},
7+
{<<"rfc3339">>,{pkg,<<"rfc3339">>,<<"0.9.0">>},2},
8+
{<<"wts">>,{pkg,<<"wts">>,<<"0.3.0">>},1}]}.
39
[
410
{pkg_hash,[
5-
{<<"prometheus">>, <<"90C4F37670C4DC7DE9319A0C310BF12CB619715EBE285F583F3B46D955EE8F81">>}]}
11+
{<<"prometheus">>, <<"90C4F37670C4DC7DE9319A0C310BF12CB619715EBE285F583F3B46D955EE8F81">>},
12+
{<<"rfc3339">>, <<"2075653DC9407541C84B1E15F8BDA2ABE95FB17C9694025E079583F2D19C1060">>},
13+
{<<"wts">>, <<"5CDF22C775CB1EBAE24C326A5DB6074D753C42F4BD12A9AA47CC62D3E2C71AD1">>}]}
614
].

src/oc_prometheus_reporter.erl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
-module(oc_prometheus_reporter).
2+
3+
-include_lib("opencensus/include/opencensus.hrl").
4+
5+
-behaviour(oc_reporter).
6+
7+
-export([init/1,
8+
report/2]).
9+
10+
%% ===================================================================
11+
%% API
12+
%% ===================================================================
13+
14+
init(_) ->
15+
prometheus_summary:declare([{name, "span"},
16+
{labels, [name]},
17+
{help, "Opencensus span"}]),
18+
ok.
19+
20+
report(Spans, _Opts) ->
21+
[
22+
prometheus_summary:observe("span", [Span#span.name],
23+
wts:duration(Span#span.start_time, Span#span.end_time))
24+
25+
|| Span <- Spans],
26+
ok.
27+
28+
29+
%% ===================================================================
30+
%% Private functions
31+
%% ===================================================================

src/opencensus_erlang_prometheus.app.src

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
{registered, []},
55
{applications,
66
[kernel,
7-
stdlib
7+
stdlib,
8+
prometheus,
9+
opencensus
810
]},
911
{env,[]},
1012
{modules, []},
1113

1214
{maintainers, ["Ilya Khaprov"]},
1315
{licenses, ["MIT"]},
14-
{links, [{"Github", "https://github.com/deadtrickster/opencensus_erlang_prometheus"}]}
16+
{links, [{"Github", "https://github.com/deadtrickster/opencensus-erlang-prometheus"}]}
1517
]}.

test/ct/oep_SUITE.erl

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
-module(oep_SUITE).
2+
3+
-compile(export_all).
4+
5+
-include_lib("eunit/include/eunit.hrl").
6+
-include_lib("common_test/include/ct.hrl").
7+
8+
-include_lib("opencensus/include/opencensus.hrl").
9+
10+
all() ->
11+
[prometheus_reporter].
12+
13+
init_per_suite(Config) ->
14+
Config.
15+
16+
end_per_suite(_Config) ->
17+
ok.
18+
19+
%% ===================================================================
20+
%% Tests
21+
%% ===================================================================
22+
23+
prometheus_reporter(_Config) ->
24+
application:set_env(opencensus, reporter, {oc_prometheus_reporter, []}),
25+
ok = application:load(opencensus),
26+
application:set_env(opencensus, reporter, {oc_prometheus_reporter, []}),
27+
{ok, _} = application:ensure_all_started(opencensus_erlang_prometheus),
28+
29+
SpanName1 = <<"span-1">>,
30+
Span1 = opencensus:start_span(SpanName1, opencensus:generate_trace_id(), undefined),
31+
32+
ChildSpanName1 = <<"child-span-1">>,
33+
ChildSpan1 = opencensus:start_span(ChildSpanName1, Span1),
34+
opencensus:finish_span(ChildSpan1),
35+
opencensus:finish_span(Span1),
36+
37+
timer:sleep(1000),
38+
39+
?assertMatch({1, _}, prometheus_summary:value("span", [SpanName1])),
40+
?assertMatch({1, _}, prometheus_summary:value("span", [ChildSpanName1])).
41+
42+
%% ===================================================================
43+
%% Private functions
44+
%% ===================================================================

0 commit comments

Comments
 (0)