12
12
% % See the License for the specific language governing permissions and
13
13
% % limitations under the License.
14
14
% %
15
- % % @doc
16
- % % A sampler is a function run on each started span that returns whether to
17
- % % record and propagate, only record or not record the span.
15
+ % % @doc Behaviour for defining samplers.
16
+ % %
17
+ % % A sampler should provide a function run on each started span that returns whether to
18
+ % % record and propagate, only record, or not record the span.
19
+ % %
20
+ % % For more information on the concept of <i>Sampling</i>, see
21
+ % % <a href="https://opentelemetry.io/docs/concepts/sampling/">Sampling in the OpenTelemetry
22
+ % % documentation</a>. For examples of configuring samplers or implementing your own sampler,
23
+ % % see <a href="https://opentelemetry.io/docs/languages/erlang/sampling/">the OpenTelemetry
24
+ % % Erlang documentation</a>.
18
25
% % @end
19
26
% %%-------------------------------------------------------------------------
20
27
-module (otel_sampler ).
30
37
t / 0 ]).
31
38
32
39
-callback setup (sampler_opts ()) -> sampler_config ().
40
+ % % Called when a sampler is created to set up the sampler.
41
+ % % Should return the sampler configuration that is then passed to other callbacks.
33
42
34
43
-callback description (sampler_config ()) -> description ().
44
+ % % Should return the description of the sampler.
35
45
36
46
-callback should_sample (
37
47
otel_ctx :t (),
42
52
opentelemetry :attributes_map (),
43
53
sampler_config ()
44
54
) -> sampling_result ().
55
+ % % Main callback that determines whether a span should be sampled.\
45
56
46
57
-include (" otel_sampler.hrl" ).
47
58
48
59
-type description () :: unicode :unicode_binary ().
60
+ % % The description of the sampler.
61
+
49
62
-type sampler_config () :: term ().
63
+ % % Any term used to configured a given sampler.
64
+
50
65
-type sampler_opts () :: term ().
66
+ % % Any options passed to a sampler.
67
+
51
68
-type builtin_sampler () ::
52
69
always_on
53
70
| always_off
59
76
local_parent_not_sampled => sampler_spec (),
60
77
root => sampler_spec ()
61
78
}}.
79
+ % % A built-in sampler.
80
+
62
81
-type sampler_spec () :: builtin_sampler () | {module (), sampler_opts ()}.
82
+
63
83
-type sampling_decision () :: ? DROP | ? RECORD_ONLY | ? RECORD_AND_SAMPLE .
84
+ % % The decision that a sampler can make on a given span.
85
+
64
86
-type sampling_result () :: {
65
87
sampling_decision (),
66
88
opentelemetry :attributes_map (),
67
89
opentelemetry :tracestate () | otel_tracestate :members ()
68
90
}.
91
+
69
92
-opaque t () :: {module (), description (), sampler_opts ()}.
93
+ % % A sampler.
70
94
95
+ % % @private
71
96
-spec new (sampler_spec ()) -> t ().
72
97
new (always_on ) ->
73
98
new ({otel_sampler_always_on , #{}});
@@ -81,6 +106,7 @@ new({Sampler, Opts}) ->
81
106
Config = Sampler :setup (Opts ),
82
107
{Sampler , Sampler :description (Config ), Config }.
83
108
109
+ % % @private
84
110
-spec should_sample (
85
111
t (),
86
112
otel_ctx :t (),
@@ -100,5 +126,6 @@ should_sample({Sampler, _, Config}, Ctx, TraceId, Links, SpanName, Kind, Attribu
100
126
Result
101
127
end .
102
128
129
+ % % @private
103
130
-spec description (t ()) -> description ().
104
131
description ({_ , Description , _ }) -> Description .
0 commit comments