Skip to content

Commit 8cee06f

Browse files
committed
fix an AutoTrace bug that fails to deal with file types other than .m or .mlx. Fixes #196.
1 parent 2f6f585 commit 8cee06f

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

auto-instrumentation/+opentelemetry/+autoinstrument/AutoTrace.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,19 @@
7171
if isdeployed
7272
% matlab.codetools.requiredFilesAndProducts is not
7373
% deployable. Instead instrument all files under CTFROOT
74-
fileinfo = dir(fullfile(ctfroot, "**", "*.m"));
74+
fileinfo = [reshape(dir(fullfile(ctfroot, "**", "*.m")), [], 1); ...
75+
reshape(dir(fullfile(ctfroot, "**", "*.mlx")), [], 1)];
7576
files = fullfile(string({fileinfo.folder}), string({fileinfo.name}));
7677

7778
% filter out internal files in the toolbox directory
7879
files = files(~startsWith(files, fullfile(ctfroot, "toolbox")));
7980
else
8081
%#exclude matlab.codetools.requiredFilesAndProducts
8182
files = string(matlab.codetools.requiredFilesAndProducts(startfunname));
83+
84+
% keep only .m and .mlx files. Filter out everything else
85+
[~,~,fext] = fileparts(files);
86+
files = files(ismember(fext, [".m" ".mlx"]));
8287
end
8388
else
8489
% only include the input file, not its dependencies
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function y = matfile_example
2+
% Example code for testing auto instrumentation, which loads a .mat file
3+
4+
% Copyright 2025 The MathWorks, Inc.
5+
6+
load("mymagic", "x");
7+
y = sum(x);
183 Bytes
Binary file not shown.

test/tautotrace.m

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,28 @@ function testNonFileOptions(testCase)
256256
end
257257
end
258258

259+
function testUnsupportedDependentFiles(testCase)
260+
% testUnsupportedDependentFiles: Check that File dependencies that are not
261+
% .m or .mlx files are ignored. For example, .mat file.
262+
263+
% Add example folders to the path
264+
examplefolder = fullfile(fileparts(mfilename('fullpath')), "autotrace_examples", "matfile_example");
265+
testCase.applyFixture(matlab.unittest.fixtures.PathFixture(examplefolder));
266+
267+
% set up AutoTrace
268+
at = opentelemetry.autoinstrument.AutoTrace(@matfile_example);
269+
270+
% run the example
271+
[~] = beginTrace(at);
272+
273+
% perform test comparisons
274+
results = readJsonResults(testCase);
275+
276+
% should only return 1 span
277+
verifyNumElements(testCase, results, 1);
278+
verifyEqual(testCase, string(results{1}.resourceSpans.scopeSpans.spans.name), "matfile_example");
279+
end
280+
259281
function testError(testCase)
260282
% testError: handling error situation
261283

0 commit comments

Comments
 (0)