Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute limits should discard from the end #1534

Closed
fbogsany opened this issue Oct 27, 2023 · 0 comments · Fixed by #1536
Closed

Attribute limits should discard from the end #1534

fbogsany opened this issue Oct 27, 2023 · 0 comments · Fixed by #1536
Labels
bug Something isn't working

Comments

@fbogsany
Copy link
Contributor

Description of the bug

See #1533 (comment) for background. open-telemetry/opentelemetry-specification#1130 added span limits to the spec. A key requirement is:

  • set a limit of unique attribute keys such that:
  • for each unique attribute key, addition of which would result in exceeding
    the limit, SDK MUST discard that key/value pair.

Our implementation of span limits instead drops attributes added earlier when the attribute count limit is exceeded:

def trim_span_attributes(attrs)
return if attrs.nil?
excess = attrs.size - @span_limits.attribute_count_limit
excess.times { attrs.shift } if excess.positive?
truncate_attribute_values(attrs, @span_limits.attribute_length_limit)
nil
end

E.g. if ENV['OTEL_ATTRIBUTE_COUNT_LIMIT'] == '2' then the following code should produce a span with attributes {"a" => 1, "b" => 2} but instead it contains {"b" => 2, "c" => 3}:

tracer.in_span('bad limit', attributes: {"a" => 1, "b" => 2}) do |span|
  span["c"] = 3
end

Share a simplified reproduction if possible

ENV['OTEL_ATTRIBUTE_COUNT_LIMIT'] = '2'

require 'bundler/inline'

gemfile(true) do
  source 'https://rubygems.org'

  gem 'opentelemetry-api'
  gem 'opentelemetry-sdk'
end

require 'opentelemetry-api'
require 'opentelemetry-sdk'

span_processor = OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(
  OpenTelemetry::SDK::Trace::Export::ConsoleSpanExporter.new
)

OpenTelemetry::SDK.configure do |c|
  c.add_span_processor(span_processor)
end

SimpleTracer = OpenTelemetry.tracer_provider.tracer('Bug Report')

SimpleTracer.in_span('bad limit', attributes: {"a" => 1, "b" => 2}) do |span|
  span["c"] = 3
end

OpenTelemetry.tracer_provider.shutdown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant