Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple async callbacks #1495

Merged
merged 32 commits into from
Aug 5, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix
lalitb committed Jul 1, 2022
commit c605ef4ec77008e5ee7d5053232681ff214d023a
4 changes: 1 addition & 3 deletions api/include/opentelemetry/metrics/async_instruments.h
Original file line number Diff line number Diff line change
@@ -10,13 +10,11 @@ OPENTELEMETRY_BEGIN_NAMESPACE
namespace metrics
{

template <class T>
using ObservableCallbackPtr = void (*callback)(ObserverResult<T> &, void *);
typedef void (*ObservableCallbackPtr)(ObserverResult &, void *);

class AsynchronousInstrument
{};

template <class T>
class ObservableInstrument
{
public:
67 changes: 27 additions & 40 deletions api/include/opentelemetry/metrics/meter.h
Original file line number Diff line number Diff line change
@@ -51,22 +51,18 @@ class Meter
* shared_ptr to that Observable Counter
*
* @param name the name of the new Observable Counter.
* @param callback the function to be observed by the instrument.
* @param description a brief description of what the Observable Counter is used for.
* @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html.
* @param state to be passed back to callback
*/
virtual void CreateLongObservableCounter(nostd::string_view name,
void (*callback)(ObserverResult<long> &, void *),
nostd::string_view description = "",
nostd::string_view unit = "",
void *state = nullptr) noexcept = 0;

virtual void CreateDoubleObservableCounter(nostd::string_view name,
void (*callback)(ObserverResult<double> &, void *),
nostd::string_view description = "",
nostd::string_view unit = "",
void *state = nullptr) noexcept = 0;
virtual nostd::shared_ptr<ObservableCounter<long>> CreateLongObservableCounter(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;

virtual nostd::shared_ptr<ObservableCounter<double>> CreateDoubleObservableCounter(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;

/**
* Creates a Histogram with the passed characteristics and returns a shared_ptr to that Histogram.
@@ -91,22 +87,18 @@ class Meter
* shared_ptr to that Observable Counter
*
* @param name the name of the new Observable Gauge.
* @param callback the function to be observed by the instrument.
* @param description a brief description of what the Observable Gauge is used for.
* @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html.
* @param state to be passed back to callback
*/
virtual void CreateLongObservableGauge(nostd::string_view name,
void (*callback)(ObserverResult<long> &, void *),
nostd::string_view description = "",
nostd::string_view unit = "",
void *state = nullptr) noexcept = 0;

virtual void CreateDoubleObservableGauge(nostd::string_view name,
void (*callback)(ObserverResult<double> &, void *),
nostd::string_view description = "",
nostd::string_view unit = "",
void *state = nullptr) noexcept = 0;
virtual nostd::shared_ptr<ObservableGauge<long>> CreateLongObservableGauge(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;

virtual nostd::shared_ptr<ObservableGauge<double>> CreateDoubleObservableGauge(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;

/**
* Creates an UpDownCounter with the passed characteristics and returns a shared_ptr to that
@@ -132,23 +124,18 @@ class Meter
* a shared_ptr to that Observable UpDownCounter
*
* @param name the name of the new Observable UpDownCounter.
* @param callback the function to be observed by the instrument.
* @param description a brief description of what the Observable UpDownCounter is used for.
* @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html.
* @param state to be passed back to callback
*/
virtual void CreateLongObservableUpDownCounter(nostd::string_view name,
void (*callback)(ObserverResult<long> &, void *),
nostd::string_view description = "",
nostd::string_view unit = "",
void *state = nullptr) noexcept = 0;

virtual void CreateDoubleObservableUpDownCounter(nostd::string_view name,
void (*callback)(ObserverResult<double> &,
void *),
nostd::string_view description = "",
nostd::string_view unit = "",
void *state = nullptr) noexcept = 0;
virtual nostd::shared_ptr<ObservableUpDownCounter<long>> CreateLongObservableUpDownCounter(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;

virtual nostd::shared_ptr<ObservableUpDownCounter<double>> CreateDoubleObservableUpDownCounter(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;
};
} // namespace metrics
OPENTELEMETRY_END_NAMESPACE
101 changes: 43 additions & 58 deletions api/include/opentelemetry/metrics/noop.h
Original file line number Diff line number Diff line change
@@ -69,13 +69,6 @@ class NoopObservableCounter : public ObservableCounter<T>
{
public:
NoopObservableCounter(nostd::string_view name,
void (*callback)(ObserverResult<T> &),
nostd::string_view description,
nostd::string_view unit) noexcept
{}

NoopObservableCounter(nostd::string_view name,
void (*callback)(ObserverResult<T> &, const common::KeyValueIterable &),
nostd::string_view description,
nostd::string_view unit) noexcept
{}
@@ -86,13 +79,6 @@ class NoopObservableGauge : public ObservableGauge<T>
{
public:
NoopObservableGauge(nostd::string_view name,
void (*callback)(ObserverResult<T> &),
nostd::string_view description,
nostd::string_view unit) noexcept
{}

NoopObservableGauge(nostd::string_view name,
void (*callback)(ObserverResult<T> &, const common::KeyValueIterable &),
nostd::string_view description,
nostd::string_view unit) noexcept
{}
@@ -103,14 +89,6 @@ class NoopObservableUpDownCounter : public ObservableUpDownCounter<T>
{
public:
NoopObservableUpDownCounter(nostd::string_view name,
void (*callback)(ObserverResult<T> &),
nostd::string_view description,
nostd::string_view unit) noexcept
{}

NoopObservableUpDownCounter(nostd::string_view name,
void (*callback)(ObserverResult<T> &,
const common::KeyValueIterable &),
nostd::string_view description,
nostd::string_view unit) noexcept
{}
@@ -137,19 +115,21 @@ class NoopMeter final : public Meter
return nostd::shared_ptr<Counter<double>>{new NoopCounter<double>(name, description, unit)};
}

void CreateLongObservableCounter(nostd::string_view name,
void (*callback)(ObserverResult<long> &, void *),
nostd::string_view description = "",
nostd::string_view unit = "",
void *state = nullptr) noexcept override
{}
nostd::shared_ptr<ObservableCounter<long>> CreateLongObservableCounter(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override
{
return nostd::shared_ptr<ObservableCounter<long>>(new ObservableCounter<long>());
}

void CreateDoubleObservableCounter(nostd::string_view name,
void (*callback)(ObserverResult<double> &, void *),
nostd::string_view description = "",
nostd::string_view unit = "",
void *state = nullptr) noexcept override
{}
nostd::shared_ptr<ObservableCounter<double>> CreateDoubleObservableCounter(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override
{
return nostd::shared_ptr<ObservableCounter<double>>(new ObservableCounter<double>());
}

nostd::shared_ptr<Histogram<long>> CreateLongHistogram(
nostd::string_view name,
@@ -167,19 +147,21 @@ class NoopMeter final : public Meter
return nostd::shared_ptr<Histogram<double>>{new NoopHistogram<double>(name, description, unit)};
}

void CreateLongObservableGauge(nostd::string_view name,
void (*callback)(ObserverResult<long> &, void *),
nostd::string_view description = "",
nostd::string_view unit = "",
void *state = nullptr) noexcept override
{}
nostd::shared_ptr<ObservableGauge<long>> CreateLongObservableGauge(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override
{
return nostd::shared_ptr<ObservableGauge<long>>(new ObservableGauge<long>());
}

void CreateDoubleObservableGauge(nostd::string_view name,
void (*callback)(ObserverResult<double> &, void *),
nostd::string_view description = "",
nostd::string_view unit = "",
void *state = nullptr) noexcept override
{}
nostd::shared_ptr<ObservableGauge<double>> CreateDoubleObservableGauge(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override
{
return nostd::shared_ptr<ObservableGauge<double>>(new ObservableGauge<double>());
}

nostd::shared_ptr<UpDownCounter<long>> CreateLongUpDownCounter(
nostd::string_view name,
@@ -199,19 +181,22 @@ class NoopMeter final : public Meter
new NoopUpDownCounter<double>(name, description, unit)};
}

void CreateLongObservableUpDownCounter(nostd::string_view name,
void (*callback)(ObserverResult<long> &, void *),
nostd::string_view description = "",
nostd::string_view unit = "",
void *state = nullptr) noexcept override
{}
nostd::shared_ptr<ObservableUpDownCounter<long>> CreateLongObservableUpDownCounter(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override
{
return nostd::shared_ptr<ObservableUpDownCounter<long>>(new ObservableUpDownCounter<long>());
}

void CreateDoubleObservableUpDownCounter(nostd::string_view name,
void (*callback)(ObserverResult<double> &, void *),
nostd::string_view description = "",
nostd::string_view unit = "",
void *state = nullptr) noexcept override
{}
nostd::shared_ptr<ObservableUpDownCounter<double>> CreateDoubleObservableUpDownCounter(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override
{
return nostd::shared_ptr<ObservableUpDownCounter<double>>(
new ObservableUpDownCounter<double>());
}
};

/**
39 changes: 3 additions & 36 deletions api/include/opentelemetry/metrics/observer_result.h
Original file line number Diff line number Diff line change
@@ -15,12 +15,11 @@ namespace metrics
{

/**
* ObserverResult class is necessary for the callback recording asynchronous
* ObserverResultT class is necessary for the callback recording asynchronous
* instrument use.
*/

template <class T>
class ObserverResult
class ObserverResultT
{

public:
@@ -44,39 +43,7 @@ class ObserverResult
}
};

/**
* BatchObserverResult class is necessary for the batch callback recording asynchronous
* instrument use.
*/

template <class T>
class BatchObserverResult
{

public:
virtual void Observe(Observable &metric, T value) noexcept = 0;

virtual void Observe(Observable &metric,
T value,
const common::KeyValueIterable &attributes) noexcept = 0;

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

void Observe(Observable &metric,
T value,
std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
attributes) noexcept
{
this->Observe(metric, value,
nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
attributes.begin(), attributes.end()});
}
};
using ObserverResult = nostd::variant<ObserverResultT<long>, ObserverResultT<double>>;

} // namespace metrics
OPENTELEMETRY_END_NAMESPACE
Loading