open-telemetry / open-telemetry/opentelemetry-ruby
LogRecord#attributes= setter does not update @total_recorded_attributes
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 606
- Forks
- 301
- Avg merge
- 3d 19h
- Merged PRs (30d)
- 42
Description
Description of the bug
When mutating a LogRecord's attributes after initialization (e.g. in a custom LogRecordProcessor#on_emit), the attributes= setter updates the attributes hash but does not recalculate @total_recorded_attributes. This means to_log_record_data reports a stale count from initialization time.
There is no public API to update @total_recorded_attributes — the only workaround is instance_variable_set(:@total_recorded_attributes, attrs.size), which is fragile and depends on SDK internals.
Expected behavior: Either attributes= should automatically update @total_recorded_attributes, or a public method should be provided to recalculate it.
Relevant code: logs/lib/opentelemetry/sdk/logs/log_record.rb (https://github.com/open-telemetry/opentelemetry-ruby/blob/main/logs_sdk/lib/opentelemetry/sdk/logs/log_record.rb) — @total_recorded_attributes is set once in initialize and never updated when attributes is reassigned via the attr_accessor.
Here's the merge request/project where I encountered this issue: https://gitlab.com/gitlab-org/developer-relations/contributor-success/contributors-gitlab-com/-/merge_requests/2325
Share details about your runtime
- Operating system details: Linux, Debian 12 (bookworm), aarch64
- RUBY_ENGINE: "ruby"
- RUBY_VERSION: "4.0.5"
- RUBY_DESCRIPTION: "ruby 4.0.5 (2026-05-20 revision 64336ffd0e) +PRISM aarch64-linux"
Share a simplified reproduction if possible
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
gem 'opentelemetry-api'
gem 'opentelemetry-sdk'
gem 'opentelemetry-logs-sdk'
end
require 'opentelemetry-api'
require 'opentelemetry-sdk'
require 'opentelemetry/sdk/logs'
log_record = OpenTelemetry::SDK::Logs::LogRecord.new(
body: 'test message',
attributes: { 'key1' => 'value1' }
)
puts "Initial attributes count: #{log_record.instance_variable_get(:@total_recorded_attributes)}"
# => 1
log_record.attributes = { 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }
puts "Attributes after reassignment: #{log_record.attributes.size}"
# => 3
puts "total_recorded_attributes (stale): #{log_record.instance_variable_get(:@total_recorded_attributes)}"
# => 1 (BUG: should be 3)
data = log_record.to_log_record_data
puts "Reported in log_record_data: #{data.total_recorded_attributes}"
# => 1 (stale)
Tip: React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in logs_sdk/lib/opentelemetry/sdk/logs/log_record.rb, focusing on LogRecord#attributes=, initialize, and to_log_record_data. Reproduce the reassignment shown in the issue, then add regression coverage for the reported stale count. Done means reassigned attributes produce the correct total_recorded_attributes in log record data.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- observability-sre
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 74/100