This component contains the instrumentation for the standard PSR15 HTTP servers.
Before using this library, make sure the interfaces for PSR15 HTTP server are installed:
composer require psr/http-server-middleware
In this example we use fast-route and request-handler middlewares but any HTTP server middleware supporting PSR15 middlewares will work.
use Zipkin\Instrumentation\Http\Server\Psr15\Middleware as ZipkinMiddleware;
use Zipkin\Instrumentation\Http\Server\HttpServerTracing;
// Create the routing dispatcher
$fastRouteDispatcher = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $r) {
$r->get('/hello/{name}', HelloWorldController::class);
});
// Creates tracing component
$tracing = TracingBuilder::create()
->havingLocalServiceName('my_service')
->build();
$httpClientTracing = new HttpServerTracing($tracing);
$dispatcher = new Dispatcher([
new Middlewares\FastRoute($fastRouteDispatcher),
// ...
new ZipkinMiddleware($serverTracing),
new Middlewares\RequestHandler(),
]);
$response = $dispatcher->dispatch(new ServerRequest('/hello/world'));