-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from mathworks/autotrace
Add an AutoTrace example
- Loading branch information
Showing
10 changed files
with
114 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# AutoTrace Example | ||
This example shows how to use AutoTrace to automatically instrument MATLAB code. The instrumented code in *autotrace_example.m* fits a line through a cluster of data points. Notice that it does not include any instrumentation code. | ||
The function *run_example.m* first configures a tracer provider. This step only needs to be done once in a MATLAB session. Then it creates an AutoTrace object and runs it. The AutoTrace object gets cleaned up at the end. | ||
|
||
## Running the Example | ||
1. Start an instance of [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector). | ||
2. Start MATLAB. | ||
3. Ensure the installation directory of OpenTelemetry-matlab is on the MATLAB path. | ||
4. Run `run_example`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
function yf = autotrace_example | ||
% This example shows some simple MATLAB code that fits a line through a | ||
% cluster of data points. It does not include any instrumentation code. | ||
|
||
% Copyright 2024 The MathWorks, Inc. | ||
|
||
[x, y] = generate_data(); | ||
yf = best_fit_line(x,y); | ||
end | ||
|
||
function [x, y] = generate_data | ||
% generate some random data | ||
a = 1.5; | ||
b = 0.8; | ||
sigma = 5; | ||
x = 1:100; | ||
y = a * x + b + sigma * randn(1, 100); | ||
end | ||
|
||
function yf = best_fit_line(x, y) | ||
% fit a line through points defined by inputs x and y | ||
coefs = polyfit(x, y, 1); | ||
yf = polyval(coefs , x); | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function yf = run_example | ||
% Use AutoTrace to automatically instrument an example to produce a trace. | ||
|
||
% Copyright 2024 The MathWorks, Inc. | ||
|
||
% configure tracer provider | ||
resource = dictionary("service.name", "OpenTelemetry-Matlab_examples"); | ||
tp = opentelemetry.sdk.trace.TracerProvider(Resource=resource); | ||
setTracerProvider(tp); | ||
|
||
% create AutoTrace object | ||
at = opentelemetry.autoinstrument.AutoTrace(@autotrace_example, ... | ||
TracerName="autotrace_example"); | ||
|
||
% run the example | ||
yf = beginTrace(at); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters