-
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.
prepare for merging metrics branch into main
- Loading branch information
Showing
43 changed files
with
2,773 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ build | |
# Autosave files | ||
*.asv | ||
*.swp | ||
.vscode/settings.json |
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,20 @@ | ||
classdef Counter < opentelemetry.metrics.SynchronousInstrument | ||
% Counter is a value that accumulates over time and can only increase | ||
% but not decrease. | ||
|
||
% Copyright 2023 The MathWorks, Inc. | ||
|
||
methods (Access={?opentelemetry.metrics.Meter}) | ||
function obj = Counter(proxy, name, description, unit) | ||
% Private constructor. Use createCounter method of Meter | ||
% to create Counters. | ||
[email protected](proxy, name, description, unit); | ||
end | ||
end | ||
|
||
methods | ||
function add(obj, value, varargin) | ||
obj.processValue(value, varargin{:}); | ||
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,19 @@ | ||
classdef Histogram < opentelemetry.metrics.SynchronousInstrument | ||
% Histogram is an instrument that aggregates values into bins | ||
|
||
% Copyright 2023 The MathWorks, Inc. | ||
|
||
methods (Access={?opentelemetry.metrics.Meter}) | ||
function obj = Histogram(proxy, name, description, unit) | ||
% Private constructor. Use createHistogram method of Meter | ||
% to create Histograms. | ||
[email protected](proxy, name, description, unit); | ||
end | ||
end | ||
|
||
methods | ||
function record(obj, value, varargin) | ||
obj.processValue(value, varargin{:}); | ||
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,95 @@ | ||
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, ?opentelemetry.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); | ||
% cpp-opentelemetry end does not allow string input with spaces, | ||
% replace any spaces with underscores as a temporary fix | ||
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); | ||
% cpp-opentelemetry end does not allow string input with spaces, | ||
% replace any spaces with underscores as a temporary fix | ||
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); | ||
% cpp-opentelemetry end does not allow string input with spaces, | ||
% replace any spaces with underscores as a temporary fix | ||
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,69 @@ | ||
classdef MeterProvider < handle | ||
% A meter provider stores a set of configurations used in a distributed | ||
% metrics system. | ||
|
||
% Copyright 2023 The MathWorks, Inc. | ||
|
||
properties (Access={?opentelemetry.sdk.metrics.MeterProvider, ?opentelemetry.sdk.common.Cleanup}) | ||
Proxy % Proxy object to interface C++ code | ||
end | ||
|
||
methods (Access={?opentelemetry.metrics.Provider, ?opentelemetry.sdk.metrics.MeterProvider}) | ||
function obj = MeterProvider(skip) | ||
% constructor | ||
% "skip" input signals skipping construction | ||
if nargin < 1 || skip ~= "skip" | ||
obj.Proxy = libmexclass.proxy.Proxy("Name", ... | ||
"libmexclass.opentelemetry.MeterProviderProxy", ... | ||
"ConstructorArguments", {}); | ||
end | ||
end | ||
end | ||
|
||
methods | ||
function meter = getMeter(obj, mname, mversion, mschema) | ||
% GETMETER Create a meter object used to generate metrics. | ||
% M = GETMETER(MP, NAME) returns a meter with the name | ||
% NAME that uses all the configurations specified in meter | ||
% provider MP. | ||
% | ||
% M = GETMETER(MP, NAME, VERSION, SCHEMA) also specifies | ||
% the meter version and the URL that documents the schema | ||
% of the generated meters. | ||
% | ||
% See also OPENTELEMETRY.METRICS.METER | ||
arguments | ||
obj | ||
mname | ||
mversion = "" | ||
mschema = "" | ||
end | ||
% name, version, schema accepts any types that can convert to a | ||
% string | ||
import opentelemetry.common.mustBeScalarString | ||
mname = mustBeScalarString(mname); | ||
mversion = mustBeScalarString(mversion); | ||
mschema = mustBeScalarString(mschema); | ||
id = obj.Proxy.getMeter(mname, mversion, mschema); | ||
meterproxy = libmexclass.proxy.Proxy("Name", ... | ||
"libmexclass.opentelemetry.MeterProxy", "ID", id); | ||
meter = opentelemetry.metrics.Meter(meterproxy, mname, mversion, mschema); | ||
end | ||
|
||
function setMeterProvider(obj) | ||
% SETMETERPROVIDER Set global instance of meter provider | ||
% SETMETERPROVIDER(MP) sets the meter provider MP as | ||
% the global instance. | ||
% | ||
% See also OPENTELEMETRY.METRICS.PROVIDER.GETMETERPROVIDER | ||
obj.Proxy.setMeterProvider(); | ||
end | ||
end | ||
|
||
methods(Access=?opentelemetry.sdk.common.Cleanup) | ||
function postShutdown(obj) | ||
% POSTSHUTDOWN Handle post-shutdown tasks | ||
obj.Proxy.postShutdown(); | ||
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,27 @@ | ||
classdef Provider | ||
% Get and set the global instance of meter provider | ||
|
||
% Copyright 2023 The MathWorks, Inc. | ||
|
||
methods (Static) | ||
function p = getMeterProvider() | ||
% Get the global instance of meter provider | ||
% MP = OPENTELEMETRY.METRICS.PROVIDER.GETMETERPROVIDER gets | ||
% the global instance of meter provider. | ||
% | ||
% See also OPENTELEMETRY.METRICS.PROVIDER.SETMETERPROVIDER | ||
|
||
p = opentelemetry.metrics.MeterProvider(); | ||
end | ||
|
||
function setMeterProvider(p) | ||
% Set the global instance of meter provider | ||
% OPENTELEMETRY.METRICS.PROVIDER.GETMETERPROVIDER(MP) sets | ||
% MP as the global instance of meter provider. | ||
% | ||
% See also OPENTELEMETRY.METRICS.PROVIDER.GETMETERPROVIDER | ||
p.setMeterProvider(); | ||
end | ||
end | ||
|
||
end |
44 changes: 44 additions & 0 deletions
44
api/metrics/+opentelemetry/+metrics/SynchronousInstrument.m
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,44 @@ | ||
classdef SynchronousInstrument < handle | ||
% Base class inherited by all synchronous instruments | ||
|
||
% 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=protected) | ||
function obj = SynchronousInstrument(proxy, name, description, unit) | ||
obj.Proxy = proxy; | ||
obj.Name = name; | ||
obj.Description = description; | ||
obj.Unit = unit; | ||
end | ||
|
||
function processValue(obj, value, varargin) | ||
% input value must be a numerical real scalar | ||
if isnumeric(value) && isscalar(value) && isreal(value) | ||
if nargin == 2 | ||
obj.Proxy.processValue(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.processValue(value, attrkeys, attrvals); | ||
else | ||
attrkeys = [varargin{1:2:length(varargin)}]'; | ||
attrvals = [varargin(2:2:length(varargin))]'; | ||
obj.Proxy.processValue(value, attrkeys, attrvals); | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.