From 70cd823c85a1a619d660c017e2af6f6826058c0c Mon Sep 17 00:00:00 2001 From: duncanpo Date: Wed, 13 Nov 2024 10:43:46 -0500 Subject: [PATCH] fix extractSpan to not rename span. fixes #170, fixes #165 --- api/trace/+opentelemetry/+trace/Context.m | 3 +-- api/trace/+opentelemetry/+trace/Span.m | 1 - .../manual_instrumented_example.m | 5 +++++ test/tautotrace.m | 8 +++++++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/api/trace/+opentelemetry/+trace/Context.m b/api/trace/+opentelemetry/+trace/Context.m index 6e85dd2..0c7a0b5 100644 --- a/api/trace/+opentelemetry/+trace/Context.m +++ b/api/trace/+opentelemetry/+trace/Context.m @@ -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. % diff --git a/api/trace/+opentelemetry/+trace/Span.m b/api/trace/+opentelemetry/+trace/Span.m index 7ea4541..e07aab9 100644 --- a/api/trace/+opentelemetry/+trace/Span.m +++ b/api/trace/+opentelemetry/+trace/Span.m @@ -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; diff --git a/test/autotrace_examples/manual_instrumented_example/manual_instrumented_example.m b/test/autotrace_examples/manual_instrumented_example/manual_instrumented_example.m index 020f6cb..33cc9a0 100644 --- a/test/autotrace_examples/manual_instrumented_example/manual_instrumented_example.m +++ b/test/autotrace_examples/manual_instrumented_example/manual_instrumented_example.m @@ -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); \ No newline at end of file diff --git a/test/tautotrace.m b/test/tautotrace.m index b8a8b36..3a74696 100644 --- a/test/tautotrace.m +++ b/test/tautotrace.m @@ -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); @@ -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 \ No newline at end of file