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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ Increment the:

## [Unreleased]

* [METRICS SDK] Enforce a runtime minimum scale of `-11` for
`Base2ExponentialHistogramAggregation`, so a recording that spans the full
double range no longer downscales without end.
[#4353](https://github.com/open-telemetry/opentelemetry-cpp/pull/4353)

* [LOGS] Fix undefined behavior in `Logger::EmitLogRecord()` when a logger is
enabled (e.g. via `LoggerProvider::UpdateLoggerConfigurator()`) after
`CreateLogRecord()` was called while it was still disabled. The disabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ constexpr std::int32_t kMaxScaleMin = -10;
constexpr std::int32_t kMaxScaleMax = 20;
constexpr std::size_t kMaxSizeMin = 2;

// Lower bound for the scale chosen at runtime by automatic downscaling. The specification only
// requires a "reasonable minimum". At -11 every finite double maps to a bucket index in [-1, 0],
// so the whole range fits in kMaxSizeMin buckets and no configuration needs more than its
// max_size. This bounds the runtime scale only; max_scale still starts no lower than kMaxScaleMin.
constexpr std::int32_t kMinRuntimeScale = -11;

class Base2ExponentialHistogramAggregationConfig : public AggregationConfig
{
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,17 @@ class Base2ExponentialHistogramAggregation : public Aggregation
private:
void AggregateIntoBuckets(std::unique_ptr<AdaptingCircularBufferCounter> &buckets,
double value) noexcept;
void Downscale(uint32_t by) noexcept;

/* Reduces the scale by up to `by`, stopping at kMinRuntimeScale. Returns the reduction that was
* actually applied, which callers must use to shift bucket indices. */
uint32_t Downscale(uint32_t by) noexcept;

mutable opentelemetry::common::SpinLockMutex lock_;
Base2ExponentialHistogramPointData point_data_;
Base2ExponentialHistogramIndexer indexer_;
bool record_min_max_ = true;
// Keeps the scale floor warning off the record hot path after the first occurrence.
bool floor_warning_emitted_ = false;
};

} // namespace metrics
Expand Down
Loading