PHP code example of wizofgoz / laravel-opentracing
1. Go to this page and download the library: Download wizofgoz/laravel-opentracing library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wizofgoz / laravel-opentracing example snippets
// Create the application.
$app = new \Illuminate\Foundation\Application(realpath(__DIR__ . '/../'));
// Bind important interfaces.
// ...
// Register important providers.
$app->register(\LaravelOpenTracing\TracingServiceProvider::class);
// Enable tracing span context in log messages.
$app->configureMonologUsing(function (\Monolog\Logger $logger) {
$logger->pushProcessor(new \LaravelOpenTracing\Log\Processors\TracingProcessor());
});
// Return the application.
return $app;
function a() {
// We don't care about tracing this specifically.
doSomething();
\LaravelOpenTracing\Facades\Tracing::trace(
'app.do_something_else',
function () {
doSomethingElse();
}
);
}
\LaravelOpenTracing\Facades\Tracing::trace(
'app.do_stuff',
function () {
a();
}
);
$title = 'Make more coffee';
$item = \LaravelOpenTracing\Facades\Tracing::trace(
'todo.store_item',
function () use ($title) {
return \App\Models\TodoListItem::create(['title' => $title]);
},
['tags' => ['title' => $title]]
);
trace(
'todo.store_item',
function () use ($title) {
return \App\Models\TodoListItem::create(['title' => $title]);
},
['tags' => ['title' => $title]]
);
/*
* Resolvers used for generating tags for spans.
*/
'tags' => [
'middleware' => [
'request' => \LaravelOpenTracing\Resolvers\RequestTagResolver::class,
'response' => \LaravelOpenTracing\Resolvers\ResponseTagResolver::class,
],
'query' => \LaravelOpenTracing\Resolvers\QueryTagResolver::class,
],
// Add to job classes
/**
* Get the middleware the job should pass through.
*
* @return array
*/
public function middleware()
{
return [new \LaravelOpenTracing\Jobs\Middleware\Tracing];
}