Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb committed Sep 28, 2023
1 parent a45081a commit 2e1e696
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
21 changes: 21 additions & 0 deletions api/include/opentelemetry/metrics/meter.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class Histogram;
template <typename T>
class UpDownCounter;

template <typename T>
class Gauge;

class ObservableInstrument;

/**
Expand Down Expand Up @@ -91,6 +94,24 @@ class Meter
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;

/**
* Creates a Gauge with the passed characteristics and returns a
* unique_ptr to that Gauge
*
* @param name the name of the new Gauge.
* @param description a brief description of what the Gauge is used for.
* @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html.
*/
virtual nostd::unique_ptr<Gauge<uint64_t>> CreateInt64Gauge(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;

virtual nostd::unique_ptr<Gauge<double>> CreateDoubleGauge(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;

/**
* Creates a Asynchronouse (Observable) Gauge with the passed characteristics and returns a
* shared_ptr to that Observable Gauge
Expand Down
42 changes: 42 additions & 0 deletions api/include/opentelemetry/metrics/sync_instruments.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,47 @@ class UpDownCounter : public SynchronousInstrument
}
};

/** An Gauge instrument that records value. */

template <class T>
class Gauge : public SynchronousInstrument
{
public:
/**
* Records the current value.
*
* @param value The measurement value. MUST be non-negative.
*/
virtual void Record(T value, const context::Context &context) noexcept = 0;

/**
* Records a value with a set of attributes.
*
* @param value The measurement value. MUST be non-negative.
* @param attributes A set of attributes to associate with the value.
*/
virtual void Record(T value,
const common::KeyValueIterable &attributes,
const context::Context &context) noexcept = 0;

template <class U,
nostd::enable_if_t<common::detail::is_key_value_iterable<U>::value> * = nullptr>
void Record(T value, const U &attributes, const context::Context &context) noexcept
{
this->Record(value, common::KeyValueIterableView<U>{attributes}, context);
}

void Record(
T value,
std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> attributes,
const context::Context &context) noexcept
{
this->Record(value,
nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
attributes.begin(), attributes.end()},
context);
}
};

} // namespace metrics
OPENTELEMETRY_END_NAMESPACE
10 changes: 10 additions & 0 deletions sdk/include/opentelemetry/sdk/metrics/meter.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ class Meter final : public opentelemetry::metrics::Meter
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override;

nostd::unique_ptr<opentelemetry::metrics::Gauge<uint64_t>> CreateInt64Gauge(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override;

nostd::unique_ptr<opentelemetry::metrics::Gauge<double>> CreateDoubleGauge(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override;

nostd::shared_ptr<opentelemetry::metrics::ObservableInstrument> CreateInt64ObservableGauge(
nostd::string_view name,
nostd::string_view description = "",
Expand Down
31 changes: 31 additions & 0 deletions sdk/include/opentelemetry/sdk/metrics/sync_instruments.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,37 @@ class DoubleHistogram : public Synchronous, public opentelemetry::metrics::Histo
void Record(double value, const opentelemetry::context::Context &context) noexcept override;
};

class LongGauge : public Synchronous, public opentelemetry::metrics::Gauge<int64_t>
{
{
public:
/**
* Records the current value.
*
* @param value The measurement value. MUST be non-negative.
*/
virtual void Record(int64_t value, const context::Context &context) noexcept{

}

};

class DoubleGauge : public Synchronous, public opentelemetry::metrics::Gauge<double>
{
{
public:
/**
* Records the current value.
*
* @param value The measurement value. MUST be non-negative.
*/
virtual void Record(int64_t value, const context::Context &context) noexcept{

}

};


} // namespace metrics
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE

0 comments on commit 2e1e696

Please sign in to comment.