forked from nishangupta/Mart
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Showing
21 changed files
with
1,041 additions
and
449 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace App\Tracing; | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
use OpenTracing\Tracer as OpenTracingTracer; | ||
|
||
class Tracer extends Facade | ||
{ | ||
protected static function getFacadeAccessor() | ||
{ | ||
return OpenTracingTracer::class; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace App\Tracing; | ||
|
||
use Illuminate\Foundation\Http\Events\RequestHandled; | ||
use Illuminate\Support\Facades\Event; | ||
use Illuminate\Support\Facades\Request; | ||
use Illuminate\Support\ServiceProvider; | ||
use Jaeger\Config; | ||
use Jaeger\Tracer as JaegerTracer; | ||
use OpenTracing\Tracer; | ||
use Psr\Log\LoggerInterface; | ||
|
||
use const Jaeger\SAMPLER_TYPE_CONST; | ||
|
||
class TracingServiceProvider extends ServiceProvider | ||
{ | ||
public function register(): void | ||
{ | ||
$this->app->singleton(JaegerTracer::class, function () { | ||
$config = new Config([ | ||
'sampler' => [ | ||
'type' => SAMPLER_TYPE_CONST, | ||
'param' => true, | ||
], | ||
|
||
'logging' => true, | ||
|
||
'local_agent' => [ | ||
'reporting_host' => 'localhost', | ||
// You can override port by setting local_agent.reporting_port value | ||
'reporting_port' => 6832, | ||
], | ||
|
||
// Different ways to send data to Jaeger. Config::ZIPKIN_OVER_COMPACT - default): | ||
'dispatch_mode' => Config::JAEGER_OVER_BINARY_UDP, | ||
], 'Mart Web Server', $this->app->make(LoggerInterface::class)); | ||
|
||
return $config->initializeTracer(); | ||
}); | ||
|
||
$this->app->bind(Tracer::class, JaegerTracer::class); | ||
} | ||
|
||
public function boot(Tracer $tracer): void | ||
{ | ||
$scope = $tracer->startActiveSpan( | ||
Request::getMethod() . ' ' . Request::getUri(), | ||
); | ||
|
||
Event::listen(RequestHandled::class, function () use ($scope, $tracer) { | ||
$scope->close(); | ||
$tracer->flush(); | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.