Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ Increment the:

## [Unreleased]

* [METRICS SDK] Fix Windows metrics tail latency on the synchronous record path:
`SyncMetricStorage::attribute_hashmap_lock_` now uses `std::mutex` instead of
`common::SpinLockMutex`. The spin lock's final `sleep_for(1ms)` back-off is
rounded up to the Windows timer quantum (~15.6 ms), so a waiter contending
on a hot instrument could stall for a full quantum, inflating tail latency.
`std::mutex` blocks the waiter instead. Only this one contended lock changes;
the API `SpinLockMutex` and all other SDK locks are unchanged.
[#4245](https://github.com/open-telemetry/opentelemetry-cpp/pull/4245)
* [CONFIGURATION] Add the probability sampler to file configuration
[#4334](https://github.com/open-telemetry/opentelemetry-cpp/pull/4334)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage
}
#endif
static MetricAttributes attr = MetricAttributes{};
std::lock_guard<opentelemetry::common::SpinLockMutex> guard(attribute_hashmap_lock_);
std::lock_guard<std::mutex> guard(attribute_hashmap_lock_);
#ifdef OPENTELEMETRY_HAVE_METRICS_BOUND_INSTRUMENTS_PREVIEW
MetricAttributes resolved = ResolveCardinality(attr);
attributes_hashmap_->GetOrSetDefault(std::move(resolved), create_default_aggregation_)
Expand Down Expand Up @@ -131,7 +131,7 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage
#endif

MetricAttributes attr{attributes, attributes_processor_.get()};
std::lock_guard<opentelemetry::common::SpinLockMutex> guard(attribute_hashmap_lock_);
std::lock_guard<std::mutex> guard(attribute_hashmap_lock_);
#ifdef OPENTELEMETRY_HAVE_METRICS_BOUND_INSTRUMENTS_PREVIEW
// Resolve via the unified cardinality policy so unbound and bound paths
// share one combined limit (see ResolveCardinality()).
Expand Down Expand Up @@ -161,7 +161,7 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage
}
#endif
static MetricAttributes attr = MetricAttributes{};
std::lock_guard<opentelemetry::common::SpinLockMutex> guard(attribute_hashmap_lock_);
std::lock_guard<std::mutex> guard(attribute_hashmap_lock_);
#ifdef OPENTELEMETRY_HAVE_METRICS_BOUND_INSTRUMENTS_PREVIEW
MetricAttributes resolved = ResolveCardinality(attr);
attributes_hashmap_->GetOrSetDefault(std::move(resolved), create_default_aggregation_)
Expand All @@ -188,7 +188,7 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage
}
#endif
MetricAttributes attr{attributes, attributes_processor_.get()};
std::lock_guard<opentelemetry::common::SpinLockMutex> guard(attribute_hashmap_lock_);
std::lock_guard<std::mutex> guard(attribute_hashmap_lock_);
#ifdef OPENTELEMETRY_HAVE_METRICS_BOUND_INSTRUMENTS_PREVIEW
MetricAttributes resolved = ResolveCardinality(std::move(attr));
// cppcheck-suppress accessMoved
Expand Down Expand Up @@ -300,7 +300,7 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage
nostd::shared_ptr<ExemplarReservoir> exemplar_reservoir_;
#endif
TemporalMetricStorage temporal_metric_storage_;
opentelemetry::common::SpinLockMutex attribute_hashmap_lock_;
std::mutex attribute_hashmap_lock_;
#ifdef OPENTELEMETRY_HAVE_METRICS_BOUND_INSTRUMENTS_PREVIEW
// NOTE: ENABLE_METRICS_BOUND_INSTRUMENTS_PREVIEW changes the layout and
// vtable of SyncMetricStorage (these conditional members and the virtual
Expand Down
8 changes: 4 additions & 4 deletions sdk/src/metrics/state/sync_metric_storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <mutex>
#include <utility>

#include "opentelemetry/common/spin_lock_mutex.h"
#include "opentelemetry/common/timestamp.h"
#include "opentelemetry/nostd/function_ref.h"
#include "opentelemetry/nostd/span.h"
Expand All @@ -23,6 +22,7 @@
# include <unordered_set>
# include <vector>

# include "opentelemetry/common/spin_lock_mutex.h"
# include "opentelemetry/sdk/common/global_log_handler.h"
# include "opentelemetry/sdk/metrics/aggregation/aggregation.h"
# include "opentelemetry/sdk/metrics/data/exemplar_data.h"
Expand Down Expand Up @@ -51,7 +51,7 @@ bool SyncMetricStorage::Collect(CollectorHandle *collector,
std::vector<std::shared_ptr<BoundEntry>> entry_snapshot;
#endif
{
std::lock_guard<opentelemetry::common::SpinLockMutex> guard(attribute_hashmap_lock_);
std::lock_guard<std::mutex> guard(attribute_hashmap_lock_);
delta_metrics = std::move(attributes_hashmap_);
attributes_hashmap_.reset(new AttributesHashMap(aggregation_config_->cardinality_limit_));
#ifdef OPENTELEMETRY_HAVE_METRICS_BOUND_INSTRUMENTS_PREVIEW
Expand Down Expand Up @@ -142,7 +142,7 @@ bool SyncMetricStorage::Collect(CollectorHandle *collector,
// Drop snapshot refs so use_count reflects only storage + user holders.
entry_snapshot.clear();
{
std::lock_guard<opentelemetry::common::SpinLockMutex> guard(attribute_hashmap_lock_);
std::lock_guard<std::mutex> guard(attribute_hashmap_lock_);
for (const auto &k : snapshot_keys)
{
auto it = bound_entries_.find(k);
Expand Down Expand Up @@ -189,7 +189,7 @@ std::shared_ptr<BoundSyncWritableMetricStorage> SyncMetricStorage::Bind(
// Filter attributes once, at bind time.
MetricAttributes filtered{attributes, attributes_processor_.get()};

std::lock_guard<opentelemetry::common::SpinLockMutex> guard(attribute_hashmap_lock_);
std::lock_guard<std::mutex> guard(attribute_hashmap_lock_);

// Dedupe: same post-filter attribute set returns the same bound entry.
auto it = bound_entries_.find(filtered);
Expand Down
Loading