Skip to content

Commit

Permalink
Merge pull request #1 from gimletlabs/sync-gauge
Browse files Browse the repository at this point in the history
Sync gauge
  • Loading branch information
zasgar authored Dec 12, 2023
2 parents 46e20a4 + d0d34d0 commit d2317e6
Show file tree
Hide file tree
Showing 14 changed files with 853 additions and 140 deletions.
24 changes: 24 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,27 @@ class Meter
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;

#if OPENTELEMETRY_ABI_VERSION_NO >= 2
/**
* Creates a Gauge with the passed characteristics and returns a
* unique_ptr to that Gauge
* @since ABI_VERSION 2
*
* @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;
#endif

/**
* Creates a Asynchronouse (Observable) Gauge with the passed characteristics and returns a
* shared_ptr to that Observable Gauge
Expand Down
43 changes: 43 additions & 0 deletions api/include/opentelemetry/metrics/noop.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ class NoopHistogram : public Histogram<T>
const common::KeyValueIterable & /* attributes */,
const context::Context & /* context */) noexcept override
{}
#if OPENTELEMETRY_ABI_VERSION_NO >= 2
void Record(T /*value*/,
const opentelemetry::common::KeyValueIterable & /*attributes*/) noexcept override
{}

void Record(T /*value*/) noexcept override {}
#endif
};

template <class T>
Expand All @@ -64,6 +71,23 @@ class NoopUpDownCounter : public UpDownCounter<T>
{}
};

#if OPENTELEMETRY_ABI_VERSION_NO >= 2

template <class T>
class NoopGauge : public Gauge<T>
{
public:
NoopGauge(nostd::string_view /* name */,
nostd::string_view /* description */,
nostd::string_view /* unit */) noexcept
{}
void Record(T /* value */,
const common::KeyValueIterable * /* attributes */,
const context::Context * /* context */) noexcept override
{}
};
#endif

class NoopObservableInstrument : public ObservableInstrument
{
public:
Expand Down Expand Up @@ -133,6 +157,25 @@ class NoopMeter final : public Meter
return nostd::unique_ptr<Histogram<double>>{new NoopHistogram<double>(name, description, unit)};
}

#if OPENTELEMETRY_ABI_VERSION_NO >= 2

nostd::unique_ptr<Gauge<uint64_t>> CreateInt64Gauge(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override
{
return nostd::unique_ptr<Gauge<uint64_t>>(new NoopGauge<uint64_t>(name, description, unit));
}

nostd::unique_ptr<Gauge<double>> CreateDoubleGauge(nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override
{
return nostd::unique_ptr<Gauge<double>>(new NoopGauge<double>(name, description, unit));
}

#endif

nostd::shared_ptr<ObservableInstrument> CreateInt64ObservableGauge(
nostd::string_view name,
nostd::string_view description = "",
Expand Down
Loading

0 comments on commit d2317e6

Please sign in to comment.