Skip to content

Commit

Permalink
Added default config of noop driver for hyperf/opentracing. (#6550)
Browse files Browse the repository at this point in the history
  • Loading branch information
weslenteche committed Feb 24, 2024
1 parent 9168a08 commit 149f64a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
4 changes: 4 additions & 0 deletions publish/opentracing.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use function Hyperf\Support\env;

return [
// To disable hyperf/opentracing temporarily, set default driver to noop.
'default' => env('TRACER_DRIVER', 'zipkin'),
'enable' => [
'coroutine' => env('TRACER_ENABLE_COROUTINE', false),
Expand Down Expand Up @@ -88,6 +89,9 @@
],
],
],
'noop' => [
'driver' => Hyperf\Tracer\Adapter\NoOpTracerFactory::class,
],
],
'tags' => [
'http_client' => [
Expand Down
24 changes: 24 additions & 0 deletions src/Adapter/NoOpTracerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Tracer\Adapter;

use Hyperf\Tracer\Contract\NamedFactoryInterface;
use OpenTracing\NoopTracer;
use OpenTracing\Tracer;

class NoOpTracerFactory implements NamedFactoryInterface
{
public function make(string $name): Tracer
{
return new NoopTracer();
}
}
42 changes: 42 additions & 0 deletions tests/TracerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public function testZipkinFactory()
'options' => [
],
],
'noop' => [
'driver' => \Hyperf\Tracer\Adapter\NoOpTracerFactory::class,
],
],
],
]);
Expand Down Expand Up @@ -123,6 +126,9 @@ public function testJaegerFactory()
'options' => [
],
],
'noop' => [
'driver' => \Hyperf\Tracer\Adapter\NoOpTracerFactory::class,
],
],
],
]);
Expand All @@ -132,6 +138,42 @@ public function testJaegerFactory()
$this->assertInstanceOf(\Jaeger\Tracer::class, $factory($container));
}

public function testNoOpFactory()
{
$config = new Config([
'opentracing' => [
'default' => 'noop',
'enable' => [
],
'tracer' => [
'zipkin' => [
'driver' => \Hyperf\Tracer\Adapter\ZipkinTracerFactory::class,
'app' => [
'name' => 'skeleton',
// Hyperf will detect the system info automatically as the value if ipv4, ipv6, port is null
'ipv4' => '127.0.0.1',
'ipv6' => null,
'port' => 9501,
],
'options' => [
],
'sampler' => BinarySampler::createAsAlwaysSample(),
],
'jaeger' => [
'driver' => \Hyperf\Tracer\Adapter\JaegerTracerFactory::class,
'name' => 'skeleton',
'options' => [
],
],
],
],
]);
$container = $this->getContainer($config);
$factory = new TracerFactory();

$this->assertInstanceOf(\OpenTracing\NoopTracer::class, $factory($container));
}

protected function getContainer($config)
{
$container = Mockery::mock(Container::class);
Expand Down

0 comments on commit 149f64a

Please sign in to comment.