Skip to content

Commit

Permalink
fix extractSpan to not rename span. fixes #170, fixes #165
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanpo committed Nov 13, 2024
1 parent 397e4f0 commit 70cd823
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
3 changes: 1 addition & 2 deletions api/trace/+opentelemetry/+trace/Context.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
function sp = extractSpan(context)
% Extract span from context
% SP = OPENTELEMETRY.TRACE.CONTEXT.EXTRACTSPAN(CTXT) extracts
% span SP from a context object CTXT. SP is a nonrecording span
% such that ISRECORDING(SP) returns false. If CTXT does not
% span SP from a context object CTXT. If CTXT does not
% contain any spans, SP will be an invalid span with all-zero
% trace and span IDs.
%
Expand Down
1 change: 0 additions & 1 deletion api/trace/+opentelemetry/+trace/Span.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
obj.Proxy = libmexclass.proxy.Proxy("Name", ...
"libmexclass.opentelemetry.SpanProxy", ...
"ConstructorArguments", {context.Proxy.ID});
obj.Name = ""; % unknown name when span is extracted from context, leave blank
else % in is a proxy object
obj.Proxy = proxy;
obj.Name = spname;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@

% Copyright 2024 The MathWorks, Inc.

% add an attribute about input
ctx = opentelemetry.context.getCurrentContext;
sp = opentelemetry.trace.Context.extractSpan(ctx);
setAttributes(sp, "DataSize", n);

[x, y] = generate_data(n);
yf = best_fit_line(x,y);
8 changes: 7 additions & 1 deletion test/tautotrace.m
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ function testAutoManualInstrument(testCase)
at = opentelemetry.autoinstrument.AutoTrace(@manual_instrumented_example);

% run the example
[~] = beginTrace(at, 100);
n = 100;
[~] = beginTrace(at, n);

% perform test comparisons
results = readJsonResults(testCase);
Expand Down Expand Up @@ -381,6 +382,11 @@ function testAutoManualInstrument(testCase)
verifyEqual(testCase, results{1}.resourceSpans.scopeSpans.spans.parentSpanId, results{2}.resourceSpans.scopeSpans.spans.spanId);
verifyEqual(testCase, results{3}.resourceSpans.scopeSpans.spans.parentSpanId, results{5}.resourceSpans.scopeSpans.spans.spanId);
verifyEqual(testCase, results{4}.resourceSpans.scopeSpans.spans.parentSpanId, results{5}.resourceSpans.scopeSpans.spans.spanId);

% check attribute
verifyNumElements(testCase, results{6}.resourceSpans.scopeSpans.spans.attributes, 1);
verifyEqual(testCase, results{6}.resourceSpans.scopeSpans.spans.attributes.key, 'DataSize');
verifyEqual(testCase, results{6}.resourceSpans.scopeSpans.spans.attributes.value.doubleValue, n);
end
end
end

0 comments on commit 70cd823

Please sign in to comment.