-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Meter and MeterProvider in the SDK (#1078)
- Loading branch information
Showing
19 changed files
with
966 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
#ifndef ENABLE_METRICS_PREVIEW | ||
# include <chrono> | ||
# include "opentelemetry/metrics/meter.h" | ||
# include "opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h" | ||
# include "opentelemetry/sdk/metrics/meter_context.h" | ||
# include "opentelemetry/sdk/resource/resource.h" | ||
# include "opentelemetry/version.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace metrics | ||
{ | ||
class Meter final : public opentelemetry::metrics::Meter | ||
{ | ||
public: | ||
/** Construct a new Meter with the given pipeline. */ | ||
explicit Meter(std::shared_ptr<sdk::metrics::MeterContext> context, | ||
std::unique_ptr<opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary> | ||
instrumentation_library = | ||
opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary::Create( | ||
"")) noexcept; | ||
|
||
nostd::shared_ptr<opentelemetry::metrics::Counter<long>> CreateLongCounter( | ||
nostd::string_view name, | ||
nostd::string_view description = "", | ||
nostd::string_view unit = "") noexcept override; | ||
|
||
nostd::shared_ptr<opentelemetry::metrics::Counter<double>> CreateDoubleCounter( | ||
nostd::string_view name, | ||
nostd::string_view description = "", | ||
nostd::string_view unit = "") noexcept override; | ||
|
||
nostd::shared_ptr<opentelemetry::metrics::ObservableCounter<long>> CreateLongObservableCounter( | ||
nostd::string_view name, | ||
void (*callback)(opentelemetry::metrics::ObserverResult<long> &), | ||
nostd::string_view description = "", | ||
nostd::string_view unit = "") noexcept override; | ||
|
||
nostd::shared_ptr<opentelemetry::metrics::ObservableCounter<double>> | ||
CreateDoubleObservableCounter(nostd::string_view name, | ||
void (*callback)(opentelemetry::metrics::ObserverResult<double> &), | ||
nostd::string_view description = "", | ||
nostd::string_view unit = "1") noexcept override; | ||
|
||
nostd::shared_ptr<opentelemetry::metrics::Histogram<long>> CreateLongHistogram( | ||
nostd::string_view name, | ||
nostd::string_view description = "", | ||
nostd::string_view unit = "") noexcept override; | ||
|
||
nostd::shared_ptr<opentelemetry::metrics::Histogram<double>> CreateDoubleHistogram( | ||
nostd::string_view name, | ||
nostd::string_view description = "", | ||
nostd::string_view unit = "") noexcept override; | ||
|
||
nostd::shared_ptr<opentelemetry::metrics::ObservableGauge<long>> CreateLongObservableGauge( | ||
nostd::string_view name, | ||
void (*callback)(opentelemetry::metrics::ObserverResult<long> &), | ||
nostd::string_view description = "", | ||
nostd::string_view unit = "") noexcept override; | ||
|
||
nostd::shared_ptr<opentelemetry::metrics::ObservableGauge<double>> CreateDoubleObservableGauge( | ||
nostd::string_view name, | ||
void (*callback)(opentelemetry::metrics::ObserverResult<double> &), | ||
nostd::string_view description = "", | ||
nostd::string_view unit = "") noexcept override; | ||
|
||
nostd::shared_ptr<opentelemetry::metrics::UpDownCounter<long>> CreateLongUpDownCounter( | ||
nostd::string_view name, | ||
nostd::string_view description = "", | ||
nostd::string_view unit = "") noexcept override; | ||
|
||
nostd::shared_ptr<opentelemetry::metrics::UpDownCounter<double>> CreateDoubleUpDownCounter( | ||
nostd::string_view name, | ||
nostd::string_view description = "", | ||
nostd::string_view unit = "") noexcept override; | ||
|
||
nostd::shared_ptr<opentelemetry::metrics::ObservableUpDownCounter<long>> | ||
CreateLongObservableUpDownCounter( | ||
nostd::string_view name, | ||
void (*callback)(opentelemetry::metrics::ObserverResult<long> &), | ||
nostd::string_view description = "", | ||
nostd::string_view unit = "") noexcept override; | ||
|
||
nostd::shared_ptr<opentelemetry::metrics::ObservableUpDownCounter<double>> | ||
CreateDoubleObservableUpDownCounter( | ||
nostd::string_view name, | ||
void (*callback)(opentelemetry::metrics::ObserverResult<double> &), | ||
nostd::string_view description = "", | ||
nostd::string_view unit = "") noexcept override; | ||
|
||
/** Returns the associated instruementation library */ | ||
const sdk::instrumentationlibrary::InstrumentationLibrary &GetInstrumentationLibrary() | ||
const noexcept; | ||
|
||
private: | ||
// order of declaration is important here - instrumentation library should destroy after | ||
// meter-context. | ||
std::shared_ptr<sdk::instrumentationlibrary::InstrumentationLibrary> instrumentation_library_; | ||
std::shared_ptr<sdk::metrics::MeterContext> context_; | ||
}; | ||
} // namespace metrics | ||
} // namespace sdk | ||
OPENTELEMETRY_END_NAMESPACE | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
#ifndef ENABLE_METRICS_PREVIEW | ||
# include <chrono> | ||
# include <memory> | ||
# include <vector> | ||
# include "opentelemetry/sdk/metrics/metric_exporter.h" | ||
# include "opentelemetry/sdk/metrics/metric_reader.h" | ||
# include "opentelemetry/sdk/metrics/view.h" | ||
# include "opentelemetry/sdk/resource/resource.h" | ||
# include "opentelemetry/version.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace metrics | ||
{ | ||
/** | ||
* A class which stores the MeterProvider context. | ||
*/ | ||
class MeterContext | ||
{ | ||
public: | ||
/** | ||
* Initialize a new meter provider | ||
* @param exporters The exporters to be configured with meter context | ||
* @param readers The readers to be configured with meter context. | ||
* @param views The views to be configured with meter context. | ||
* @param resource The resource for this meter context. | ||
*/ | ||
MeterContext(std::vector<std::unique_ptr<sdk::metrics::MetricExporter>> &&exporters, | ||
std::vector<std::unique_ptr<MetricReader>> &&readers, | ||
std::vector<std::unique_ptr<View>> &&views, | ||
opentelemetry::sdk::resource::Resource resource = | ||
opentelemetry::sdk::resource::Resource::Create({})) noexcept; | ||
|
||
/** | ||
* Obtain the resource associated with this meter context. | ||
* @return The resource for this meter context | ||
*/ | ||
const opentelemetry::sdk::resource::Resource &GetResource() const noexcept; | ||
|
||
/** | ||
* Attaches a metric exporter to list of configured exporters for this Meter context. | ||
* @param exporter The metric exporter for this meter context. This | ||
* must not be a nullptr. | ||
* | ||
* Note: This exporter may not receive any in-flight meter data, but will get newly created meter | ||
* data. Note: This method is not thread safe, and should ideally be called from main thread. | ||
*/ | ||
void AddMetricExporter(std::unique_ptr<MetricExporter> exporter) noexcept; | ||
|
||
/** | ||
* Attaches a metric reader to list of configured readers for this Meter context. | ||
* @param reader The metric reader for this meter context. This | ||
* must not be a nullptr. | ||
* | ||
* Note: This reader may not receive any in-flight meter data, but will get newly created meter | ||
* data. Note: This method is not thread safe, and should ideally be called from main thread. | ||
*/ | ||
void AddMetricReader(std::unique_ptr<MetricReader> reader) noexcept; | ||
|
||
/** | ||
* Attaches a View to list of configured Views for this Meter context. | ||
* @param view The Views for this meter context. This | ||
* must not be a nullptr. | ||
* | ||
* Note: This view may not receive any in-flight meter data, but will get newly created meter | ||
* data. Note: This method is not thread safe, and should ideally be called from main thread. | ||
*/ | ||
void AddView(std::unique_ptr<View> view) noexcept; | ||
|
||
/** | ||
* Force all active Exporters and Readers to flush any buffered meter data | ||
* within the given timeout. | ||
*/ | ||
|
||
bool ForceFlush(std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept; | ||
|
||
/** | ||
* Shutdown the Exporters and Readers associated with this meter provider. | ||
*/ | ||
bool Shutdown() noexcept; | ||
|
||
private: | ||
opentelemetry::sdk::resource::Resource resource_; | ||
std::vector<std::unique_ptr<MetricExporter>> exporters_; | ||
std::vector<std::unique_ptr<MetricReader>> readers_; | ||
std::vector<std::unique_ptr<View>> views_; | ||
}; | ||
|
||
} // namespace metrics | ||
} // namespace sdk | ||
OPENTELEMETRY_END_NAMESPACE | ||
#endif |
Oops, something went wrong.