class EventSubscriber implements SubscriberInterface

This class handles integration with GuzzleHttp 5. Attaching this EventSubscriber to your Guzzle client, will enable distrubted tracing by passing along the trace context header and will also create trace spans for all outgoing requests.

Example:

use GuzzleHttp\Client;
use OpenCensus\Trace\Integrations\Guzzle\EventSubscriber;

$client = new Client();
$subscriber = new EventSubscriber();
$client->getEmitter()->attach($subscriber);

Methods

__construct(PropagatorInterface $propagator = null)

Create a new Guzzle event listener that creates trace spans and propagates the current trace context to the downstream request.

array
getEvents()

Returns an array of event names this subscriber wants to listen to.

onBefore(BeforeEvent $event)

Handler for the BeforeEvent request lifecycle event. Adds the current trace context as the trace context header. Also starts a span representing this outgoing http request.

onEnd(EndEvent $event)

Handler for the EndEvent request lifecycle event. Ends the current span which should be the span started in the BeforeEvent handler.

Details

at line 62
__construct(PropagatorInterface $propagator = null)

Create a new Guzzle event listener that creates trace spans and propagates the current trace context to the downstream request.

Parameters

PropagatorInterface $propagator Interface responsible for serializing trace context

at line 72
array getEvents()

Returns an array of event names this subscriber wants to listen to.

Return Value

array

at line 86
onBefore(BeforeEvent $event)

Handler for the BeforeEvent request lifecycle event. Adds the current trace context as the trace context header. Also starts a span representing this outgoing http request.

Parameters

BeforeEvent $event Event object emitted before a request is sent

at line 110
onEnd(EndEvent $event)

Handler for the EndEvent request lifecycle event. Ends the current span which should be the span started in the BeforeEvent handler.

Parameters

EndEvent $event A terminal event that is emitted when a request transaction has ended