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

Metrics API : Provider , MeterProvider, Meter, SynchronousInstrument #1033

Merged
merged 20 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from 13 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
27 changes: 27 additions & 0 deletions api/include/opentelemetry/metrics_new/async_instruments.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "observer_result.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace metrics_new
{
class AsynchronousInstrument
{};

template <class T>
class ObservableCounter : public AsynchronousInstrument
{};

template <class T>
class ObservableGauge : public AsynchronousInstrument
{};

template <class T>
class ObservableUpDownCounter : public AsynchronousInstrument
{};

} // namespace metrics_new
OPENTELEMETRY_END_NAMESPACE
191 changes: 191 additions & 0 deletions api/include/opentelemetry/metrics_new/meter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "opentelemetry/metrics_new/async_instruments.h"
#include "opentelemetry/metrics_new/sync_instruments.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/span.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace metrics_new
{
/**
* Handles instrument creation and provides a facility for batch recording.
*
* This class provides methods to create new metric instruments, record a
* batch of values to a specified set of instruments, and collect
* measurements from all instruments.
*
*/
class Meter
{
public:
virtual ~Meter() = default;

/**
* Creates a Counter with the passed characteristics and returns a shared_ptr to that Counter.
*
* @param name the name of the new Counter.
* @param description a brief description of what the Counter is used for.
* @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html.
* @return a shared pointer to the created Counter.
*/

virtual nostd::shared_ptr<Counter<long>> CreateLongCounter(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;
lalitb marked this conversation as resolved.
Show resolved Hide resolved

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

/**
* Creates a Asynchronouse (Observable) counter with the passed characteristics and returns a
* shared_ptr to that Observable Counter
*
* @param name the name of the new Observable Counter.
* @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 callback the function to be observed by the instrument. This can optionally take `state`
* as key-value argument.
* @return a shared pointer to the created Observable Counter.
*/
virtual nostd::shared_ptr<ObservableCounter<long>> CreateLongObservableCounter(
nostd::string_view name,
void (*callback)(ObserverResult<long> &),
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;

virtual nostd::shared_ptr<ObservableCounter<long>> CreateLongObservableCounter(
nostd::string_view name,
void (*callback)(ObserverResult<long> &, const common::KeyValueIterable &),
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;

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

virtual nostd::shared_ptr<ObservableCounter<double>> CreateDoubleObservableCounter(
nostd::string_view name,
void (*callback)(ObserverResult<double> &, const common::KeyValueIterable &),
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.
*
* @param name the name of the new Histogram.
* @param description a brief description of what the Histogram is used for.
* @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html.
* @return a shared pointer to the created Histogram.
*/
virtual nostd::shared_ptr<Histogram<long>> CreateLongHistogram(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;

virtual nostd::shared_ptr<Histogram<double>> CreateDoubleHistogram(
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 Counter
*
* @param name the name of the new Observable Gauge.
* @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 callback the function to be observed by the instrument. This can optionally take `state`
* as key-value argument.
* @return a shared pointer to the created Observable Gauge.
*/
virtual nostd::shared_ptr<ObservableGauge<long>> CreateLongObservableGauge(
nostd::string_view name,
void (*callback)(ObserverResult<long> &),
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;

virtual nostd::shared_ptr<ObservableGauge<long>> CreateLongObservableGauge(
nostd::string_view name,
void (*callback)(ObserverResult<long> &, const common::KeyValueIterable &),
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;

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

virtual nostd::shared_ptr<ObservableGauge<double>> CreateDoubleObservableGauge(
nostd::string_view name,
void (*callback)(ObserverResult<double> &, const common::KeyValueIterable &),
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;

/**
* Creates an UpDownCounter with the passed characteristics and returns a shared_ptr to that
* UpDownCounter.
*
* @param name the name of the new UpDownCounter.
* @param description a brief description of what the UpDownCounter is used for.
* @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html.
* @return a shared pointer to the created UpDownCounter.
*/
virtual nostd::shared_ptr<UpDownCounter<long>> CreateLongUpDownCounter(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;

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

/**
* Creates a Asynchronouse (Observable) UpDownCounter with the passed characteristics and returns
* a shared_ptr to that Observable UpDownCounter
*
* @param name the name of the new Observable UpDownCounter.
* @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 callback the function to be observed by the instrument. This can optionally take `state`
* as key-value argument.
* @return a shared pointer to the created Observable UpDownCounter.
*/
virtual nostd::shared_ptr<ObservableUpDownCounter<long>> CreateLongObservableUpDownCounter(
nostd::string_view name,
void (*callback)(ObserverResult<long> &),
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;

virtual nostd::shared_ptr<ObservableUpDownCounter<long>> CreateLongObservableUpDownCounter(
nostd::string_view name,
void (*callback)(ObserverResult<long> &, const common::KeyValueIterable &),
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;

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

virtual nostd::shared_ptr<ObservableUpDownCounter<double>> CreateDoubleObservableUpDownCounter(
nostd::string_view name,
void (*callback)(ObserverResult<double> &, const common::KeyValueIterable &),
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;
};
} // namespace metrics_new
OPENTELEMETRY_END_NAMESPACE
31 changes: 31 additions & 0 deletions api/include/opentelemetry/metrics_new/meter_provider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "opentelemetry/metrics_new/meter.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/string_view.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace metrics_new
{
/**
* Creates new Meter instances.
*/
class MeterProvider
{
public:
virtual ~MeterProvider() = default;
/**
* Gets or creates a named Meter instance.
*
* Optionally a version can be passed to create a named and versioned Meter
* instance.
*/
virtual nostd::shared_ptr<Meter> GetMeter(nostd::string_view library_name,
nostd::string_view library_version = "",
nostd::string_view schema_url = "") noexcept = 0;
};
} // namespace metrics_new
OPENTELEMETRY_END_NAMESPACE
Loading