1+ classdef tautotrace < matlab .unittest .TestCase
2+ % tests for AutoTrace
3+
4+ % Copyright 2024 The MathWorks, Inc.
5+
6+ properties
7+ OtelConfigFile
8+ JsonFile
9+ PidFile
10+ OtelcolName
11+ Otelcol
12+ ListPid
13+ ReadPidList
14+ ExtractPid
15+ Sigint
16+ Sigterm
17+ end
18+
19+ methods (TestClassSetup )
20+ function setupOnce(testCase )
21+ % add the utils folder to the path
22+ utilsfolder = fullfile(fileparts(mfilename(' fullpath' )), " utils" );
23+ testCase .applyFixture(matlab .unittest .fixtures .PathFixture(utilsfolder ));
24+ % add the example folder to the path
25+ example1folder = fullfile(fileparts(mfilename(' fullpath' )), " autotrace_examples" , " example1" );
26+ testCase .applyFixture(matlab .unittest .fixtures .PathFixture(example1folder ));
27+ commonSetupOnce(testCase );
28+ end
29+ end
30+
31+ methods (TestMethodSetup )
32+ function setup(testCase )
33+ commonSetup(testCase );
34+ end
35+ end
36+
37+ methods (TestMethodTeardown )
38+ function teardown(testCase )
39+ commonTeardown(testCase );
40+ end
41+ end
42+
43+ methods (Test )
44+ function testBasic(testCase )
45+ % testBasic: instrument a simple example
46+
47+ % configure the global tracer provider
48+ tp = opentelemetry .sdk .trace .TracerProvider();
49+ setTracerProvider(tp );
50+ clear(" tp" );
51+
52+ % set up AutoTrace
53+ at = opentelemetry .autoinstrument .AutoTrace(@example1 );
54+
55+ % run the example
56+ [~ ] = beginTrace(at , 100 );
57+
58+ % perform test comparisons
59+ results = readJsonResults(testCase );
60+ verifyNumElements(testCase , results , 3 );
61+
62+ % check logger name, log body and severity, trace and span IDs
63+ verifyEqual(testCase , string(results{1 }.resourceSpans.scopeSpans.scope.name), " AutoTrace" );
64+ verifyEqual(testCase , string(results{1 }.resourceSpans.scopeSpans.spans.name), " generate_data" );
65+ verifyEqual(testCase , string(results{2 }.resourceSpans.scopeSpans.spans.name), " best_fit_line" );
66+ verifyEqual(testCase , string(results{3 }.resourceSpans.scopeSpans.spans.name), " example1" );
67+ end
68+ end
69+ end
0 commit comments