Skip to content

Commit

Permalink
Merge pull request #29 from mathworks/metrics_reader
Browse files Browse the repository at this point in the history
fix: invalid instrument names with spaces
  • Loading branch information
duncanpo authored Oct 6, 2023
2 parents 2636072 + e995d79 commit 9af0a3d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
15 changes: 12 additions & 3 deletions api/metrics/+opentelemetry/+metrics/Meter.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
ctunit = ""
end
import opentelemetry.common.mustBeScalarString
ctname = mustBeScalarString(ctname);
ctname = mustBeScalarString(ctname);
% cpp-opentelemetry end does not allow string input with spaces,
% replace any spaces with underscores as a temporary fix
ctname = strrep(ctname, ' ', '_');
ctdescription = mustBeScalarString(ctdescription);
ctunit = mustBeScalarString(ctunit);
id = obj.Proxy.createCounter(ctname, ctdescription, ctunit);
Expand All @@ -56,7 +59,10 @@
end

import opentelemetry.common.mustBeScalarString
ctname = mustBeScalarString(ctname);
ctname = mustBeScalarString(ctname);
% cpp-opentelemetry end does not allow string input with spaces,
% replace any spaces with underscores as a temporary fix
ctname = strrep(ctname, ' ', '_');
ctdescription = mustBeScalarString(ctdescription);
ctunit = mustBeScalarString(ctunit);
id = obj.Proxy.createUpDownCounter(ctname, ctdescription, ctunit);
Expand All @@ -75,7 +81,10 @@
end

import opentelemetry.common.mustBeScalarString
hiname = mustBeScalarString(hiname);
hiname = mustBeScalarString(hiname);
% cpp-opentelemetry end does not allow string input with spaces,
% replace any spaces with underscores as a temporary fix
hiname = strrep(hiname, ' ', '_');
hidescription = mustBeScalarString(hidescription);
hiunit = mustBeScalarString(hiunit);
id = obj.Proxy.createHistogram(hiname, hidescription, hiunit);
Expand Down
12 changes: 7 additions & 5 deletions test/tmetrics.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,17 @@ function testAddMetricReader(testCase)
ct = mt.createCounter(countername);

% verify if the provider has two metric readers attached
reader_size = size(p.MetricReader);
verifyEqual(testCase,reader_size(2), 2);
reader_count = numel(p.MetricReader);
verifyEqual(testCase,reader_count, 2);

% verify if the json results has two exported instances
% verify if the json results has two exported instances after
% adding a single value
ct.add(1);
pause(2.5);
clear p;
results = readJsonResults(testCase);
result_size = size(results);
verifyEqual(testCase,result_size(2), 2);
result_count = numel(results);
verifyEqual(testCase,result_count, 2);
end


Expand Down Expand Up @@ -189,6 +190,7 @@ function testCounterDelta(testCase)
verifyEqual(testCase, dp2.asDouble, vals(2));
end


function testCounterAddAttributes(testCase)
% test names, added value and attributes in Counter

Expand Down

0 comments on commit 9af0a3d

Please sign in to comment.