Skip to content

Commit 70cd823

Browse files
committed
fix extractSpan to not rename span. fixes #170, fixes #165
1 parent 397e4f0 commit 70cd823

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

api/trace/+opentelemetry/+trace/Context.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
function sp = extractSpan(context)
88
% Extract span from context
99
% SP = OPENTELEMETRY.TRACE.CONTEXT.EXTRACTSPAN(CTXT) extracts
10-
% span SP from a context object CTXT. SP is a nonrecording span
11-
% such that ISRECORDING(SP) returns false. If CTXT does not
10+
% span SP from a context object CTXT. If CTXT does not
1211
% contain any spans, SP will be an invalid span with all-zero
1312
% trace and span IDs.
1413
%

api/trace/+opentelemetry/+trace/Span.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
obj.Proxy = libmexclass.proxy.Proxy("Name", ...
2121
"libmexclass.opentelemetry.SpanProxy", ...
2222
"ConstructorArguments", {context.Proxy.ID});
23-
obj.Name = ""; % unknown name when span is extracted from context, leave blank
2423
else % in is a proxy object
2524
obj.Proxy = proxy;
2625
obj.Name = spname;

test/autotrace_examples/manual_instrumented_example/manual_instrumented_example.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@
44

55
% Copyright 2024 The MathWorks, Inc.
66

7+
% add an attribute about input
8+
ctx = opentelemetry.context.getCurrentContext;
9+
sp = opentelemetry.trace.Context.extractSpan(ctx);
10+
setAttributes(sp, "DataSize", n);
11+
712
[x, y] = generate_data(n);
813
yf = best_fit_line(x,y);

test/tautotrace.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ function testAutoManualInstrument(testCase)
353353
at = opentelemetry.autoinstrument.AutoTrace(@manual_instrumented_example);
354354

355355
% run the example
356-
[~] = beginTrace(at, 100);
356+
n = 100;
357+
[~] = beginTrace(at, n);
357358

358359
% perform test comparisons
359360
results = readJsonResults(testCase);
@@ -381,6 +382,11 @@ function testAutoManualInstrument(testCase)
381382
verifyEqual(testCase, results{1}.resourceSpans.scopeSpans.spans.parentSpanId, results{2}.resourceSpans.scopeSpans.spans.spanId);
382383
verifyEqual(testCase, results{3}.resourceSpans.scopeSpans.spans.parentSpanId, results{5}.resourceSpans.scopeSpans.spans.spanId);
383384
verifyEqual(testCase, results{4}.resourceSpans.scopeSpans.spans.parentSpanId, results{5}.resourceSpans.scopeSpans.spans.spanId);
385+
386+
% check attribute
387+
verifyNumElements(testCase, results{6}.resourceSpans.scopeSpans.spans.attributes, 1);
388+
verifyEqual(testCase, results{6}.resourceSpans.scopeSpans.spans.attributes.key, 'DataSize');
389+
verifyEqual(testCase, results{6}.resourceSpans.scopeSpans.spans.attributes.value.doubleValue, n);
384390
end
385391
end
386392
end

0 commit comments

Comments
 (0)