Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit a31bc28

Browse files
Housekeeping: update deps, fix trace protobuf path, regenerate files (#126)
housekeeping: update deps, fix trace protobuf path, regenerate files
1 parent 71e98af commit a31bc28

14 files changed

+3815
-1102
lines changed

bin/set-edoc-hidden

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#!/usr/bin/env sh
22

3-
[ -f "$1" ] || exit 1
4-
5-
FILE="$1"
63
HIDDEN="%% @hidden"
74

8-
if [ "$(head -n 1 $FILE)" != "$HIDDEN" ]; then
9-
echo "0a\n$HIDDEN\n.\nw" | ed "$FILE" >/dev/null
10-
fi
5+
for FILE in "$@"
6+
do
7+
[ -f "$FILE" ] || exit 1
8+
9+
if [ "$(head -n 1 $FILE)" != "$HIDDEN" ]; then
10+
echo "0a\n$HIDDEN\n.\nw" | ed "$FILE" >/dev/null
11+
fi
12+
done

doc/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ $ rebar3 protobuf compile
192192
<tr><td><a href="oc_span.md" class="module">oc_span</a></td></tr>
193193
<tr><td><a href="oc_span_ctx_binary.md" class="module">oc_span_ctx_binary</a></td></tr>
194194
<tr><td><a href="oc_span_ctx_header.md" class="module">oc_span_ctx_header</a></td></tr>
195+
<tr><td><a href="oc_span_sweeper.md" class="module">oc_span_sweeper</a></td></tr>
195196
<tr><td><a href="oc_span_transform.md" class="module">oc_span_transform</a></td></tr>
196197
<tr><td><a href="oc_stat.md" class="module">oc_stat</a></td></tr>
197198
<tr><td><a href="oc_stat_aggregation.md" class="module">oc_stat_aggregation</a></td></tr>

doc/edoc-info

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
{modules,[oc_reporter,oc_reporter_noop,oc_reporter_sequential,
44
oc_reporter_stdout,oc_reporter_zipkin,oc_sampler,oc_sampler_always,
55
oc_sampler_impl,oc_sampler_never,oc_sampler_probability,oc_server,
6-
oc_span,oc_span_ctx_binary,oc_span_ctx_header,oc_span_transform,
7-
oc_stat,oc_stat_aggregation,oc_stat_aggregation_count,
8-
oc_stat_aggregation_distribution,oc_stat_aggregation_latest,
9-
oc_stat_aggregation_sum,oc_stat_config,oc_stat_exporter,
10-
oc_stat_exporter_stdout,oc_stat_measure,oc_stat_transform,
11-
oc_stat_unit,oc_stat_view,oc_std_encoder,oc_tag_ctx_binary,
12-
oc_tag_ctx_header,oc_tags,oc_trace,ocp,opencensus,opencensus_app,
13-
opencensus_sup]}.
6+
oc_span,oc_span_ctx_binary,oc_span_ctx_header,oc_span_sweeper,
7+
oc_span_transform,oc_stat,oc_stat_aggregation,
8+
oc_stat_aggregation_count,oc_stat_aggregation_distribution,
9+
oc_stat_aggregation_latest,oc_stat_aggregation_sum,oc_stat_config,
10+
oc_stat_exporter,oc_stat_exporter_stdout,oc_stat_measure,
11+
oc_stat_transform,oc_stat_unit,oc_stat_view,oc_std_encoder,
12+
oc_tag_ctx_binary,oc_tag_ctx_header,oc_tags,oc_trace,ocp,opencensus,
13+
opencensus_app,opencensus_sup]}.

doc/index.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,29 @@ Headers = [{oc_span_ctx_header:field_name(), EncodedSpanCtx}],
8080

8181
[Prometheus](https://github.com/deadtrickster/opencensus-erlang-prometheus): Exports spans as Prometheus metrics.
8282

83+
[DataDog][oc_datadog]: Export spans to DataDog APM
84+
85+
#### <a name="Sweeper">Cleaning Up Abandoned Spans</a> ####
86+
87+
Active spans have their data stored in an ETS table. When a span is finished it is removed from the active spans table and moved to a table handled by the reporter process. If a span isn't finished, either because of a mistake in the code creating and finishing spans, or the process with open spans crashes before being able to finish the spans, there would be a memory leak.
88+
89+
The `oc_span_sweeper` process checks for active spans which started greater than a configurable (`span_ttl`) duration, with a default of 5 minutes. There are 4 strategies for handling a span that is older than the time to live (`strategy`):
90+
91+
* `drop`: Spans are removed from the active span table and a log message is written with the total number of spans being dropped in this sweep.
92+
* `finish`: Each span is finished as is.
93+
* `failed_attribute_and_finish`: An attribute `finished_by_sweeper` with value `true` is added to the span data and then the span is finished.
94+
* Custom function: Any funtion with type spec `fun((opencensus:span()) -> ok)` can be used. Note that the span is not removed from the active spans table if this method is used and the function must do the removal if it deems it necessary.
95+
96+
An example configuration in `sys.config` to run a check every 5 minutes, dropping active spans older than 5 minutes can be found in the example project `helloworld`, `examples/helloworld/config/sys.config`, the sweeper snippet looks like:
97+
98+
``` erlang
99+
{sweeper, #{interval => 300000,
100+
strategy => drop,
101+
span_ttl => 300000}}
102+
```
103+
104+
To disable sweeping set `interval` to `infinity`.
105+
83106
### <a name="Logging">Logging</a> ###
84107

85108
OTP-21 includes a new logging framework. When a context is created with a span (for example `ocp:with_child_span/1` or `oc_trace:with_child_span/2`) opencensus will update the current process's logger metadata to include the `trace_id`, `span_id` and `trace_options` with the latest ids under the key `span_ctx`, `trace_options` will be `1` if the trace is enabled. To use these with the default formatter you can create a custom template that includes them if they exist like so:
@@ -147,7 +170,9 @@ oc_stat_view:subscribe(#{name => "opencensus.io/http/server/server_latency",
147170
```
148171
prometheus_registry:register_collector(oc_stat_exporter_prometheus)
149172
```
150-
173+
174+
[DogStatsD][oc_datadog]: Export stat views as DataDog metrics.
175+
151176
### Development
152177

153178
```sh
@@ -168,3 +193,5 @@ Language independent interface types for Census are found in the `opencensus-pro
168193
$ git clone https://github.com/census-instrumentation/opencensus-proto priv/opencensus-proto
169194
$ rebar3 protobuf compile
170195
```
196+
197+
[oc_datadog]: https://github.com/hauleth/oc_datadog

doc/oc_reporter.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@ __This module defines the `oc_reporter` behaviour.__<br /> Required callback fun
1717
## Function Index ##
1818

1919

20-
<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#handle_call-3">handle_call/3</a></td><td></td></tr><tr><td valign="top"><a href="#handle_cast-2">handle_cast/2</a></td><td></td></tr><tr><td valign="top"><a href="#handle_info-2">handle_info/2</a></td><td></td></tr><tr><td valign="top"><a href="#init-1">init/1</a></td><td></td></tr><tr><td valign="top"><a href="#start_link-0">start_link/0</a></td><td></td></tr><tr><td valign="top"><a href="#store_span-1">store_span/1</a></td><td></td></tr><tr><td valign="top"><a href="#terminate-2">terminate/2</a></td><td></td></tr></table>
20+
<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#code_change-3">code_change/3</a></td><td></td></tr><tr><td valign="top"><a href="#handle_call-3">handle_call/3</a></td><td></td></tr><tr><td valign="top"><a href="#handle_cast-2">handle_cast/2</a></td><td></td></tr><tr><td valign="top"><a href="#handle_info-2">handle_info/2</a></td><td></td></tr><tr><td valign="top"><a href="#init-1">init/1</a></td><td></td></tr><tr><td valign="top"><a href="#start_link-0">start_link/0</a></td><td></td></tr><tr><td valign="top"><a href="#store_span-1">store_span/1</a></td><td></td></tr><tr><td valign="top"><a href="#terminate-2">terminate/2</a></td><td></td></tr></table>
2121

2222

2323
<a name="functions"></a>
2424

2525
## Function Details ##
2626

27+
<a name="code_change-3"></a>
28+
29+
### code_change/3 ###
30+
31+
`code_change(X1, State, X3) -> any()`
32+
2733
<a name="handle_call-3"></a>
2834

2935
### handle_call/3 ###

doc/oc_span_sweeper.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
3+
# Module oc_span_sweeper #
4+
* [Function Index](#index)
5+
* [Function Details](#functions)
6+
7+
__Behaviours:__ [`gen_statem`](gen_statem.md).
8+
9+
<a name="index"></a>
10+
11+
## Function Index ##
12+
13+
14+
<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#callback_mode-0">callback_mode/0</a></td><td></td></tr><tr><td valign="top"><a href="#code_change-4">code_change/4</a></td><td></td></tr><tr><td valign="top"><a href="#handle_event-4">handle_event/4</a></td><td></td></tr><tr><td valign="top"><a href="#init-1">init/1</a></td><td></td></tr><tr><td valign="top"><a href="#start_link-0">start_link/0</a></td><td></td></tr><tr><td valign="top"><a href="#terminate-3">terminate/3</a></td><td></td></tr></table>
15+
16+
17+
<a name="functions"></a>
18+
19+
## Function Details ##
20+
21+
<a name="callback_mode-0"></a>
22+
23+
### callback_mode/0 ###
24+
25+
`callback_mode() -> any()`
26+
27+
<a name="code_change-4"></a>
28+
29+
### code_change/4 ###
30+
31+
`code_change(X1, State, Data, X4) -> any()`
32+
33+
<a name="handle_event-4"></a>
34+
35+
### handle_event/4 ###
36+
37+
`handle_event(X1, X2, X3, Data) -> any()`
38+
39+
<a name="init-1"></a>
40+
41+
### init/1 ###
42+
43+
`init(X1) -> any()`
44+
45+
<a name="start_link-0"></a>
46+
47+
### start_link/0 ###
48+
49+
`start_link() -> any()`
50+
51+
<a name="terminate-3"></a>
52+
53+
### terminate/3 ###
54+
55+
`terminate(Reason, State, Data) -> any()`
56+

doc/oc_stat.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Records one or multiple measurements with the same tags at once.</td></tr></tabl
2626
### export/0 ###
2727

2828
<pre><code>
29-
export() -&gt; <a href="oc_stat_view.md#type-view_data">oc_stat_view:view_data()</a>
29+
export() -&gt; [<a href="oc_stat_view.md#type-view_data">oc_stat_view:view_data()</a>]
3030
</code></pre>
3131
<br />
3232

doc/oc_stat_aggregation.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,53 @@
22

33
# Module oc_stat_aggregation #
44
* [Description](#description)
5+
* [Data Types](#types)
56

67
Aggregation represents a data aggregation method.
78

89
__This module defines the `oc_stat_aggregation` behaviour.__<br /> Required callback functions: `init/3`, `type/0`, `add_sample/4`, `export/2`, `clear_rows/2`.
910

11+
<a name="types"></a>
12+
13+
## Data Types ##
14+
15+
16+
17+
18+
### <a name="type-data">data()</a> ###
19+
20+
21+
<pre><code>
22+
data() = <a href="#type-data">data</a>(latest, number()) | <a href="#type-data">data</a>(count, number()) | <a href="#type-data">data</a>(sum, #{count =&gt; non_neg_integer(), mean =&gt; number(), sum =&gt; number()}) | <a href="#type-data">data</a>(distribution, #{count =&gt; non_neg_integer(), mean =&gt; number(), sum =&gt; number(), buckets =&gt; [{number(), non_neg_integer()}]})
23+
</code></pre>
24+
25+
26+
27+
28+
### <a name="type-data">data()</a> ###
29+
30+
31+
<pre><code>
32+
data(Type, AggregationValue) = #{type =&gt; Type, rows =&gt; <a href="#type-data_rows">data_rows</a>(AggregationValue)}
33+
</code></pre>
34+
35+
36+
37+
38+
### <a name="type-data_rows">data_rows()</a> ###
39+
40+
41+
<pre><code>
42+
data_rows(AggregationValue) = [#{tags =&gt; <a href="#type-tv">tv()</a>, value =&gt; AggregationValue}]
43+
</code></pre>
44+
45+
46+
47+
48+
### <a name="type-tv">tv()</a> ###
49+
50+
51+
<pre><code>
52+
tv() = [<a href="oc_tags.md#type-value">oc_tags:value()</a>]
53+
</code></pre>
54+

elvis.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{config,
66
[#{dirs => ["src"],
77
filter => "*.erl",
8-
ignore => ["src/oc_trace_pb.erl"],
8+
ignore => ["src/oc_trace_pb.erl", "src/oc_trace_config_pb.erl"],
99
rules => [{elvis_style, god_modules, #{ignore => [ocp]}},
1010
{elvis_style, no_debug_call, #{ignore => [oc_reporter_stdout, oc_stat_exporter_stdout]}},
1111
{elvis_style, dont_repeat_yourself, #{min_complexity => 20}},

include/oc_trace_config_pb.hrl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
%% -*- coding: utf-8 -*-
2+
%% Automatically generated, do not edit
3+
%% Generated by gpb_compile version 4.4.1
4+
5+
-ifndef(oc_trace_config_pb).
6+
-define(oc_trace_config_pb, true).
7+
8+
-define(oc_trace_config_pb_gpb_version, "4.4.1").
9+
10+
-ifndef('TRACE_CONFIG_PB_PB_H').
11+
-define('TRACE_CONFIG_PB_PB_H', true).
12+
-record(trace_config_pb,
13+
{sampler :: {probability_sampler, oc_trace_config_pb:probability_sampler_pb()} | {constant_sampler, oc_trace_config_pb:constant_sampler_pb()} | {rate_limiting_sampler, oc_trace_config_pb:rate_limiting_sampler_pb()} | undefined, % oneof
14+
max_number_of_attributes = 0 :: integer() | undefined, % = 4, 32 bits
15+
max_number_of_annotations = 0 :: integer() | undefined, % = 5, 32 bits
16+
max_number_of_message_events = 0 :: integer() | undefined, % = 6, 32 bits
17+
max_number_of_links = 0 :: integer() | undefined % = 7, 32 bits
18+
}).
19+
-endif.
20+
21+
-ifndef('PROBABILITY_SAMPLER_PB_PB_H').
22+
-define('PROBABILITY_SAMPLER_PB_PB_H', true).
23+
-record(probability_sampler_pb,
24+
{samplingProbability = 0.0 :: float() | integer() | infinity | '-infinity' | nan | undefined % = 1
25+
}).
26+
-endif.
27+
28+
-ifndef('CONSTANT_SAMPLER_PB_PB_H').
29+
-define('CONSTANT_SAMPLER_PB_PB_H', true).
30+
-record(constant_sampler_pb,
31+
{decision = false :: boolean() | 0 | 1 | undefined % = 1
32+
}).
33+
-endif.
34+
35+
-ifndef('RATE_LIMITING_SAMPLER_PB_PB_H').
36+
-define('RATE_LIMITING_SAMPLER_PB_PB_H', true).
37+
-record(rate_limiting_sampler_pb,
38+
{qps = 0 :: integer() | undefined % = 1, 32 bits
39+
}).
40+
-endif.
41+
42+
-endif.

0 commit comments

Comments
 (0)