66
77 properties (Access = private )
88 Proxy % Proxy object to interface C++ code
9+ isShutdown (1 ,1 ) logical = false
910 end
1011
1112 properties (SetAccess = private )
@@ -101,8 +102,10 @@ function addSpanProcessor(obj, processor)
101102 obj
102103 processor (1 ,1 ) {mustBeA(processor , " opentelemetry.sdk.trace.SpanProcessor" )}
103104 end
104- obj .Proxy .addSpanProcessor(processor .Proxy .ID );
105- obj .SpanProcessor(end + 1 ) = processor ; % append
105+ if ~obj .isShutdown
106+ obj .Proxy .addSpanProcessor(processor .Proxy .ID );
107+ obj .SpanProcessor(end + 1 ) = processor ; % append
108+ end
106109 end
107110
108111 function tracer = getTracer(obj , trname , trversion , trschema )
@@ -125,13 +128,14 @@ function addSpanProcessor(obj, processor)
125128 % name, version, schema accepts any types that can convert to a
126129 % string
127130 import opentelemetry .utils .mustBeScalarString
128- trname = mustBeScalarString(trname );
131+ trname = mustBeScalarString(trname );
129132 trversion = mustBeScalarString(trversion );
130133 trschema = mustBeScalarString(trschema );
131134 id = obj .Proxy .getTracer(trname , trversion , trschema );
132- tracerproxy = libmexclass .proxy .Proxy(" Name" , ...
135+
136+ tracerproxy = libmexclass .proxy .Proxy(" Name" , ...
133137 " libmexclass.opentelemetry.TracerProxy" , " ID" , id );
134- tracer = opentelemetry .trace .Tracer(tracerproxy , trname , trversion , trschema );
138+ tracer = opentelemetry .trace .Tracer(tracerproxy , trname , trversion , trschema );
135139 end
136140
137141 function setTracerProvider(obj )
@@ -142,5 +146,39 @@ function setTracerProvider(obj)
142146 % See also OPENTELEMETRY.TRACE.PROVIDER.GETTRACERPROVIDER
143147 obj .Proxy .setTracerProvider();
144148 end
149+
150+ function success = shutdown(obj )
151+ % SHUTDOWN Shutdown
152+ % SUCCESS = SHUTDOWN(TP) shuts down all span processors associated with tracer provider TP
153+ % and return a logical that indicates whether shutdown was successful.
154+ %
155+ % See also FORCEFLUSH
156+ if ~obj .isShutdown
157+ success = obj .Proxy .shutdown();
158+ obj.isShutdown = success ;
159+ else
160+ success = true ;
161+ end
162+ end
163+
164+ function success = forceFlush(obj , timeout )
165+ % FORCEFLUSH Force flush
166+ % SUCCESS = FORCEFLUSH(TP) immediately exports all spans
167+ % that have not yet been exported. Returns a logical that
168+ % indicates whether force flush was successful.
169+ %
170+ % SUCCESS = FORCEFLUSH(TP, TIMEOUT) specifies a TIMEOUT
171+ % duration. Force flush must be completed within this time,
172+ % or else it will fail.
173+ %
174+ % See also SHUTDOWN
175+ if obj .isShutdown
176+ success = false ;
177+ elseif nargin < 2 || ~isa(timeout , " duration" ) % ignore timeout if not a duration
178+ success = obj .Proxy .forceFlush();
179+ else
180+ success = obj .Proxy .forceFlush(milliseconds(timeout )*1000 ); % convert to microseconds
181+ end
182+ end
145183 end
146184end
0 commit comments