forked from hyperf/tracer
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de74ee4
commit 5d014bc
Showing
2 changed files
with
26 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,21 +9,21 @@ | |
* @contact [email protected] | ||
* @license https://github.com/opencodeco/hyperf-metric/blob/main/LICENSE | ||
*/ | ||
|
||
namespace Jaeger; | ||
|
||
use Hyperf\Context\ApplicationContext; | ||
use Hyperf\Contract\StdoutLoggerInterface; | ||
use Hyperf\Coordinator\Constants; | ||
use Hyperf\Coordinator\CoordinatorManager; | ||
use Hyperf\Coroutine\Coroutine; | ||
use Hyperf\Engine\Channel; | ||
use Psr\Log\LoggerInterface; | ||
use Psr\Log\NullLogger; | ||
use Socket; | ||
use Thrift\Exception\TTransportException; | ||
use Thrift\Transport\TTransport; | ||
use Throwable; | ||
|
||
use function Hyperf\Support\env; | ||
|
||
class ThriftUdpTransport extends TTransport | ||
{ | ||
private null|Socket $socket = null; | ||
|
@@ -33,10 +33,8 @@ class ThriftUdpTransport extends TTransport | |
public function __construct( | ||
private string $host, | ||
private int $port, | ||
private ?LoggerInterface $logger = null | ||
) { | ||
$this->logger = $logger ?? new NullLogger(); | ||
} | ||
private LoggerInterface $logger | ||
) {} | ||
|
||
/** | ||
* Whether this transport is open. | ||
|
@@ -120,9 +118,17 @@ public function write($buf) | |
$this->loop(); | ||
} | ||
|
||
$this->chan->push(function () use ($buf) { | ||
$pushed = $this->chan->push(function () use ($buf) { | ||
$this->doWrite($buf); | ||
}); | ||
}, (float) env('TRACE_THRIFT_UDP_TIMEOUT', 0.1)); | ||
|
||
if (! $pushed) { | ||
$this->logger->error('ThriftUdpTransport error:' . match (true) { | ||
$this->chan->isTimeout() => 'Channel Timeout', | ||
$this->chan->isClosing() => 'Channel Close', | ||
default => 'Channel Error' | ||
}); | ||
} | ||
} | ||
|
||
private function doOpen(): void | ||
|
@@ -151,7 +157,14 @@ private function loop(): void | |
$this->chan = new Channel(1); | ||
Coroutine::create(function () { | ||
while (true) { | ||
$this->doOpen(); | ||
try { | ||
$this->doOpen(); | ||
} catch (Throwable $e) { | ||
$this->chan->close(); | ||
$this->chan = null; | ||
throw $e; | ||
} | ||
|
||
while (true) { | ||
try { | ||
$closure = $this->chan->pop(); | ||
|
@@ -160,13 +173,7 @@ private function loop(): void | |
} | ||
$closure->call($this); | ||
} catch (Throwable $e) { | ||
if (ApplicationContext::hasContainer()) { | ||
if (ApplicationContext::getContainer()->has(StdoutLoggerInterface::class)) { | ||
ApplicationContext::getContainer() | ||
->get(StdoutLoggerInterface::class) | ||
->error('ThriftUdpTransport error:' . $e->getMessage()); | ||
} | ||
} | ||
$this->logger->error('ThriftUdpTransport error:' . $e->getMessage()); | ||
@socket_close($this->socket); | ||
$this->socket = null; | ||
break; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
* @contact [email protected] | ||
* @license https://github.com/opencodeco/hyperf-metric/blob/main/LICENSE | ||
*/ | ||
|
||
namespace Hyperf\Tracer\Adapter; | ||
|
||
use Hyperf\Contract\ConfigInterface; | ||
|
@@ -26,9 +27,7 @@ class JaegerTracerFactory implements NamedFactoryInterface | |
|
||
private string $name = ''; | ||
|
||
public function __construct(private ConfigInterface $config, private ?LoggerInterface $logger = null, private ?CacheItemPoolInterface $cache = null) | ||
{ | ||
} | ||
public function __construct(private ConfigInterface $config, private LoggerInterface $logger, private ?CacheItemPoolInterface $cache = null) {} | ||
|
||
public function make(string $name): Tracer | ||
{ | ||
|