-
Notifications
You must be signed in to change notification settings - Fork 560
Sync and Async Instruments SDK #1184
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6a68108
Sync instruments sdk
lalitb 6a9b07c
Sync Intruments
lalitb d4aa275
fix for gcc4.8
lalitb 739c563
more changes
lalitb 29a817c
change reference to pointer
lalitb aab9f34
add tests
lalitb ac394a9
remove commented code
lalitb beeba78
Merge branch 'main' into instruments-sdk
lalitb d27cd2f
more changes for metric reader and measurement processor interface
lalitb 53aa943
Merge branch 'instruments-sdk' of github.com:lalitb/opentelemetry-cpp…
lalitb 1273d44
Merge branch 'main' into instruments-sdk
lalitb 22cdfdf
Merge branch 'main' into instruments-sdk
lalitb 0f05485
Review comments
lalitb da76ead
review comment
lalitb 9f04cbf
add tests for async instrument
lalitb aeab6cf
Merge branch 'main' into instruments-sdk
lalitb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
179 changes: 179 additions & 0 deletions
179
sdk/include/opentelemetry/sdk/metrics/async_instruments.h
This file contains hidden or 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,179 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #pragma once | ||
| #ifndef ENABLE_METRICS_PREVIEW | ||
| # include "opentelemetry/metrics/async_instruments.h" | ||
| # include "opentelemetry/metrics/observer_result.h" | ||
| # include "opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h" | ||
| # include "opentelemetry/sdk/metrics/measurement_processor.h" | ||
|
|
||
| # include "opentelemetry/nostd/string_view.h" | ||
| # include "opentelemetry/sdk/metrics/instruments.h" | ||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace sdk | ||
| { | ||
| namespace metrics | ||
| { | ||
|
|
||
| template <class T> | ||
| class Asynchronous | ||
| { | ||
| public: | ||
| Asynchronous(nostd::string_view name, | ||
| const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary | ||
| *instrumentation_library, | ||
| MeasurementProcessor *measurement_processor, | ||
| void (*callback)(opentelemetry::metrics::ObserverResult<T> &), | ||
| nostd::string_view description = "", | ||
| nostd::string_view unit = "") | ||
| : name_(name), | ||
| instrumentation_library_{instrumentation_library}, | ||
| measurement_processor_{measurement_processor}, | ||
| callback_(callback), | ||
| description_(description), | ||
| unit_(unit) | ||
| {} | ||
|
|
||
| protected: | ||
| std::string name_; | ||
| const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary | ||
| *instrumentation_library_; | ||
| const MeasurementProcessor *measurement_processor_; | ||
| void (*callback_)(opentelemetry::metrics::ObserverResult<T> &); | ||
| std::string description_; | ||
| std::string unit_; | ||
| }; | ||
|
|
||
| class LongObservableCounter : public opentelemetry::metrics::ObservableCounter<long>, | ||
| public Asynchronous<long> | ||
| { | ||
| public: | ||
| LongObservableCounter(nostd::string_view name, | ||
| const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary | ||
| *instrumentation_library, | ||
| MeasurementProcessor *measurement_processor, | ||
| void (*callback)(opentelemetry::metrics::ObserverResult<long> &), | ||
| nostd::string_view description = "", | ||
| nostd::string_view unit = "") | ||
| : Asynchronous(name, | ||
| instrumentation_library, | ||
| measurement_processor, | ||
| callback, | ||
| description, | ||
| unit) | ||
|
|
||
| {} | ||
| }; | ||
|
|
||
| class DoubleObservableCounter : public opentelemetry::metrics::ObservableCounter<double>, | ||
| public Asynchronous<double> | ||
| { | ||
| public: | ||
| DoubleObservableCounter(nostd::string_view name, | ||
| const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary | ||
| *instrumentation_library, | ||
| MeasurementProcessor *measurement_processor, | ||
| void (*callback)(opentelemetry::metrics::ObserverResult<double> &), | ||
| nostd::string_view description = "", | ||
| nostd::string_view unit = "") | ||
| : Asynchronous(name, | ||
| instrumentation_library, | ||
| measurement_processor, | ||
| callback, | ||
| description, | ||
| unit) | ||
|
|
||
| {} | ||
| }; | ||
|
|
||
| class LongObservableGauge : public opentelemetry::metrics::ObservableGauge<long>, | ||
| public Asynchronous<long> | ||
| { | ||
| public: | ||
| LongObservableGauge(nostd::string_view name, | ||
| const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary | ||
| *instrumentation_library, | ||
| MeasurementProcessor *measurement_processor, | ||
| void (*callback)(opentelemetry::metrics::ObserverResult<long> &), | ||
| nostd::string_view description = "", | ||
| nostd::string_view unit = "") | ||
| : Asynchronous(name, | ||
| instrumentation_library, | ||
| measurement_processor, | ||
| callback, | ||
| description, | ||
| unit) | ||
|
|
||
| {} | ||
| }; | ||
|
|
||
| class DoubleObservableGauge : public opentelemetry::metrics::ObservableGauge<double>, | ||
| public Asynchronous<double> | ||
| { | ||
| public: | ||
| DoubleObservableGauge(nostd::string_view name, | ||
| const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary | ||
| *instrumentation_library, | ||
| MeasurementProcessor *measurement_processor, | ||
| void (*callback)(opentelemetry::metrics::ObserverResult<double> &), | ||
| nostd::string_view description = "", | ||
| nostd::string_view unit = "") | ||
| : Asynchronous(name, | ||
| instrumentation_library, | ||
| measurement_processor, | ||
| callback, | ||
| description, | ||
| unit) | ||
|
|
||
| {} | ||
| }; | ||
|
|
||
| class LongObservableUpDownCounter : public opentelemetry::metrics::ObservableUpDownCounter<long>, | ||
| public Asynchronous<long> | ||
| { | ||
| public: | ||
| LongObservableUpDownCounter( | ||
| nostd::string_view name, | ||
| const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary | ||
| *instrumentation_library, | ||
| MeasurementProcessor *measurement_processor, | ||
| void (*callback)(opentelemetry::metrics::ObserverResult<long> &), | ||
| nostd::string_view description = "", | ||
| nostd::string_view unit = "") | ||
| : Asynchronous(name, | ||
| instrumentation_library, | ||
| measurement_processor, | ||
| callback, | ||
| description, | ||
| unit) | ||
|
|
||
| {} | ||
| }; | ||
|
|
||
| class DoubleObservableUpDownCounter | ||
| : public opentelemetry::metrics::ObservableUpDownCounter<double>, | ||
| public Asynchronous<double> | ||
| { | ||
| public: | ||
| DoubleObservableUpDownCounter( | ||
| nostd::string_view name, | ||
| const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary | ||
| *instrumentation_library, | ||
| MeasurementProcessor *measurement_processor, | ||
| void (*callback)(opentelemetry::metrics::ObserverResult<double> &), | ||
| nostd::string_view description = "", | ||
| nostd::string_view unit = "") | ||
| : Asynchronous(name, | ||
| instrumentation_library, | ||
| measurement_processor, | ||
| callback, | ||
| description, | ||
| unit) | ||
| {} | ||
| }; | ||
|
|
||
| } // namespace metrics | ||
| } // namespace sdk | ||
| OPENTELEMETRY_END_NAMESPACE | ||
| #endif | ||
108 changes: 108 additions & 0 deletions
108
sdk/include/opentelemetry/sdk/metrics/measurement_processor.h
This file contains hidden or 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,108 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #pragma once | ||
| #ifndef ENABLE_METRICS_PREVIEW | ||
|
|
||
| # include "opentelemetry/common/key_value_iterable_view.h" | ||
| # include "opentelemetry/sdk/metrics/instruments.h" | ||
| # include "opentelemetry/sdk/metrics/metric_reader.h" | ||
| # include "opentelemetry/sdk/metrics/state/sync_metric_storage.h" | ||
|
|
||
| # include <map> | ||
|
|
||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace sdk | ||
| { | ||
| namespace metrics | ||
| { | ||
|
|
||
| static std::size_t MakeKey(const MetricReader &metric_reader) | ||
|
esigo marked this conversation as resolved.
|
||
| { | ||
| return reinterpret_cast<std::size_t>(&metric_reader); | ||
| } | ||
| class MeasurementProcessor | ||
| { | ||
| public: | ||
| virtual void RecordLong(long value) noexcept = 0; | ||
|
|
||
| virtual void RecordLong(long value, | ||
| const opentelemetry::common::KeyValueIterable &attributes) noexcept = 0; | ||
|
|
||
| virtual void RecordDouble(double value) noexcept = 0; | ||
|
|
||
| virtual void RecordDouble(double value, | ||
| const opentelemetry::common::KeyValueIterable &attributes) noexcept = 0; | ||
|
|
||
| virtual bool Collect(MetricReader &reader, | ||
| AggregationTemporarily aggregation_temporarily, | ||
| nostd::function_ref<bool(MetricData)> callback) noexcept = 0; | ||
| }; | ||
|
|
||
| class DefaultMeasurementProcessor : public MeasurementProcessor | ||
| { | ||
|
|
||
| public: | ||
| bool AddMetricStorage(const MetricReader &reader) | ||
| { | ||
| // TBD = check if already present. | ||
| metric_storages_[MakeKey(reader)] = std::unique_ptr<SyncMetricStorage>(new SyncMetricStorage()); | ||
| return true; | ||
| } | ||
|
|
||
| virtual void RecordLong(long value) noexcept override | ||
| { | ||
| for (const auto &kv : metric_storages_) | ||
| { | ||
| kv.second->RecordLong(value); | ||
| } | ||
| } | ||
|
|
||
| virtual void RecordLong( | ||
| long value, | ||
| const opentelemetry::common::KeyValueIterable &attributes) noexcept override | ||
| { | ||
| for (const auto &kv : metric_storages_) | ||
| { | ||
| kv.second->RecordLong(value, attributes); | ||
| } | ||
| } | ||
|
|
||
| virtual void RecordDouble(double value) noexcept override | ||
| { | ||
| for (const auto &kv : metric_storages_) | ||
| { | ||
| kv.second->RecordDouble(value); | ||
| } | ||
| } | ||
|
|
||
| virtual void RecordDouble( | ||
| double value, | ||
| const opentelemetry::common::KeyValueIterable &attributes) noexcept override | ||
| { | ||
| for (const auto &kv : metric_storages_) | ||
| { | ||
| kv.second->RecordDouble(value, attributes); | ||
| } | ||
| } | ||
|
|
||
| bool Collect(MetricReader &reader, | ||
| AggregationTemporarily aggregation_temporarily, | ||
| nostd::function_ref<bool(MetricData)> callback) noexcept override | ||
| { | ||
| auto i = metric_storages_.find(MakeKey(reader)); | ||
| if (i != metric_storages_.end()) | ||
| { | ||
| return i->second->Collect(aggregation_temporarily, callback); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private: | ||
| std::map<std::size_t, std::unique_ptr<SyncMetricStorage>> metric_storages_; | ||
| }; | ||
|
|
||
| } // namespace metrics | ||
| } // namespace sdk | ||
| OPENTELEMETRY_END_NAMESPACE | ||
| #endif | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.