diff --git a/api/trace/+opentelemetry/+trace/getCurrentSpan.m b/api/trace/+opentelemetry/+trace/getCurrentSpan.m new file mode 100644 index 0000000..ac757a6 --- /dev/null +++ b/api/trace/+opentelemetry/+trace/getCurrentSpan.m @@ -0,0 +1,14 @@ +function sp = getCurrentSpan() +% Retrieve the current span +% SP = OPENTELEMETRY.TRACE.GETCURRENTSPAN() returns the current span. +% If there is not current span, SP will be an invalid span with all-zero +% trace and span IDs. +% +% See also OPENTELEMETRY.TRACE.SPAN, +% OPENTELEMETRY.CONTEXT.GETCURRENTCONTEXT +% OPENTELEMETRY.TRACE.CONTEXT.EXTRACTSPAN + +% Copyright 2024 The MathWorks, Inc. + +ctx = opentelemetry.context.getCurrentContext; +sp = opentelemetry.trace.Context.extractSpan(ctx); 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 33cc9a0..85e0080 100644 --- a/test/autotrace_examples/manual_instrumented_example/manual_instrumented_example.m +++ b/test/autotrace_examples/manual_instrumented_example/manual_instrumented_example.m @@ -5,8 +5,7 @@ % Copyright 2024 The MathWorks, Inc. % add an attribute about input -ctx = opentelemetry.context.getCurrentContext; -sp = opentelemetry.trace.Context.extractSpan(ctx); +sp = opentelemetry.trace.getCurrentSpan; setAttributes(sp, "DataSize", n); [x, y] = generate_data(n);