Skip to content

Commit ef0d8e3

Browse files
committed
Add README file for auto instrumentation
1 parent 3f43d34 commit ef0d8e3

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ otelcol --config <otelcol-config-yaml>
101101

102102
For more examples, see the "examples" folder.
103103

104+
## Automatic Instrumentation
105+
See example [here](auto-instrumentation/README.md).
106+
104107
## Help
105108
To view documentation of individual function, type "help \<function_name>\". For example,
106109
```

auto-instrumentation/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Automatic Instrumentation
2+
3+
Automatic instrumentation provides a way to instrument MATLAB code with OpenTelemetry data without requiring any code changes.
4+
5+
## AutoTrace
6+
With AutoTrace enabled, spans are automatically started at function beginnings and ended when functions end. By default, AutoTrace instruments the input function and all of its dependencies. An example workflow is as follows:
7+
```
8+
% The example functions should be on the path when calling AutoTrace
9+
addpath("myexample");
10+
11+
% Configure a tracer provider and set it as the global instance
12+
tp = opentelemetry.sdk.trace.TracerProvider; % use default settings
13+
setTracerProvider(tp);
14+
15+
% Instrument the code
16+
at = opentelemetry.autoinstrument.AutoTrace(@myexample, TracerName="AutoTraceExample");
17+
18+
% Start the example
19+
beginTrace(at);
20+
```
21+
Using the `beginTrace` method ensures proper error handling. In the case of an error, `beginTrace` will end all spans and set the "Error" status.
22+
23+
Alternatively, you can also get the same behavior by inserting a try-catch in the starting function.
24+
```
25+
function myexample(at)
26+
% wrap a try catch around the code
27+
try
28+
% example code goes here
29+
catch ME
30+
handleError(at);
31+
end
32+
```
33+
With the try-catch, `beginTrace` method is no longer necessary and you can simply call `myexample` directly and pass in the AutoTrace object.
34+
35+
To disable automatic tracing, delete the object returned by `AutoTrace`.

0 commit comments

Comments
 (0)