Skip to content

Commit

Permalink
Allowed output log when an exception occurs (#6111)
Browse files Browse the repository at this point in the history
  • Loading branch information
huangdijia authored Aug 31, 2023
1 parent b599685 commit f8e7986
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/Adapter/Reporter/HttpClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Hyperf\Tracer\Adapter\Reporter;

use Closure;
use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\Coordinator\Constants;
use Hyperf\Coordinator\CoordinatorManager;
use Hyperf\Engine\Channel;
Expand All @@ -28,7 +27,7 @@ class HttpClientFactory implements ClientFactoryInterface

protected int $channelSize = 65535;

public function __construct(private ClientFactory $clientFactory, protected StdoutLoggerInterface $logger)
public function __construct(private ClientFactory $clientFactory)
{
}

Expand Down Expand Up @@ -58,7 +57,7 @@ public function build(array $options): callable
'no_aspect' => true,
]);
$statusCode = $response->getStatusCode();
if ($statusCode !== 202) {
if (! in_array($statusCode, [200, 202])) {
throw new RuntimeException(
sprintf('Reporting of spans failed, status code %d', $statusCode)
);
Expand Down
16 changes: 11 additions & 5 deletions src/Adapter/Reporter/ReporterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*/
namespace Hyperf\Tracer\Adapter\Reporter;

use Hyperf\Contract\StdoutLoggerInterface;
use Psr\Container\ContainerInterface;
use RuntimeException;
use Zipkin\Reporter;

Expand All @@ -19,7 +21,7 @@
class ReporterFactory
{
public function __construct(
private HttpClientFactory $httpClientFactory,
private ContainerInterface $container
) {
}

Expand All @@ -28,10 +30,6 @@ public function make(array $option = []): Reporter
$class = $option['class'] ?? '';
$constructor = $option['constructor'] ?? [];

if ($class === \Zipkin\Reporters\Http::class) {
$option['constructor']['requesterFactory'] = $this->httpClientFactory;
}

if (! class_exists($class)) {
throw new RuntimeException(sprintf('Class %s is not exists.', $class));
}
Expand All @@ -40,6 +38,14 @@ public function make(array $option = []): Reporter
throw new RuntimeException('Unsupported reporter.');
}

if ($class === \Zipkin\Reporters\Http::class) {
$constructor['requesterFactory'] = $this->container->get(HttpClientFactory::class);
}

if ($this->container->has(StdoutLoggerInterface::class)) {
$constructor['logger'] = $this->container->get(StdoutLoggerInterface::class);
}

return make($class, $constructor);
}
}

0 comments on commit f8e7986

Please sign in to comment.