Skip to content

Commit 40211f0

Browse files
committed
Add a test for combining auto and manual instrumentation and clean up AutoTrace test examples
1 parent 1b9ff8a commit 40211f0

File tree

14 files changed

+195
-72
lines changed

14 files changed

+195
-72
lines changed

test/autotrace_examples/example2/example2.m

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/autotrace_examples/example2/helpers/ex2helper1.m

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/autotrace_examples/example2/helpers/ex2helper2.m

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/autotrace_examples/example1/best_fit_line.m renamed to test/autotrace_examples/linearfit_example/best_fit_line.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function yf = best_fit_line(x, y)
2-
% example code for testing auto instrumentation
2+
% Fit a straight line on input data
33

44
% Copyright 2024 The MathWorks, Inc.
55

test/autotrace_examples/example1/generate_data.m renamed to test/autotrace_examples/linearfit_example/generate_data.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
function [x, y] = generate_data(n)
2-
% example code for testing auto instrumentation
2+
% Generate random data with n data points
33

44
% Copyright 2024 The MathWorks, Inc.
55

66
% check input is valid
77
if ~(isnumeric(n) && isscalar(n))
8-
error("autotrace_examples:example1:generate_data:InvalidN", ...
8+
error("autotrace_examples:linearfit_example:generate_data:InvalidN", ...
99
"Input must be a numeric scalar");
1010
end
1111

test/autotrace_examples/example1/example1.m renamed to test/autotrace_examples/linearfit_example/linearfit_example.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
function yf = example1(n)
2-
% example code for testing auto instrumentation. Input n is the number of
1+
function yf = linearfit_example(n)
2+
% Example code for testing auto instrumentation. Input n is the number of
33
% data points.
44

55
% Copyright 2024 The MathWorks, Inc.

test/autotrace_examples/example1/example1_trycatch.m renamed to test/autotrace_examples/linearfit_example/linearfit_example_trycatch.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
function yf = example1_trycatch(at, n)
2-
% example code for testing auto instrumentation. This example should not
1+
function yf = linearfit_example_trycatch(at, n)
2+
% Example code for testing auto instrumentation. This example should not
33
% use beginTrace method and instead should be called directly.
44

55
% Copyright 2024 The MathWorks, Inc.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function yf = best_fit_line(x, y)
2+
% Fit a straight line on input data and manually start and end two spans.
3+
4+
% Copyright 2024 The MathWorks, Inc.
5+
6+
tr = opentelemetry.trace.getTracer("ManualInstrument");
7+
8+
sp1 = startSpan(tr, "polyfit");
9+
coefs = polyfit(x, y, 1);
10+
endSpan(sp1);
11+
12+
sp2 = startSpan(tr, "polyval");
13+
yf = polyval(coefs , x);
14+
endSpan(sp2);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function [x, y] = generate_data(n)
2+
% Generate random data with n data points and manually start and end a span.
3+
4+
% Copyright 2024 The MathWorks, Inc.
5+
6+
% check input is valid
7+
if ~(isnumeric(n) && isscalar(n))
8+
error("autotrace_examples:linearfit_example:generate_data:InvalidN", ...
9+
"Input must be a numeric scalar");
10+
end
11+
12+
% generate some random data
13+
a = 1.5;
14+
b = 0.8;
15+
sigma = 5;
16+
x = 1:n;
17+
18+
% start a span
19+
tr = opentelemetry.trace.getTracer("ManualInstrument");
20+
sp = startSpan(tr, "compute_y");
21+
y = a * x + b + sigma * randn(1, n);
22+
endSpan(sp);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function yf = manual_instrumented_example(n)
2+
% Example code for testing auto and manual instrumentation together.
3+
% Input n is the number of data points.
4+
5+
% Copyright 2024 The MathWorks, Inc.
6+
7+
[x, y] = generate_data(n);
8+
yf = best_fit_line(x,y);

0 commit comments

Comments
 (0)