Skip to content

Commit 2f6f585

Browse files
committed
fix a bug when autotrace includes or excludes multiple folders, fixes #195
1 parent c663569 commit 2f6f585

File tree

8 files changed

+75
-3
lines changed

8 files changed

+75
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
classdef AutoTrace < handle
22
% Automatic instrumentation with OpenTelemetry tracing.
33

4-
% Copyright 2024 The MathWorks, Inc.
4+
% Copyright 2024-2025 The MathWorks, Inc.
55

66
properties (SetAccess=private)
77
StartFunction function_handle % entry function
@@ -190,7 +190,7 @@ function handleError(obj, ME)
190190
mfiles = fullfile(string({mfileinfo.folder}), string({mfileinfo.name}));
191191
mlxfileinfo = dir(fullfile(f, "*.mlx"));
192192
mlxfiles = fullfile(string({mlxfileinfo.folder}), string({mlxfileinfo.name}));
193-
f = [mfiles; mlxfiles];
193+
f = [mfiles(:); mlxfiles(:)];
194194
else
195195
% file
196196
f = processFileInput(f);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function x = subfolder_helper1_1(x)
2+
% example code for testing auto instrumentation, helper function
3+
4+
% Copyright 2025 The MathWorks, Inc.
5+
6+
x = x * 2;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function x = subfolder_helper1_2(x)
2+
% example code for testing auto instrumentation, helper function
3+
4+
% Copyright 2025 The MathWorks, Inc.
5+
6+
x = x * 3;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function x = subfolder_helper2_1(x)
2+
% example code for testing auto instrumentation, helper function
3+
4+
% Copyright 2025 The MathWorks, Inc.
5+
6+
x = x * 4;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function x = subfolder_helper2_2(x)
2+
% example code for testing auto instrumentation, helper function
3+
4+
% Copyright 2025 The MathWorks, Inc.
5+
6+
x = x * 5;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function x = subfolder_helper2_3(x)
2+
% example code for testing auto instrumentation, helper function
3+
4+
% Copyright 2025 The MathWorks, Inc.
5+
6+
x = x * 5;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function x = two_subfolders_example
2+
% Example code for testing auto instrumentation, with helper functions
3+
% in a two subfolders
4+
5+
% Copyright 2025 The MathWorks, Inc.
6+
7+
x = 10;
8+
x = subfolder_helper1_1(x);
9+
x = subfolder_helper1_2(x);
10+
x = subfolder_helper2_1(x);
11+
x = subfolder_helper2_2(x);
12+
x = subfolder_helper2_3(x);
13+

test/tautotrace.m

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
classdef tautotrace < matlab.unittest.TestCase
22
% tests for AutoTrace
33

4-
% Copyright 2024 The MathWorks, Inc.
4+
% Copyright 2024-2025 The MathWorks, Inc.
55

66
properties
77
OtelConfigFile
@@ -155,6 +155,35 @@ function testIncludeFolder(testCase)
155155
verifyEqual(testCase, results{2}.resourceSpans.scopeSpans.spans.parentSpanId, results{3}.resourceSpans.scopeSpans.spans.spanId);
156156
end
157157

158+
function testMultipleIncludeFolders(testCase)
159+
% testMultipleIncludeFolders: specify multiple folders in AdditionalFiles
160+
161+
% Add example folders to the path
162+
examplefolder = fullfile(fileparts(mfilename('fullpath')), "autotrace_examples", "two_subfolders_example");
163+
testCase.applyFixture(matlab.unittest.fixtures.PathFixture(examplefolder, ...
164+
"IncludingSubfolders",true));
165+
166+
% set up AutoTrace, turn off automatic detection and specify
167+
% dependencies using their folder name
168+
at = opentelemetry.autoinstrument.AutoTrace(@two_subfolders_example, ...
169+
"AutoDetectFiles", false, "AdditionalFiles", fullfile(examplefolder, ["helper1" "helper2"]));
170+
171+
% run the example
172+
[~] = beginTrace(at);
173+
174+
% perform test comparisons
175+
results = readJsonResults(testCase);
176+
verifyNumElements(testCase, results, 6);
177+
178+
% check span names
179+
verifyEqual(testCase, string(results{1}.resourceSpans.scopeSpans.spans.name), "subfolder_helper1_1");
180+
verifyEqual(testCase, string(results{2}.resourceSpans.scopeSpans.spans.name), "subfolder_helper1_2");
181+
verifyEqual(testCase, string(results{3}.resourceSpans.scopeSpans.spans.name), "subfolder_helper2_1");
182+
verifyEqual(testCase, string(results{4}.resourceSpans.scopeSpans.spans.name), "subfolder_helper2_2");
183+
verifyEqual(testCase, string(results{5}.resourceSpans.scopeSpans.spans.name), "subfolder_helper2_3");
184+
verifyEqual(testCase, string(results{6}.resourceSpans.scopeSpans.spans.name), "two_subfolders_example");
185+
end
186+
158187
function testExcludeFolder(testCase)
159188
% testExcludeFolder: specify a folder in ExcludeFiles
160189

0 commit comments

Comments
 (0)