Skip to content

HistogramMetric.record is not thread-safe #608

Closed
@angelo-ebay

Description

@angelo-ebay

Hello OpenTelemetry friends, we've recently adopted OpenTelemetry metrics at eBay but we're experiencing an access race in HistogramMetricSdk.boundInstruments.

HistogramMetric.record is not thread-safe. Or, from an implementation perspective, HistogramMetricSdk.bind(labelSet:) is not thread safe.

MeterSdk reads boundInstruments of histograms during its collect implementation but it's possible for other threads to simultaneously write to boundInstruments while recording histogram values. This write occurs in HistogramMetricSdk.bind(labelSet:) when a new boundInstrument is added to the boundInstruments dictionary. MeterSdk uses collectLock to synchronize access to doubleHistograms but does not synchronize writes to the boundInstruments dictionary of histograms.

I've read that there is a new stable metrics implementation but the legacy implementation is fully functional so I'm wondering:

  • Are you open to accepting a PR to fix the synchronization issue in the legacy implementation although its replacement is in active development? I've noticed other instruments like as CounterMetricSdkBase have locks to synchronize access to boundInstruments
  • Is my better course of action to migrate to the new stable metrics implementation instead?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions