diff --git a/apps/opentelemetry/include/otel_span.hrl b/apps/opentelemetry/include/otel_span.hrl index 20707c4a..c28f3efe 100644 --- a/apps/opentelemetry/include/otel_span.hrl +++ b/apps/opentelemetry/include/otel_span.hrl @@ -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 diff --git a/apps/opentelemetry/src/opentelemetry_app.erl b/apps/opentelemetry/src/opentelemetry_app.erl index 57891747..29c27679 100644 --- a/apps/opentelemetry/src/opentelemetry_app.erl +++ b/apps/opentelemetry/src/opentelemetry_app.erl @@ -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), diff --git a/apps/opentelemetry/src/otel_configuration.erl b/apps/opentelemetry/src/otel_configuration.erl index 2b7eb53d..dd9f793c 100644 --- a/apps/opentelemetry/src/otel_configuration.erl +++ b/apps/opentelemetry/src/otel_configuration.erl @@ -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) -> @@ -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}, diff --git a/apps/opentelemetry/src/otel_span_limits.erl b/apps/opentelemetry/src/otel_limits.erl similarity index 73% rename from apps/opentelemetry/src/otel_span_limits.erl rename to apps/opentelemetry/src/otel_limits.erl index 1fcd895b..08aace99 100644 --- a/apps/opentelemetry/src/otel_span_limits.erl +++ b/apps/opentelemetry/src/otel_limits.erl @@ -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, @@ -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, @@ -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()). @@ -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. diff --git a/apps/opentelemetry/src/otel_span_utils.erl b/apps/opentelemetry/src/otel_span_utils.erl index 0c9b16fd..210d92d1 100644 --- a/apps/opentelemetry/src/otel_span_utils.erl +++ b/apps/opentelemetry/src/otel_span_utils.erl @@ -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, #{}), diff --git a/apps/opentelemetry/test/otel_configuration_SUITE.erl b/apps/opentelemetry/test/otel_configuration_SUITE.erl index 4f292c12..9aa06f8b 100644 --- a/apps/opentelemetry/test/otel_configuration_SUITE.erl +++ b/apps/opentelemetry/test/otel_configuration_SUITE.erl @@ -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) -> @@ -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"}, @@ -155,7 +155,7 @@ 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, @@ -163,7 +163,7 @@ init_per_testcase(span_limits, Config) -> 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"}, @@ -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, @@ -344,11 +344,11 @@ 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}, @@ -356,16 +356,16 @@ bad_app_config(_Config) -> 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),