open-telemetry / open-telemetry/opentelemetry-ruby

Make `ExemplarReservoir` implementations internally thread-safe

Open
#2,367 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug metrics spec-compliance spec:stable
Dominant language
Ruby
Stars
606
Forks
301
Avg merge
3d 19h
Merged PRs (30d)
42

Description

Spec requirement

All ExemplarReservoir methods MUST be safe for concurrent use (sdk.md:1984-2001, Concurrency requirements).

Current behavior

SimpleFixedSizeExemplarReservoir and AlignedHistogramBucketExemplarReservoir (exemplar/simple_fixed_size_exemplar_reservoir.rb (permalink), exemplar/aligned_histogram_bucket_exemplar_reservoir.rb (permalink)) have no internal locking — their @num_measurements_seen/bucket-array mutation in #offer is unsynchronized, relying entirely on the caller (MetricStream#update, itself mutex-guarded per-stream) to serialize access. This holds for the shipped call path but isn't a property of the reservoir classes themselves, as the spec requires.

Suggested fix

Add a mutex around the mutable state in both reservoir implementations' #offer/#collect methods, so they're safe even if called from outside the one guarded call path the SDK currently uses.

Related rows in SPEC_COMPLIANCE_METRICS.md

SDK-65

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with exemplar/simple_fixed_size_exemplar_reservoir.rb and exemplar/aligned_histogram_bucket_exemplar_reservoir.rb, focusing on their offer and collect methods and the mutable measurement and bucket state. Review the SDK concurrency requirement at sdk.md:1984-2001 and the existing MetricStream#update call path. Done means both reservoir implementations are internally safe for concurrent use without relying on the caller's mutex.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
observability
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.