tracer = $tracer; } public function handle(Protocol $protocol, $next) { $context = $this->tracer->extract(TEXT_MAP, $protocol->getContext()); $scope = $this->tracer->startActiveSpan( 'rpc.server:' . $protocol->getInterface() . '@' . $protocol->getMethod(), [ 'child_of' => $context, 'tags' => [ SPAN_KIND => SPAN_KIND_RPC_SERVER, ], ] ); $span = $scope->getSpan(); try { return $next($protocol); } catch (Throwable $e) { $span->setTag(ERROR, $e); throw $e; } finally { $scope->close(); Coroutine::defer(function () { $this->tracer->flush(); }); } } }