Skip to content

Make ExemplarReservoir implementations internally thread-safe #2367

Description

@kaylareopelle

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmetricsspec-complianceRequired for OpenTelemetry spec compliancespec:stableRelated to a stable specification

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions