Skip to content

Commit

Permalink
add getCurrentSpan convenience function
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanpo committed Nov 13, 2024
1 parent 70cd823 commit 618e16c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
14 changes: 14 additions & 0 deletions api/trace/+opentelemetry/+trace/getCurrentSpan.m
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 618e16c

Please sign in to comment.