|
1 | 1 | %%%------------------------------------------------------------------------ |
2 | | -%% Copyright 2018, OpenCensus Authors |
| 2 | +%% Copyright 2017, OpenCensus Authors |
3 | 3 | %% Licensed under the Apache License, Version 2.0 (the "License"); |
4 | 4 | %% you may not use this file except in compliance with the License. |
5 | 5 | %% You may obtain a copy of the License at |
|
11 | 11 | %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | 12 | %% See the License for the specific language governing permissions and |
13 | 13 | %% limitations under the License. |
14 | | -%% |
15 | | -%% @doc Server with no logic, simply owns the span ets table. |
| 14 | +%%%------------------------------------------------------------------------ |
| 15 | + |
| 16 | +%% @doc |
| 17 | +%% Exporter exports the collected records as view data. |
16 | 18 | %% @end |
17 | | -%%%------------------------------------------------------------------------- |
18 | | --module(oc_server). |
| 19 | +-module(oc_stat_reporter). |
19 | 20 |
|
20 | | --export([start_link/0]). |
| 21 | +-behaviour(oc_internal_timer). |
21 | 22 |
|
22 | | --export([init/1, |
23 | | - handle_call/3, |
24 | | - handle_cast/2]). |
| 23 | +-export([start_link/1, |
| 24 | + ping/0]). |
25 | 25 |
|
26 | 26 | -include("opencensus.hrl"). |
| 27 | +-include("oc_logger.hrl"). |
27 | 28 |
|
28 | | --record(state, {}). |
29 | | - |
30 | | -start_link() -> |
31 | | - maybe_init_ets(), |
32 | | - gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). |
| 29 | +start_link(Handlers) -> |
| 30 | + case gen_event:start_link({local, ?MODULE}, []) of |
| 31 | + {ok, Pid} -> |
| 32 | + [gen_event:add_handler(Pid, Handler, Opts) |
| 33 | + || {Handler, Opts} <- Handlers], |
33 | 34 |
|
34 | | -init([]) -> |
35 | | - {ok, #state{}}. |
36 | | - |
37 | | -handle_call(_, _From, State) -> |
38 | | - {noreply, State}. |
| 35 | + {ok, Pid}; |
| 36 | + Other -> Other |
| 37 | + end. |
39 | 38 |
|
40 | | -handle_cast(_, State) -> |
41 | | - {noreply, State}. |
| 39 | +%% @private |
| 40 | +ping() -> |
| 41 | + Measurements = oc_stat:export(), |
| 42 | + gen_event:sync_notify(?MODULE, {stats, Measurements}), |
42 | 43 |
|
43 | | -maybe_init_ets() -> |
44 | | - case ets:info(?SPAN_TAB, name) of |
45 | | - undefined -> |
46 | | - ets:new(?SPAN_TAB, [named_table, public, {write_concurrency, true}, {keypos, #span.span_id}]); |
47 | | - _ -> |
48 | | - ok |
49 | | - end. |
| 44 | + ok. |
0 commit comments