@@ -161,6 +161,9 @@ public static function start(ExporterInterface $reporter, array $options = [])
161161 */
162162 public static function inSpan (array $ spanOptions , callable $ callable , array $ arguments = [])
163163 {
164+ if (!isset (self ::$ instance )) {
165+ return call_user_func_array ($ callable , $ arguments );
166+ }
164167 return self ::$ instance ->inSpan ($ spanOptions , $ callable , $ arguments );
165168 }
166169
@@ -186,6 +189,9 @@ public static function inSpan(array $spanOptions, callable $callable, array $arg
186189 */
187190 public static function startSpan (array $ spanOptions = [])
188191 {
192+ if (!isset (self ::$ instance )) {
193+ return new Span ();
194+ }
189195 return self ::$ instance ->startSpan ($ spanOptions );
190196 }
191197
@@ -195,8 +201,8 @@ public static function startSpan(array $spanOptions = [])
195201 *
196202 * Example:
197203 * ```
198- * $span = RequestTracer ::startSpan(['name' => 'expensive-operation']);
199- * $scope = RequestTracer ::withSpan($span);
204+ * $span = Tracer ::startSpan(['name' => 'expensive-operation']);
205+ * $scope = Tracer ::withSpan($span);
200206 * try {
201207 * // do something expensive
202208 * } finally {
@@ -209,6 +215,10 @@ public static function startSpan(array $spanOptions = [])
209215 */
210216 public static function withSpan (Span $ span )
211217 {
218+ if (!isset (self ::$ instance )) {
219+ return new Scope (function () {
220+ });
221+ }
212222 return self ::$ instance ->withSpan ($ span );
213223 }
214224
@@ -223,6 +233,9 @@ public static function withSpan(Span $span)
223233 */
224234 public static function addAttribute ($ attribute , $ value , $ options = [])
225235 {
236+ if (!isset (self ::$ instance )) {
237+ return ;
238+ }
226239 return self ::$ instance ->addAttribute ($ attribute , $ value , $ options );
227240 }
228241
@@ -233,6 +246,9 @@ public static function addAttribute($attribute, $value, $options = [])
233246 */
234247 public static function spanContext ()
235248 {
249+ if (!isset (self ::$ instance )) {
250+ return new SpanContext (null , null , false );
251+ }
236252 return self ::$ instance ->tracer ()->spanContext ();
237253 }
238254}
0 commit comments