Skip to content

Commit 0e46adf

Browse files
authored
Merge branch 'metrics' into metrics_view
2 parents bfe1c50 + 6d492c9 commit 0e46adf

File tree

20 files changed

+403
-421
lines changed

20 files changed

+403
-421
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ set(BAGGAGE_API_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/api/baggage/+opentele
398398
set(COMMON_API_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/api/common/+opentelemetry)
399399
set(TRACE_SDK_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/sdk/trace/+opentelemetry)
400400
set(METRICS_SDK_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/sdk/metrics/+opentelemetry)
401+
set(COMMON_SDK_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/sdk/common/+opentelemetry)
401402
set(DEFAULT_EXPORTER_MATLAB_SOURCES
402403
${CMAKE_CURRENT_SOURCE_DIR}/exporters/otlp/+opentelemetry/+exporters/+otlp/defaultSpanExporter.m
403404
${CMAKE_CURRENT_SOURCE_DIR}/exporters/otlp/+opentelemetry/+exporters/+otlp/defaultMetricExporter.m)
@@ -418,6 +419,7 @@ install(DIRECTORY ${BAGGAGE_API_MATLAB_SOURCES} DESTINATION .)
418419
install(DIRECTORY ${COMMON_API_MATLAB_SOURCES} DESTINATION .)
419420
install(DIRECTORY ${TRACE_SDK_MATLAB_SOURCES} DESTINATION .)
420421
install(DIRECTORY ${METRICS_SDK_MATLAB_SOURCES} DESTINATION .)
422+
install(DIRECTORY ${COMMON_SDK_MATLAB_SOURCES} DESTINATION .)
421423
install(FILES ${DEFAULT_EXPORTER_MATLAB_SOURCES} DESTINATION ${OTLP_EXPORTERS_DIR})
422424
if(WITH_OTLP_HTTP)
423425
install(FILES ${OTLP_HTTP_EXPORTER_MATLAB_SOURCES} DESTINATION ${OTLP_EXPORTERS_DIR})
Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,20 @@
1-
classdef Counter < handle
2-
% Counter is a value that accumulates over time,
3-
% you can think of this like an odometer on a car; it only ever goes up.
1+
classdef Counter < opentelemetry.metrics.SynchronousInstrument
2+
% Counter is a value that accumulates over time and can only increase
3+
% but not decrease.
44

55
% Copyright 2023 The MathWorks, Inc.
66

7-
properties (SetAccess=immutable)
8-
Name (1,1) string
9-
Description (1,1) string
10-
Unit (1,1) string
11-
end
12-
13-
properties (Access=private)
14-
Proxy % Proxy object to interface C++ code
15-
end
16-
177
methods (Access={?opentelemetry.metrics.Meter})
18-
19-
function obj = Counter(proxy, ctname, ctdescription, ctunit)
8+
function obj = Counter(proxy, name, description, unit)
209
% Private constructor. Use createCounter method of Meter
2110
% to create Counters.
22-
obj.Proxy = proxy;
23-
obj.Name = ctname;
24-
obj.Description = ctdescription;
25-
obj.Unit = ctunit;
11+
[email protected](proxy, name, description, unit);
2612
end
27-
2813
end
29-
14+
3015
methods
31-
3216
function add(obj, value, varargin)
33-
% input value must be a numerical scalar
34-
if isnumeric(value) && isscalar(value)
35-
36-
if nargin == 2
37-
obj.Proxy.add(value);
38-
39-
elseif isa(varargin{1}, "dictionary")
40-
attrkeys = keys(varargin{1});
41-
attrvals = values(varargin{1},"cell");
42-
if all(cellfun(@iscell, attrvals))
43-
attrvals = [attrvals{:}];
44-
end
45-
obj.Proxy.add(value,attrkeys,attrvals);
46-
47-
else
48-
attrkeys = [varargin{1:2:length(varargin)}]';
49-
attrvals = [varargin(2:2:length(varargin))]';
50-
obj.Proxy.add(value,attrkeys,attrvals);
51-
end
52-
end
53-
17+
obj.processValue(value, varargin{:});
5418
end
55-
5619
end
57-
58-
59-
end
20+
end
Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,19 @@
1-
classdef Histogram < handle
2-
% Histogram is an instrument that adds or reduce values.
1+
classdef Histogram < opentelemetry.metrics.SynchronousInstrument
2+
% Histogram is an instrument that aggregates values into bins
33

44
% Copyright 2023 The MathWorks, Inc.
55

6-
properties (SetAccess=immutable)
7-
Name (1,1) string
8-
Description (1,1) string
9-
Unit (1,1) string
10-
end
11-
12-
properties (Access=public)
13-
Proxy % Proxy object to interface C++ code
14-
end
15-
166
methods (Access={?opentelemetry.metrics.Meter})
17-
18-
function obj = Histogram(proxy, hiname, hidescription, hiunit)
7+
function obj = Histogram(proxy, name, description, unit)
198
% Private constructor. Use createHistogram method of Meter
209
% to create Histograms.
21-
obj.Proxy = proxy;
22-
obj.Name = hiname;
23-
obj.Description = hidescription;
24-
obj.Unit = hiunit;
10+
[email protected](proxy, name, description, unit);
2511
end
26-
2712
end
28-
13+
2914
methods
30-
3115
function record(obj, value, varargin)
32-
% input value must be a numerical scalar
33-
if isnumeric(value) && isscalar(value)
34-
if nargin == 2
35-
obj.Proxy.record(value);
36-
elseif isa(varargin{1}, "dictionary")
37-
attrkeys = keys(varargin{1});
38-
attrvals = values(varargin{1},"cell");
39-
if all(cellfun(@iscell, attrvals))
40-
attrvals = [attrvals{:}];
41-
end
42-
obj.Proxy.record(value,attrkeys,attrvals);
43-
else
44-
attrkeys = [varargin{1:2:length(varargin)}]';
45-
attrvals = [varargin(2:2:length(varargin))]';
46-
obj.Proxy.record(value,attrkeys,attrvals);
47-
end
48-
end
49-
16+
obj.processValue(value, varargin{:});
5017
end
51-
5218
end
53-
54-
5519
end

api/metrics/+opentelemetry/+metrics/Meter.m

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
ctname = mustBeScalarString(ctname);
4141
% cpp-opentelemetry end does not allow string input with spaces,
4242
% replace any spaces with underscores as a temporary fix
43-
ctname = strrep(ctname, ' ', '_');
4443
ctdescription = mustBeScalarString(ctdescription);
4544
ctunit = mustBeScalarString(ctunit);
4645
id = obj.Proxy.createCounter(ctname, ctdescription, ctunit);
@@ -62,7 +61,6 @@
6261
ctname = mustBeScalarString(ctname);
6362
% cpp-opentelemetry end does not allow string input with spaces,
6463
% replace any spaces with underscores as a temporary fix
65-
ctname = strrep(ctname, ' ', '_');
6664
ctdescription = mustBeScalarString(ctdescription);
6765
ctunit = mustBeScalarString(ctunit);
6866
id = obj.Proxy.createUpDownCounter(ctname, ctdescription, ctunit);
@@ -84,7 +82,6 @@
8482
hiname = mustBeScalarString(hiname);
8583
% cpp-opentelemetry end does not allow string input with spaces,
8684
% replace any spaces with underscores as a temporary fix
87-
hiname = strrep(hiname, ' ', '_');
8885
hidescription = mustBeScalarString(hidescription);
8986
hiunit = mustBeScalarString(hiunit);
9087
id = obj.Proxy.createHistogram(hiname, hidescription, hiunit);

api/metrics/+opentelemetry/+metrics/MeterProvider.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
% Copyright 2023 The MathWorks, Inc.
66

7-
properties (Access={?opentelemetry.sdk.metrics.MeterProvider, ?opentelemetry.sdk.metrics.Cleanup})
7+
properties (Access={?opentelemetry.sdk.metrics.MeterProvider, ?opentelemetry.sdk.common.Cleanup})
88
Proxy % Proxy object to interface C++ code
99
end
1010

@@ -60,7 +60,7 @@ function setMeterProvider(obj)
6060
end
6161
end
6262

63-
methods(Access=?opentelemetry.sdk.metrics.Cleanup)
63+
methods(Access=?opentelemetry.sdk.common.Cleanup)
6464
function postShutdown(obj)
6565
% POSTSHUTDOWN Handle post-shutdown tasks
6666
obj.Proxy.postShutdown();
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
classdef SynchronousInstrument < handle
2+
% Base class inherited by all synchronous instruments
3+
4+
% Copyright 2023 The MathWorks, Inc.
5+
6+
properties (SetAccess=immutable)
7+
Name (1,1) string
8+
Description (1,1) string
9+
Unit (1,1) string
10+
end
11+
12+
properties (Access=private)
13+
Proxy % Proxy object to interface C++ code
14+
end
15+
16+
methods (Access=protected)
17+
function obj = SynchronousInstrument(proxy, name, description, unit)
18+
obj.Proxy = proxy;
19+
obj.Name = name;
20+
obj.Description = description;
21+
obj.Unit = unit;
22+
end
23+
24+
function processValue(obj, value, varargin)
25+
% input value must be a numerical real scalar
26+
if isnumeric(value) && isscalar(value) && isreal(value)
27+
if nargin == 2
28+
obj.Proxy.processValue(value);
29+
elseif isa(varargin{1}, "dictionary")
30+
attrkeys = keys(varargin{1});
31+
attrvals = values(varargin{1},"cell");
32+
if all(cellfun(@iscell, attrvals))
33+
attrvals = [attrvals{:}];
34+
end
35+
obj.Proxy.processValue(value, attrkeys, attrvals);
36+
else
37+
attrkeys = [varargin{1:2:length(varargin)}]';
38+
attrvals = [varargin(2:2:length(varargin))]';
39+
obj.Proxy.processValue(value, attrkeys, attrvals);
40+
end
41+
end
42+
end
43+
end
44+
end
Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,19 @@
1-
classdef UpDownCounter < handle
1+
classdef UpDownCounter < opentelemetry.metrics.SynchronousInstrument
22
% UpDownCounter is an instrument that adds or reduce values.
33

44
% Copyright 2023 The MathWorks, Inc.
55

6-
properties (SetAccess=immutable)
7-
Name (1,1) string
8-
Description (1,1) string
9-
Unit (1,1) string
10-
end
11-
12-
properties (Access=public)
13-
Proxy % Proxy object to interface C++ code
14-
end
15-
166
methods (Access={?opentelemetry.metrics.Meter})
17-
18-
function obj = UpDownCounter(proxy, ctname, ctdescription, ctunit)
7+
function obj = UpDownCounter(proxy, name, description, unit)
198
% Private constructor. Use createUpDownCounter method of Meter
209
% to create UpDownCounters.
21-
obj.Proxy = proxy;
22-
obj.Name = ctname;
23-
obj.Description = ctdescription;
24-
obj.Unit = ctunit;
10+
[email protected](proxy, name, description, unit);
2511
end
26-
2712
end
28-
13+
2914
methods
30-
3115
function add(obj, value, varargin)
32-
% input value must be a numerical scalar
33-
if isnumeric(value) && isscalar(value)
34-
35-
if nargin == 2
36-
obj.Proxy.add(value);
37-
38-
elseif isa(varargin{1}, "dictionary")
39-
attrkeys = keys(varargin{1});
40-
attrvals = values(varargin{1},"cell");
41-
if all(cellfun(@iscell, attrvals))
42-
attrvals = [attrvals{:}];
43-
end
44-
obj.Proxy.add(value,attrkeys,attrvals);
45-
46-
else
47-
attrkeys = [varargin{1:2:length(varargin)}]';
48-
attrvals = [varargin(2:2:length(varargin))]';
49-
obj.Proxy.add(value,attrkeys,attrvals);
50-
end
51-
end
52-
16+
obj.processValue(value, varargin{:});
5317
end
54-
5518
end
56-
57-
58-
end
19+
end

api/metrics/include/opentelemetry-matlab/metrics/CounterProxy.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ namespace libmexclass::opentelemetry {
1818
class CounterProxy : public libmexclass::proxy::Proxy {
1919
public:
2020
CounterProxy(nostd::shared_ptr<metrics_api::Counter<double> > ct) : CppCounter(ct) {
21-
REGISTER_METHOD(CounterProxy, add);
21+
REGISTER_METHOD(CounterProxy, processValue);
2222
}
2323

24-
void add(libmexclass::proxy::method::Context& context);
24+
void processValue(libmexclass::proxy::method::Context& context);
2525

2626
private:
2727

api/metrics/include/opentelemetry-matlab/metrics/HistogramProxy.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ namespace libmexclass::opentelemetry {
2121
class HistogramProxy : public libmexclass::proxy::Proxy {
2222
public:
2323
HistogramProxy(nostd::shared_ptr<metrics_api::Histogram<double> > hist) : CppHistogram(hist) {
24-
REGISTER_METHOD(HistogramProxy, record);
24+
REGISTER_METHOD(HistogramProxy, processValue);
2525
}
2626

27-
void record(libmexclass::proxy::method::Context& context);
27+
void processValue(libmexclass::proxy::method::Context& context);
2828

2929
private:
3030

api/metrics/include/opentelemetry-matlab/metrics/UpDownCounterProxy.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ namespace libmexclass::opentelemetry {
1818
class UpDownCounterProxy : public libmexclass::proxy::Proxy {
1919
public:
2020
UpDownCounterProxy(nostd::shared_ptr<metrics_api::UpDownCounter<double> > ct) : CppUpDownCounter(ct) {
21-
REGISTER_METHOD(UpDownCounterProxy, add);
21+
REGISTER_METHOD(UpDownCounterProxy, processValue);
2222
}
2323

24-
void add(libmexclass::proxy::method::Context& context);
24+
void processValue(libmexclass::proxy::method::Context& context);
2525

2626
private:
2727

0 commit comments

Comments
 (0)