diff --git a/apps/opentelemetry/src/otel_sampler.erl b/apps/opentelemetry/src/otel_sampler.erl index bbae7d5e..3e4e649b 100644 --- a/apps/opentelemetry/src/otel_sampler.erl +++ b/apps/opentelemetry/src/otel_sampler.erl @@ -19,7 +19,8 @@ %%%------------------------------------------------------------------------- -module(otel_sampler). --export([setup/1, +-export([new/3, + setup/1, get_description/1, always_on/7, always_off/7, @@ -31,26 +32,35 @@ -include("otel_sampler.hrl"). -include("otel_span.hrl"). --callback setup(module(), map()) -> t(). +-callback setup(sampler_opts()) -> t(). -type sampling_decision() :: ?DROP | ?RECORD_ONLY | ?RECORD_AND_SAMPLE. -type sampling_result() :: {sampling_decision(), opentelemetry:attributes(), opentelemetry:tracestate()}. -type description() :: unicode:unicode_binary(). --type sampler() :: {fun((otel_ctx:t(), - opentelemetry:trace_id(), - opentelemetry:links(), - opentelemetry:span_name(), - opentelemetry:span_kind(), - opentelemetry:attributes(), - term()) -> sampling_result()), description(), term()}. +-type sampler_fun() :: fun((otel_ctx:t(), + opentelemetry:trace_id(), + opentelemetry:links(), + opentelemetry:span_name(), + opentelemetry:span_kind(), + opentelemetry:attributes(), + term()) -> sampling_result()). +-type sampler() :: {sampler_fun(), description(), sampler_opts()}. +-type sampler_opts() :: term(). -opaque t() :: sampler(). --export_type([sampling_result/0, +-export_type([sampler_fun/0, + description/0, + sampling_result/0, sampling_decision/0, + sampler_opts/0, t/0]). -define(MAX_VALUE, 9223372036854775807). %% 2^63 - 1 --spec setup(atom() | {atom() | module(), term()}) -> t(). +-spec new(sampler_fun(), description(), sampler_opts()) -> t(). +new(DecisionFunction, Description, SamplerOpts) -> + {DecisionFunction, Description, SamplerOpts}. + +-spec setup(atom() | {atom() | module(), sampler_opts()}) -> t(). setup({Sampler, Opts}) -> setup(Sampler, Opts); setup(Sampler) when is_atom(Sampler) -> diff --git a/apps/opentelemetry/test/static_sampler.erl b/apps/opentelemetry/test/static_sampler.erl index 6d3cca55..19bb292d 100644 --- a/apps/opentelemetry/test/static_sampler.erl +++ b/apps/opentelemetry/test/static_sampler.erl @@ -6,6 +6,8 @@ %% sampler returns the value from the Opts map based on the SpanName or `NOT_RECORD' setup(Opts) -> - {fun(_, _, _, SpanName, _, _, Opts1) -> - {maps:get(SpanName, Opts1, ?DROP), [], []} - end, <<"StaticSampler">>, Opts}. + otel_sampler:new( + fun(_, _, _, SpanName, _, _, Opts1) -> {maps:get(SpanName, Opts1, ?DROP), [], []} end, + <<"StaticSampler">>, + Opts + ).