tracer = $tracer; } public function handle(Protocol $protocol, $next) { $scope = $this->tracer->startActiveSpan( 'rpc.client:' . $protocol->getInterface() . '@' . $protocol->getMethod(), [ 'tags' => [ SPAN_KIND => SPAN_KIND_RPC_CLIENT, ], ] ); $span = $scope->getSpan(); $context = $protocol->getContext(); $this->tracer->inject($span->getContext(), TEXT_MAP, $context); $protocol->setContext($context); try { return $next($protocol); } catch (Throwable $e) { if (!$e instanceof RpcResponseException) { $span->setTag(ERROR, $e); } throw $e; } finally { $scope->close(); } } }