Skip to content

Commit

Permalink
增加noop驱动
Browse files Browse the repository at this point in the history
  • Loading branch information
yunwuxin committed Dec 31, 2022
1 parent 7f6fa8d commit b9a3913
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
5 changes: 4 additions & 1 deletion config/tracing.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php
return [
'default' => 'zipkin',
'default' => 'noop',
'tracers' => [
'noop' => [
'type' => 'noop',
],
'jaeger' => [
'type' => 'jaeger',
'endpoint' => 'http://localhost:9411/api/traces',
Expand Down
5 changes: 3 additions & 2 deletions src/tracer/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
use think\tracing\InteractsWithTracer;
use think\tracing\reporter\AsyncReporter;
use think\tracing\reporter\RedisReporter;
use OpenTracing\Tracer as OTTracer;

abstract class Driver implements \OpenTracing\Tracer
abstract class Driver implements OTTracer
{
use InteractsWithTracer;

Expand All @@ -31,7 +32,7 @@ public function setRedisReporter(RedisReporter $reporter)

abstract protected function createReporter();

abstract protected function createTracer();
abstract protected function createTracer(): OTTracer;

protected function tracer()
{
Expand Down
3 changes: 2 additions & 1 deletion src/tracer/Jaeger.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use think\helper\Arr;
use Thrift\Protocol\TCompactProtocol;
use Thrift\Transport\TBufferedTransport;
use OpenTracing\Tracer as OTTracer;

class Jaeger extends Driver
{
Expand All @@ -32,7 +33,7 @@ protected function createReporter()
return new RemoteReporter($sender);
}

protected function createTracer()
protected function createTracer(): OTTracer
{
$reporter = $this->createReporter();
$sampler = new ConstSampler();
Expand Down
20 changes: 20 additions & 0 deletions src/tracer/Noop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace think\tracing\tracer;

use OpenTracing\NoopTracer;
use OpenTracing\Tracer as OTTracer;

class Noop extends Driver
{

protected function createReporter()
{
return null;
}

protected function createTracer(): OTTracer
{
return new NoopTracer();
}
}
3 changes: 2 additions & 1 deletion src/tracer/Zipkin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace think\tracing\tracer;

use OpenTracing\Tracer as OTTracer;
use think\helper\Arr;
use think\tracing\reporter\ZipkinReporter;
use Zipkin\Endpoint;
Expand All @@ -25,7 +26,7 @@ protected function createReporter()
return new Http($options);
}

protected function createTracer()
protected function createTracer(): OTTracer
{
$reporter = $this->createReporter();

Expand Down

0 comments on commit b9a3913

Please # to comment.