Transports

Sentry PHP is not tied to any specific library that sends HTTP messages. Instead, it uses Httplug to let users choose whichever PSR-7 implementation and HTTP client they want to use.

We recommend that you use the sentry/sdk meta-package which provides our recommend HTTP client:

Copied
composer require sentry/sdk

If you want to use a different HTTP client just install sentry/sentry with the clients you prefer:

Copied
composer require sentry/sentry php-http/curl-client

This will install the library itself along with an HTTP client adapter that uses cURL as the transport method (provided by Httplug and a PSR-7 implementation (provided by Guzzle). You do not have to use those packages if you do not want to. The SDK does not care about which transport method you want to use because it's an implementation detail of your application. You may use any package that provides php-http/async-client-implementation and http-message-implementation.

Transport Classes

Transports are the classes in Sentry PHP that are responsible for communicating with a service in order to deliver an event. There are several types of transports available out-of-the-box, all of which implement the TransportInterface interface;

  • The NullTransport which is used in case you do not define a DSN in the options. It will not send events.
  • The HttpTransport which is the default and will be used when the server is set in the client configuration.

The examples below pretty much replace the \Sentry\init() call. Please also keep in mind that once a Client is initialized with a Transport it cannot be changed.

NullTransport

Although not so common there could be cases in which you don't want to send events at all. The NullTransport transport does this: it simply ignores the events, but report them as sent.

Copied
use Sentry\ClientBuilder;
use Sentry\Transport\NullTransport;
use Sentry\SentrySdk;
use Sentry\Transport\TransportFactoryInterface;

$transportFactory = new class implements TransportFactoryInterface {

    public function create(\Sentry\Options $options): \Sentry\Transport\TransportInterface
    {
        return new NullTransport();
    }
};

$builder = ClientBuilder::create(['dsn' => 'https://examplePublicKey@o0.ingest.sentry.io/0']);
$builder->setTransportFactory($transportFactory);

SentrySdk::getCurrentHub()->bindClient($builder->getClient());
HttpTransport

The HttpTransport sends events over the HTTP protocol using Httplug. The best adapter available is automatically selected when creating a client instance through the client builder, but you can override it using the appropriate methods.

Copied
use Http\Discovery\HttpAsyncClientDiscovery;
use Http\Discovery\Psr17FactoryDiscovery;
use Sentry\Client;
use Sentry\ClientBuilder;
use Sentry\HttpClient\HttpClientFactory;
use Sentry\HttpClient\HttpClientFactoryInterface;
use Sentry\Transport\HttpTransport;
use Sentry\SentrySdk;
use Sentry\Transport\TransportFactoryInterface;

$httpClientFactory = new HttpClientFactory(
    Psr17FactoryDiscovery::findUriFactory(),
    Psr17FactoryDiscovery::findResponseFactory(),
    Psr17FactoryDiscovery::findStreamFactory(),
    HttpAsyncClientDiscovery::find(),
    'sentry.php',
    Client::SDK_VERSION
);

$transportFactory = new class($httpClientFactory) implements TransportFactoryInterface  {
    /**
     * @var HttpClientFactoryInterface
     */
    private $clientFactory;

    public function __construct(HttpClientFactoryInterface $clientFactory)
    {
        $this->clientFactory = $clientFactory;
    }

    public function create(\Sentry\Options $options): \Sentry\Transport\TransportInterface
    {
        return new HttpTransport($options, $this->clientFactory->create($options), Psr17FactoryDiscovery::findStreamFactory(), Psr17FactoryDiscovery::findRequestFactory(), new PayloadSerializer($options));
    }
};


$builder = ClientBuilder::create(['dsn' => 'https://examplePublicKey@o0.ingest.sentry.io/0']);
$builder->setTransportFactory($transportFactory);

SentrySdk::getCurrentHub()->bindClient($builder->getClient());
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").