|
| 1 | +classdef traceTest < matlab.perftest.TestCase |
| 2 | +% performance tests for tracing |
| 3 | + |
| 4 | + properties |
| 5 | + OtelConfigFile |
| 6 | + OtelRoot |
| 7 | + JsonFile |
| 8 | + PidFile |
| 9 | + OtelcolName |
| 10 | + Otelcol |
| 11 | + ListPid |
| 12 | + ReadPidList |
| 13 | + ExtractPid |
| 14 | + Sigint |
| 15 | + Sigterm |
| 16 | + end |
| 17 | + |
| 18 | + methods (TestClassSetup) |
| 19 | + function setupOnce(testCase) |
| 20 | + testdir = fileparts(mfilename("fullpath")); |
| 21 | + addpath(fullfile(testdir, "..")); % add directory where common setup and teardown code lives |
| 22 | + commonSetupOnce(testCase); |
| 23 | + end |
| 24 | + end |
| 25 | + |
| 26 | + methods (TestMethodSetup) |
| 27 | + function setup(testCase) |
| 28 | + commonSetup(testCase); |
| 29 | + |
| 30 | + % create a global tracer provider |
| 31 | + import opentelemetry.sdk.trace.* |
| 32 | + tp = TracerProvider(BatchSpanProcessor()); |
| 33 | + setTracerProvider(tp); |
| 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 testSpan(testCase) |
| 45 | + % start and end a span |
| 46 | + tr = opentelemetry.trace.getTracer("Tracer"); |
| 47 | + |
| 48 | + testCase.startMeasuring(); |
| 49 | + sp = startSpan(tr, "Span"); |
| 50 | + endSpan(sp); |
| 51 | + testCase.stopMeasuring(); |
| 52 | + end |
| 53 | + |
| 54 | + function testCurrentSpan(testCase) |
| 55 | + % start a span, put it in current context, end the span |
| 56 | + tr = opentelemetry.trace.getTracer("Tracer"); |
| 57 | + |
| 58 | + testCase.startMeasuring(); |
| 59 | + sp = startSpan(tr, "Span"); |
| 60 | + scope = makeCurrent(sp); %#ok<NASGU> |
| 61 | + endSpan(sp); |
| 62 | + testCase.stopMeasuring(); |
| 63 | + end |
| 64 | + |
| 65 | + function testNestedSpansImplicitContext(testCase) |
| 66 | + % nested spans, using current span as parent |
| 67 | + tr = opentelemetry.trace.getTracer("Tracer"); |
| 68 | + |
| 69 | + testCase.startMeasuring(); |
| 70 | + osp = startSpan(tr, "outer"); |
| 71 | + oscope = makeCurrent(osp); %#ok<NASGU> |
| 72 | + |
| 73 | + isp = startSpan(tr, "inner"); |
| 74 | + iscope = makeCurrent(isp); %#ok<NASGU> |
| 75 | + |
| 76 | + imsp = startSpan(tr, "innermost"); |
| 77 | + |
| 78 | + endSpan(imsp); |
| 79 | + endSpan(isp); |
| 80 | + endSpan(osp); |
| 81 | + testCase.stopMeasuring(); |
| 82 | + end |
| 83 | + |
| 84 | + function testNestedSpansExplicitContext(testCase) |
| 85 | + % nested spans, explicitly setting parents |
| 86 | + tr = opentelemetry.trace.getTracer("Tracer"); |
| 87 | + |
| 88 | + testCase.startMeasuring(); |
| 89 | + osp = startSpan(tr, "outer"); |
| 90 | + context = insertSpan(osp); |
| 91 | + |
| 92 | + isp = startSpan(tr, "inner", Context=context); |
| 93 | + context = insertSpan(isp, context); |
| 94 | + |
| 95 | + imsp = startSpan(tr, "innermost", Context=context); |
| 96 | + |
| 97 | + endSpan(imsp); |
| 98 | + endSpan(isp); |
| 99 | + endSpan(osp); |
| 100 | + testCase.stopMeasuring(); |
| 101 | + end |
| 102 | + |
| 103 | + function testAttributes(testCase) |
| 104 | + % span with 3 attributes |
| 105 | + tr = opentelemetry.trace.getTracer("Tracer"); |
| 106 | + m = magic(4); |
| 107 | + |
| 108 | + testCase.startMeasuring(); |
| 109 | + sp = startSpan(tr, "Span"); |
| 110 | + setAttributes(sp, "attribute 1", "value 1", "attribute 2", 10, ... |
| 111 | + "attribute 3", m); |
| 112 | + endSpan(sp); |
| 113 | + testCase.stopMeasuring() |
| 114 | + end |
| 115 | + |
| 116 | + function testEvents(testCase) |
| 117 | + % span with 3 events |
| 118 | + tr = opentelemetry.trace.getTracer("Tracer"); |
| 119 | + |
| 120 | + testCase.startMeasuring(); |
| 121 | + sp = startSpan(tr, "Span"); |
| 122 | + addEvent(sp, "event 1") |
| 123 | + addEvent(sp, "event 2"); |
| 124 | + addEvent(sp, "event 3"); |
| 125 | + endSpan(sp); |
| 126 | + testCase.stopMeasuring() |
| 127 | + end |
| 128 | + |
| 129 | + function testLinks(testCase) |
| 130 | + % span with 2 links |
| 131 | + tr = opentelemetry.trace.getTracer("Tracer"); |
| 132 | + sp1 = startSpan(tr, "Span 1"); |
| 133 | + sp1ctxt = getSpanContext(sp1); |
| 134 | + sp2 = startSpan(tr, "Span 2"); |
| 135 | + sp2ctxt = getSpanContext(sp2); |
| 136 | + |
| 137 | + testCase.startMeasuring(); |
| 138 | + link1 = opentelemetry.trace.Link(sp1ctxt); |
| 139 | + link2 = opentelemetry.trace.Link(sp2ctxt); |
| 140 | + sp3 = startSpan(tr, "Span 3", Links=[link1 link2]); |
| 141 | + endSpan(sp3); |
| 142 | + testCase.stopMeasuring() |
| 143 | + end |
| 144 | + |
| 145 | + function testGetTracer(testCase) |
| 146 | + % get a tracer from the global tracer provider instance |
| 147 | + testCase.startMeasuring(); |
| 148 | + tr = opentelemetry.trace.getTracer("Tracer"); %#ok<NASGU> |
| 149 | + testCase.stopMeasuring(); |
| 150 | + end |
| 151 | + |
| 152 | + function testCreateDefaultTracerProvider(testCase) |
| 153 | + % create default TracerProvider in the sdk |
| 154 | + testCase.startMeasuring(); |
| 155 | + tp = opentelemetry.sdk.trace.TracerProvider(); %#ok<NASGU> |
| 156 | + testCase.stopMeasuring(); |
| 157 | + end |
| 158 | + |
| 159 | + function testSpanContext(testCase) |
| 160 | + % retrieve trace ID and span ID in the span context |
| 161 | + tr = opentelemetry.trace.getTracer("Tracer"); |
| 162 | + sp = startSpan(tr, "Span"); |
| 163 | + |
| 164 | + testCase.startMeasuring(); |
| 165 | + spctxt = getSpanContext(sp); |
| 166 | + traceid = spctxt.TraceId; %#ok<NASGU> |
| 167 | + spanid = spctxt.SpanId; %#ok<NASGU> |
| 168 | + testCase.stopMeasuring(); |
| 169 | + end |
| 170 | + |
| 171 | + end |
| 172 | +end |
0 commit comments