-
Notifications
You must be signed in to change notification settings - Fork 3
Synchronous gauge #183
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
Synchronous gauge #183
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
classdef Gauge < opentelemetry.metrics.SynchronousInstrument | ||
% Gauge is an instrument for recording non-aggregatable measurements. | ||
|
||
% Copyright 2025 The MathWorks, Inc. | ||
|
||
methods (Access={?opentelemetry.metrics.Meter}) | ||
function obj = Gauge(proxy, name, description, unit) | ||
% Private constructor. Use createGauge method of Meter | ||
% to create gauges. | ||
[email protected](proxy, name, description, unit); | ||
end | ||
end | ||
|
||
methods | ||
function record(obj, value, varargin) | ||
% RECORD Record a value | ||
% RECORD(G, VALUE) records a scalar numeric value. VALUE can be positive or negative. | ||
% | ||
% RECORD(G, VALUE, ATTRIBUTES) also specifies attributes as a | ||
% dictionary | ||
% | ||
% RECORD(G, VALUE, ATTRNAME1, ATTRVALUE1, ATTRNAME2, | ||
% ATTRVALUE2, ...) specifies attributes as trailing | ||
% name-value pairs. | ||
obj.processValue(value, varargin{:}); | ||
end | ||
end | ||
end |
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
33 changes: 33 additions & 0 deletions
33
api/metrics/include/opentelemetry-matlab/metrics/GaugeProxy.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,33 @@ | ||
// Copyright 2025 The MathWorks, Inc. | ||
duncanpo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#pragma once | ||
|
||
#include "libmexclass/proxy/Proxy.h" | ||
duncanpo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#include "libmexclass/proxy/method/Context.h" | ||
|
||
#include "opentelemetry/metrics/meter.h" | ||
#include "opentelemetry/metrics/sync_instruments.h" | ||
|
||
#include "opentelemetry-matlab/common/attribute.h" | ||
#include "opentelemetry-matlab/common/ProcessedAttributes.h" | ||
|
||
namespace metrics_api = opentelemetry::metrics; | ||
namespace nostd = opentelemetry::nostd; | ||
|
||
namespace libmexclass::opentelemetry { | ||
class GaugeProxy : public libmexclass::proxy::Proxy { | ||
public: | ||
GaugeProxy(nostd::shared_ptr<metrics_api::Gauge<double> > g) : CppGauge(g) { | ||
REGISTER_METHOD(GaugeProxy, processValue); | ||
} | ||
|
||
void processValue(libmexclass::proxy::method::Context& context); | ||
|
||
private: | ||
|
||
nostd::shared_ptr<metrics_api::Gauge<double> > CppGauge; | ||
|
||
}; | ||
} // namespace libmexclass::opentelemetry | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2025 The MathWorks, Inc. | ||
|
||
#include "opentelemetry-matlab/metrics/GaugeProxy.h" | ||
|
||
#include "MatlabDataArray.hpp" | ||
|
||
namespace libmexclass::opentelemetry { | ||
|
||
|
||
void GaugeProxy::processValue(libmexclass::proxy::method::Context& context){ | ||
|
||
matlab::data::Array value_mda = context.inputs[0]; | ||
double value = static_cast<double>(value_mda[0]); | ||
duncanpo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
size_t nin = context.inputs.getNumberOfElements(); | ||
if (nin == 1){ | ||
CppGauge->Record(value); | ||
} | ||
// add attributes | ||
else { | ||
ProcessedAttributes attrs; | ||
matlab::data::StringArray attrnames_mda = context.inputs[1]; | ||
duncanpo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
matlab::data::Array attrvalues_mda = context.inputs[2]; | ||
size_t nattrs = attrnames_mda.getNumberOfElements(); | ||
for (size_t i = 0; i < nattrs; i ++){ | ||
std::string attrname = static_cast<std::string>(attrnames_mda[i]); | ||
duncanpo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
matlab::data::Array attrvalue = attrvalues_mda[i]; | ||
processAttribute(attrname, attrvalue, attrs); | ||
} | ||
CppGauge->Record(value, attrs.Attributes); | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
} // namespace libmexclass::opentelemetry |
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
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.
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.