Skip to content

Commit

Permalink
Rename otel_span_limits to otel_limits
Browse files Browse the repository at this point in the history
  • Loading branch information
albertored committed Oct 7, 2023
1 parent bda86cb commit 37c1c7a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion apps/opentelemetry/include/otel_span.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
instrumentation_scope :: opentelemetry:instrumentation_scope() | undefined | '_'
}).

-record(span_limits, {
-record(limits, {
attribute_count_limit = 128 :: integer(), %% Maximum allowed attribute count per span;
attribute_value_length_limit = infinity :: integer() | infinity, %% Maximum allowed attribute value length
event_count_limit = 128 :: integer(), %% Maximum allowed span event count
Expand Down
2 changes: 1 addition & 1 deletion apps/opentelemetry/src/opentelemetry_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ start(_StartType, _StartArgs) ->
SupResult;
_ ->
%% set global span limits record based on configuration
otel_span_limits:set(Config),
otel_limits:set(Config),

Resource = otel_resource_detector:get_resource(),
_ = otel_tracer_provider_sup:start(?GLOBAL_TRACER_PROVIDER_NAME, Resource, Config),
Expand Down
10 changes: 5 additions & 5 deletions apps/opentelemetry/src/otel_configuration.erl
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ merge_with_os(AppEnv) ->

lists:foldl(fun(F, Acc) ->
F(AppEnv, Acc)
end, ConfigMap, [fun span_limits/2,
end, ConfigMap, [fun limits/2,
fun general/2,
fun sampler/2,
fun processors/2,
fun sweeper/2]).

-spec span_limits(list(), t()) -> t().
span_limits(AppEnv, ConfigMap) ->
merge_list_with_environment(config_mappings(span_limits), AppEnv, ConfigMap).
-spec limits(list(), t()) -> t().
limits(AppEnv, ConfigMap) ->
merge_list_with_environment(config_mappings(limits), AppEnv, ConfigMap).

-spec general(list(), t()) -> t().
general(AppEnv, ConfigMap) ->
Expand Down Expand Up @@ -322,7 +322,7 @@ config_mappings(general_sdk) ->

{"OTEL_SSP_EXPORT_TIMEOUT_MILLIS", ssp_exporting_timeout_ms, integer}
];
config_mappings(span_limits) ->
config_mappings(limits) ->
[{"OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT", attribute_count_limit, integer},
{"OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT", attribute_value_length_limit, integer_infinity},
{"OTEL_SPAN_EVENT_COUNT_LIMIT", event_count_limit, integer},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
%% limitations under the License.
%%
%% @doc Module for setting the global limits for the number of attributes,
%% events and links on a Span.
%% events and links.
%% @end
%%%-------------------------------------------------------------------------
-module(otel_span_limits).
-module(otel_limits).

-export([get/0,
set/1,
Expand All @@ -29,11 +29,11 @@

-include("otel_span.hrl").

-define(SPAN_LIMITS_KEY, {?MODULE, span_limits}).
-define(LIMITS_KEY, {?MODULE, limits}).

-spec get() -> #span_limits{}.
-spec get() -> #limits{}.
get() ->
persistent_term:get(?SPAN_LIMITS_KEY).
persistent_term:get(?LIMITS_KEY).

-spec set(otel_configuration:t()) -> ok.
set(#{attribute_count_limit := AttributeCountLimit,
Expand All @@ -42,13 +42,13 @@ set(#{attribute_count_limit := AttributeCountLimit,
link_count_limit := LinkCountLimit,
attribute_per_event_limit := AttributePerEventLimit,
attribute_per_link_limit := AttributePerLinkLimit}) ->
SpanLimits = #span_limits{attribute_count_limit=AttributeCountLimit,
Limits = #limits{attribute_count_limit=AttributeCountLimit,
attribute_value_length_limit=AttributeValueLengthLimit,
event_count_limit=EventCountLimit,
link_count_limit=LinkCountLimit,
attribute_per_event_limit=AttributePerEventLimit,
attribute_per_link_limit=AttributePerLinkLimit},
persistent_term:put(?SPAN_LIMITS_KEY, SpanLimits).
persistent_term:put(?LIMITS_KEY, Limits).

attribute_count_limit() ->
get_limit(attribute_count_limit, ?MODULE:get()).
Expand All @@ -68,15 +68,15 @@ attribute_per_event_limit() ->
attribute_per_link_limit() ->
get_limit(attribute_per_link_limit, ?MODULE:get()).

get_limit(attribute_count_limit, #span_limits{attribute_count_limit=AttributeCountLimit}) ->
get_limit(attribute_count_limit, #limits{attribute_count_limit=AttributeCountLimit}) ->
AttributeCountLimit;
get_limit(attribute_value_length_limit, #span_limits{attribute_value_length_limit=AttributeValueLengthLimit}) ->
get_limit(attribute_value_length_limit, #limits{attribute_value_length_limit=AttributeValueLengthLimit}) ->
AttributeValueLengthLimit;
get_limit(event_count_limit, #span_limits{event_count_limit=EventCountLimit}) ->
get_limit(event_count_limit, #limits{event_count_limit=EventCountLimit}) ->
EventCountLimit;
get_limit(link_count_limit, #span_limits{link_count_limit=LinkCountLimit}) ->
get_limit(link_count_limit, #limits{link_count_limit=LinkCountLimit}) ->
LinkCountLimit;
get_limit(attribute_per_event_limit, #span_limits{attribute_per_event_limit=AttributePerEventLimit}) ->
get_limit(attribute_per_event_limit, #limits{attribute_per_event_limit=AttributePerEventLimit}) ->
AttributePerEventLimit;
get_limit(attribute_per_link_limit, #span_limits{attribute_per_link_limit=AttributePerLinkLimit}) ->
get_limit(attribute_per_link_limit, #limits{attribute_per_link_limit=AttributePerLinkLimit}) ->
AttributePerLinkLimit.
12 changes: 6 additions & 6 deletions apps/opentelemetry/src/otel_span_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
-spec start_span(otel_ctx:t(), opentelemetry:span_name(), otel_sampler:t(), otel_id_generator:t(),
otel_span:start_opts()) -> {opentelemetry:span_ctx(), opentelemetry:span() | undefined}.
start_span(Ctx, Name, Sampler, IdGenerator, Opts) ->
SpanAttributeCountLimit = otel_span_limits:attribute_count_limit(),
SpanAttributeValueLengthLimit= otel_span_limits:attribute_value_length_limit(),
EventCountLimit = otel_span_limits:event_count_limit(),
LinkCountLimit = otel_span_limits:link_count_limit(),
AttributePerEventLimit = otel_span_limits:attribute_per_event_limit(),
AttributePerLinkLimit = otel_span_limits:attribute_per_link_limit(),
SpanAttributeCountLimit = otel_limits:attribute_count_limit(),
SpanAttributeValueLengthLimit= otel_limits:attribute_value_length_limit(),
EventCountLimit = otel_limits:event_count_limit(),
LinkCountLimit = otel_limits:link_count_limit(),
AttributePerEventLimit = otel_limits:attribute_per_event_limit(),
AttributePerLinkLimit = otel_limits:attribute_per_link_limit(),


Attributes = otel_attributes:new(maps:get(attributes, Opts, #{}),
Expand Down
24 changes: 12 additions & 12 deletions apps/opentelemetry/test/otel_configuration_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ all() ->
sampler_trace_id, sampler_trace_id_default, sampler_parent_based_one,
log_level, propagators, propagators_b3, propagators_b3multi, otlp_exporter,
jaeger_exporter, zipkin_exporter, none_exporter, app_env_exporter,
otlp_metrics_exporter, none_metrics_exporter, span_limits, bad_span_limits,
otlp_metrics_exporter, none_metrics_exporter, limits, bad_limits,
bad_app_config, deny_list, resource_detectors, span_processors].

init_per_testcase(empty_os_environment, Config) ->
Expand Down Expand Up @@ -139,7 +139,7 @@ init_per_testcase(resource_detectors, Config) ->
setup_env(Vars),

[{os_vars, Vars} | Config];
init_per_testcase(span_limits, Config) ->
init_per_testcase(limits, Config) ->
Vars = [{"OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT", "111"},
{"OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT", "009"},
{"OTEL_SPAN_EVENT_COUNT_LIMIT", "200"},
Expand All @@ -155,15 +155,15 @@ init_per_testcase(span_limits, Config) ->
link_count_limit => 1101,
attribute_per_event_limit => 400,
attribute_per_link_limit => 500},
ExpectedRecord = #span_limits{attribute_count_limit=111,
ExpectedRecord = #limits{attribute_count_limit=111,
attribute_value_length_limit=9,
event_count_limit=200,
link_count_limit=1101,
attribute_per_event_limit=400,
attribute_per_link_limit=500},

[{expected_opts, ExpectedOpts}, {expected_record, ExpectedRecord}, {os_vars, Vars} | Config];
init_per_testcase(bad_span_limits, Config) ->
init_per_testcase(bad_limits, Config) ->
Vars = [{"OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT", "aaa"},
{"OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT", "bbb"},
{"OTEL_SPAN_EVENT_COUNT_LIMIT", "1d4"},
Expand All @@ -174,7 +174,7 @@ init_per_testcase(bad_span_limits, Config) ->
setup_env(Vars),

ExpectedOpts = #{},
ExpectedRecord = #span_limits{attribute_count_limit=128,
ExpectedRecord = #limits{attribute_count_limit=128,
attribute_value_length_limit=infinity,
event_count_limit=128,
link_count_limit=128,
Expand Down Expand Up @@ -344,28 +344,28 @@ resource_detectors(_Config) ->

ok.

span_limits(Config) ->
compare_span_limits(Config).
limits(Config) ->
compare_limits(Config).

bad_span_limits(Config) ->
compare_span_limits(Config).
bad_limits(Config) ->
compare_limits(Config).

bad_app_config(_Config) ->
?assertMatch(#{attribute_value_length_limit := infinity},
otel_configuration:merge_with_os([{attribute_value_length_limit, "aaa"}])),

ok.

compare_span_limits(Config) ->
compare_limits(Config) ->
ExpectedRecord = ?config(expected_record, Config),
ExpectedOpts = maps:to_list(?config(expected_opts, Config)),
Opts = maps:to_list(otel_configuration:merge_with_os([])),

?assertIsSubset(ExpectedOpts, Opts),

otel_span_limits:set(maps:from_list(Opts)),
otel_limits:set(maps:from_list(Opts)),

SpanLimits = otel_span_limits:get(),
SpanLimits = otel_limits:get(),

%% verifies the defaults because the base record has the defaults set as well
?assertEqual(ExpectedRecord, SpanLimits),
Expand Down

0 comments on commit 37c1c7a

Please sign in to comment.