-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'metrics' into changes_after_v_1_3_0
- Loading branch information
Showing
18 changed files
with
1,156 additions
and
1 deletion.
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,59 @@ | ||
classdef Counter < handle | ||
% Counter is a value that accumulates over time, | ||
% you can think of this like an odometer on a car; it only ever goes up. | ||
|
||
% Copyright 2023 The MathWorks, Inc. | ||
|
||
properties (SetAccess=immutable) | ||
Name (1,1) string | ||
Description (1,1) string | ||
Unit (1,1) string | ||
end | ||
|
||
properties (Access=private) | ||
Proxy % Proxy object to interface C++ code | ||
end | ||
|
||
methods (Access={?opentelemetry.metrics.Meter}) | ||
|
||
function obj = Counter(proxy, ctname, ctdescription, ctunit) | ||
% Private constructor. Use createCounter method of Meter | ||
% to create Counters. | ||
obj.Proxy = proxy; | ||
obj.Name = ctname; | ||
obj.Description = ctdescription; | ||
obj.Unit = ctunit; | ||
end | ||
|
||
end | ||
|
||
methods | ||
|
||
function add(obj, value, varargin) | ||
% input value must be a numerical scalar | ||
if isnumeric(value) && isscalar(value) | ||
|
||
if nargin == 2 | ||
obj.Proxy.add(value); | ||
|
||
elseif isa(varargin{1}, "dictionary") | ||
attrkeys = keys(varargin{1}); | ||
attrvals = values(varargin{1},"cell"); | ||
if all(cellfun(@iscell, attrvals)) | ||
attrvals = [attrvals{:}]; | ||
end | ||
obj.Proxy.add(value,attrkeys,attrvals); | ||
|
||
else | ||
attrkeys = [varargin{1:2:length(varargin)}]'; | ||
attrvals = [varargin(2:2:length(varargin))]'; | ||
obj.Proxy.add(value,attrkeys,attrvals); | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
|
||
|
||
end |
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,55 @@ | ||
classdef Histogram < handle | ||
% Histogram is an instrument that adds or reduce values. | ||
|
||
% Copyright 2023 The MathWorks, Inc. | ||
|
||
properties (SetAccess=immutable) | ||
Name (1,1) string | ||
Description (1,1) string | ||
Unit (1,1) string | ||
end | ||
|
||
properties (Access=public) | ||
Proxy % Proxy object to interface C++ code | ||
end | ||
|
||
methods (Access={?opentelemetry.metrics.Meter}) | ||
|
||
function obj = Histogram(proxy, hiname, hidescription, hiunit) | ||
% Private constructor. Use createHistogram method of Meter | ||
% to create Histograms. | ||
obj.Proxy = proxy; | ||
obj.Name = hiname; | ||
obj.Description = hidescription; | ||
obj.Unit = hiunit; | ||
end | ||
|
||
end | ||
|
||
methods | ||
|
||
function record(obj, value, varargin) | ||
% input value must be a numerical scalar | ||
if isnumeric(value) && isscalar(value) | ||
if nargin == 2 | ||
obj.Proxy.record(value); | ||
elseif isa(varargin{1}, "dictionary") | ||
attrkeys = keys(varargin{1}); | ||
attrvals = values(varargin{1},"cell"); | ||
if all(cellfun(@iscell, attrvals)) | ||
attrvals = [attrvals{:}]; | ||
end | ||
obj.Proxy.record(value,attrkeys,attrvals); | ||
else | ||
attrkeys = [varargin{1:2:length(varargin)}]'; | ||
attrvals = [varargin(2:2:length(varargin))]'; | ||
obj.Proxy.record(value,attrkeys,attrvals); | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
|
||
|
||
end |
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,89 @@ | ||
classdef Meter < handle | ||
% A Meter creates metric instruments, capturing measurements about a service at runtime. | ||
% Meters are created from Meter Providers. | ||
|
||
% Copyright 2023 The MathWorks, Inc. | ||
|
||
properties (SetAccess=immutable) | ||
Name (1,1) string % Meter name | ||
Version (1,1) string % Meter version | ||
Schema (1,1) string % URL that documents the schema of the generated spans | ||
end | ||
|
||
properties (Access=private) | ||
Proxy % Proxy object to interface C++ code | ||
end | ||
|
||
methods (Access={?opentelemetry.sdk.metrics.MeterProvider}) | ||
|
||
function obj = Meter(proxy, mtname, mtversion, mtschema) | ||
% Private constructor. Use getMeter method of MeterProvider | ||
% to create Meters. | ||
obj.Proxy = proxy; | ||
obj.Name = mtname; | ||
obj.Version = mtversion; | ||
obj.Schema = mtschema; | ||
end | ||
|
||
end | ||
|
||
methods | ||
|
||
function counter = createCounter(obj, ctname, ctdescription, ctunit) | ||
arguments | ||
obj | ||
ctname | ||
ctdescription = "" | ||
ctunit = "" | ||
end | ||
import opentelemetry.common.mustBeScalarString | ||
ctname = mustBeScalarString(ctname); | ||
ctdescription = mustBeScalarString(ctdescription); | ||
ctunit = mustBeScalarString(ctunit); | ||
id = obj.Proxy.createCounter(ctname, ctdescription, ctunit); | ||
CounterProxy = libmexclass.proxy.Proxy("Name", ... | ||
"libmexclass.opentelemetry.CounterProxy", "ID", id); | ||
counter = opentelemetry.metrics.Counter(CounterProxy, ctname, ctdescription, ctunit); | ||
end | ||
|
||
|
||
function updowncounter = createUpDownCounter(obj, ctname, ctdescription, ctunit) | ||
arguments | ||
obj | ||
ctname | ||
ctdescription = "" | ||
ctunit = "" | ||
end | ||
|
||
import opentelemetry.common.mustBeScalarString | ||
ctname = mustBeScalarString(ctname); | ||
ctdescription = mustBeScalarString(ctdescription); | ||
ctunit = mustBeScalarString(ctunit); | ||
id = obj.Proxy.createUpDownCounter(ctname, ctdescription, ctunit); | ||
UpDownCounterProxy = libmexclass.proxy.Proxy("Name", ... | ||
"libmexclass.opentelemetry.UpDownCounterProxy", "ID", id); | ||
updowncounter = opentelemetry.metrics.UpDownCounter(UpDownCounterProxy, ctname, ctdescription, ctunit); | ||
end | ||
|
||
|
||
function histogram = createHistogram(obj, hiname, hidescription, hiunit) | ||
arguments | ||
obj | ||
hiname | ||
hidescription = "" | ||
hiunit = "" | ||
end | ||
|
||
import opentelemetry.common.mustBeScalarString | ||
hiname = mustBeScalarString(hiname); | ||
hidescription = mustBeScalarString(hidescription); | ||
hiunit = mustBeScalarString(hiunit); | ||
id = obj.Proxy.createHistogram(hiname, hidescription, hiunit); | ||
HistogramProxy = libmexclass.proxy.Proxy("Name", ... | ||
"libmexclass.opentelemetry.HistogramProxy", "ID", id); | ||
histogram = opentelemetry.metrics.Histogram(HistogramProxy, hiname, hidescription, hiunit); | ||
end | ||
|
||
end | ||
|
||
end |
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,58 @@ | ||
classdef UpDownCounter < handle | ||
% UpDownCounter is an instrument that adds or reduce values. | ||
|
||
% Copyright 2023 The MathWorks, Inc. | ||
|
||
properties (SetAccess=immutable) | ||
Name (1,1) string | ||
Description (1,1) string | ||
Unit (1,1) string | ||
end | ||
|
||
properties (Access=public) | ||
Proxy % Proxy object to interface C++ code | ||
end | ||
|
||
methods (Access={?opentelemetry.metrics.Meter}) | ||
|
||
function obj = UpDownCounter(proxy, ctname, ctdescription, ctunit) | ||
% Private constructor. Use createUpDownCounter method of Meter | ||
% to create UpDownCounters. | ||
obj.Proxy = proxy; | ||
obj.Name = ctname; | ||
obj.Description = ctdescription; | ||
obj.Unit = ctunit; | ||
end | ||
|
||
end | ||
|
||
methods | ||
|
||
function add(obj, value, varargin) | ||
% input value must be a numerical scalar | ||
if isnumeric(value) && isscalar(value) | ||
|
||
if nargin == 2 | ||
obj.Proxy.add(value); | ||
|
||
elseif isa(varargin{1}, "dictionary") | ||
attrkeys = keys(varargin{1}); | ||
attrvals = values(varargin{1},"cell"); | ||
if all(cellfun(@iscell, attrvals)) | ||
attrvals = [attrvals{:}]; | ||
end | ||
obj.Proxy.add(value,attrkeys,attrvals); | ||
|
||
else | ||
attrkeys = [varargin{1:2:length(varargin)}]'; | ||
attrvals = [varargin(2:2:length(varargin))]'; | ||
obj.Proxy.add(value,attrkeys,attrvals); | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
|
||
|
||
end |
Oops, something went wrong.