-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtjsonbytesmapping.m
More file actions
93 lines (77 loc) · 3.12 KB
/
tjsonbytesmapping.m
File metadata and controls
93 lines (77 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
classdef tjsonbytesmapping < matlab.unittest.TestCase
% tests for setting JsonBytesMapping in the exporter
% Copyright 2025 The MathWorks, Inc.
properties
OtelConfigFile
JsonFile
PidFile
OtelcolName
Otelcol
ListPid
ReadPidList
ExtractPid
Sigint
Sigterm
end
methods (TestClassSetup)
function setupOnce(testCase)
% add the utils folder to the path
utilsfolder = fullfile(fileparts(mfilename('fullpath')), "utils");
testCase.applyFixture(matlab.unittest.fixtures.PathFixture(utilsfolder));
commonSetupOnce(testCase);
end
end
methods (TestMethodSetup)
function setup(testCase)
commonSetup(testCase);
end
end
methods (TestMethodTeardown)
function teardown(testCase)
commonTeardown(testCase);
end
end
methods (Test)
function testNondefaultJsonBytesMapping(testCase)
% testNondefaultJsonBytesMapping: using an alternative JsonBytesMapping
testCase.assumeTrue(logical(exist("opentelemetry.exporters.otlp.OtlpHttpSpanExporter", "class")), ...
"Otlp HTTP exporter must be installed.");
tracername = "foo";
spanname = "bar";
exp = opentelemetry.exporters.otlp.OtlpHttpSpanExporter(...
"JsonBytesMapping", "base64");
processor = opentelemetry.sdk.trace.SimpleSpanProcessor(exp);
tp = opentelemetry.sdk.trace.TracerProvider(processor);
tr = getTracer(tp, tracername);
sp = startSpan(tr, spanname);
pause(1);
endSpan(sp);
% perform test comparisons
results = readJsonResults(testCase);
results = results{1};
% check span and tracer names
verifyEqual(testCase, string(results.resourceSpans.scopeSpans.spans.name), spanname);
verifyEqual(testCase, string(results.resourceSpans.scopeSpans.scope.name), tracername);
end
function NondefaultMetricsJsonBytesMapping(testCase)
% testNondefaultMetricsJsonBytesMapping: using an alternative JsonBytesMapping
testCase.assumeTrue(logical(exist("opentelemetry.exporters.otlp.OtlpHttpMetricExporter", "class")), ...
"Otlp HTTP exporter must be installed.");
exp = opentelemetry.exporters.otlp.OtlpHttpMetricExporter(...
"JsonBytesMapping", "base64");
reader = opentelemetry.sdk.metrics.PeriodicExportingMetricReader(...
exp, "Interval", seconds(2), "Timeout", seconds(1));
p = opentelemetry.sdk.metrics.MeterProvider(reader);
mt = p.getMeter("foo");
ct = mt.createCounter("bar");
val = 4;
ct.add(val);
pause(2.5);
% fetch result
clear p;
results = readJsonResults(testCase);
% verify counter value
verifyEqual(testCase, results{end}.resourceMetrics.scopeMetrics.metrics.sum.dataPoints.asDouble, val);
end
end
end