Version 2.x is a complete rewrite of the existing code base. The public API has been trimmed down to a minimum.
The preferred way of using the SDK is through our "Static API" / global functions.
Here is a simple example to get started:
\Sentry\init(['dsn' => '___PUBLIC_DSN___' ]);
\Sentry\configureScope(function (\Sentry\State\Scope $scope): void {
$scope->setTag('page_locale', 'de-at');
$scope->setUser(['email' => 'john.doe@example.com']);
$scope->setLevel(\Sentry\Severity::warning());
$scope->setExtra('character_name', 'Mighty Fighter');
});
// The following capture call will contain the data from the previous configured Scope
try {
thisFunctionThrows(); // -> throw new \Exception('foo bar');
} catch (\Exception $exception) {
\Sentry\captureException($exception);
}
\Sentry\addBreadcrumb(new Breadcrumb(Breadcrumb::LEVEL_ERROR, Breadcrumb::TYPE_ERROR, 'error_reporting', 'Message'));The call to \Sentry\init() sets up global exception/error handlers and any uncaught error will be sent to Sentry.
Version >= 2.0 conforms to the Unified SDK API.
It has a fundamentally different concept, it's no longer recommended to just use a Client unless you really know what you are doing.
Please visit our docs to get a full overview.
-
The
excludeoption has been removed. -
The
excluded_app_pathoption has been renamed toin_app_exclude -
The
send_callbackoption has been renamed tobefore_send. -
The
nameoption has been renamed toserver_name. -
The
secret_keyoption has been removed. -
The
public_keyoption has been removed. -
The
message_limitoption has been removed. -
The
projectoption has been removed. -
The
severity_mapoption has been removed. -
The
ignore_server_portoption has been removed. -
The
trust_x_forwarded_protooption has been removed. -
The
mb_detect_orderoption has been removed. -
The
traceoption has been removed. -
The
tagsoption has been removed in favour of setting them in the scope. -
The
siteoption has been removed. -
The
extra_dataoption has been removed in favour of setting additional data in the scope. -
The
curl_methodoption has been removed. -
The
curl_pathoption has been removed. -
The
curl_ipv4option has been removed. -
The
curl_ssl_versionoption has been removed. -
The
verify_ssloption has been removed. -
The
ca_certoption has been removed. -
The
proxyoption has been removed in favour of leaving to the user the burden of configuring the HTTP client options using a custom client. -
The
processorsoption has been removed. -
The
processors_optionsoption has been removed. -
The
transportoption has been removed in favour of setting it using the client builder. -
The
install_default_breadcrumb_handlersoption has been removed. -
The
serialize_all_objectoption has been removed. -
The
context_linesoption has been added to configure the number of lines of code context to capture. -
The
max_value_lengthoption has been added to set an upper bound to the length of serialized items. -
The
serveroption has been renamed todsn.
-
All the classes have been renamed and moved around to follow the PSR-4 convention and
finalhave been added where appropriate. -
The
Raven_Autoloaderclass has been removed. To install and use the library you are required to use Composer. -
The
Raven_Utilclass has been removed. -
The
Raven_Compatclass has been removed. -
The
Raven_Utilclass has been removed. -
The
Raven_CurlHandlerclass has been removed. -
The
Raven_TransactionStackclass has been removed. -
The
Raven_Exceptionclass has been removed.
-
The constructor of the
Client(beforeRaven_Client) class has changed its signature and now requires to be passed a configuration object, an instance of a transport and an event factory.Before:
public function __construct($options_or_dsn = null, $options = array()) { // ... }
After:
public function __construct(Options $options, TransportInterface $transport, EventFactoryInterface $eventFactory) { // ... }
The suggested way to create your own instance of the client is to use the provided builder (ClientBuilder) that will take care of instantiating a few dependencies like the PSR-7 factories and the HTTP client.
-
The method
Raven_Client::close_all_children_linkhas been removed and there -
The methods
Raven_Client::getReleaseandRaven_Client::setReleasehave been removed. You should useOptions::getReleaseandOptions::setReleaseinstead.Before:
$client->getRelease(); $client->setRelease(...);
After:
use Sentry\State\Hub; $options = Hub::getCurrent()->getClient()->getOptions(); $options->getRelease(); $options->setRelease(...);
-
The methods
Raven_Client::getEnvironmentandRaven_Client::setEnvironmenthave been removed. You should useOptions::getEnvironmentandOptions::setEnvironmentinstead.Before:
$client->getEnvironment(); $client->setEnvironment(...);
After:
use Sentry\State\Hub; $options = Hub::getCurrent()->getClient()->getOptions(); $options->getEnvironment(); $options->setEnvironment(...);
-
The method
Raven_Client::getInputStreamhas been removed. -
The methods
Raven_Client::getDefaultPrefixesandRaven_Client::setPrefixeshave been removed. You should useOptions::getPrefixesandOptions::setPrefixesinstead.Before:
$client->getPrefixes(); $client->setPrefixes(...);
After:
use Sentry\State\Hub; $options = Hub::getCurrent()->getClient()->getOptions(); $options->getPrefixes(); $options->setPrefixes(...);
-
The methods
Raven_Client::getAppPathandRaven_Client::setAppPathhave been removed. You should useOptions::getProjectRootandOptions::setProjectRootinstead.Before:
$client->getAppPath(); $client->setAppPath(...);
After:
use Sentry\State\Hub; $options = Hub::getCurrent()->getClient()->getOptions(); $options->getProjectRoot(); $options->setProjectRoot(...);
-
The methods
Raven_Client::getExcludedAppPathsandRaven_Client::setExcludedAppPathshave been removed. You should useOptions::getInAppExcludedPathsandOptions::setInAppExcludedPathsinstead.Before:
$client->getExcludedAppPaths(); $client->setExcludedAppPaths(...);
After:
use Sentry\State\Hub; $options = Hub::getCurrent()->getClient()->getOptions(); $options->getExcludedAppPaths(); $options->setExcludedAppPaths(...);
-
The methods
Raven_Client::getSendCallbackandRaven_Client::setSendCallbackhave been removed. You should useOptions::getBeforeSendCallbackandOptions::setBeforeSendCallbackinstead.Before:
$client->getSendCallback(); $client->setSendCallback(...);
After:
use Sentry\State\Hub; $options = Hub::getCurrent()->getClient()->getOptions(); $options->getBeforeSendCallback(); $options->setBeforeSendCallback(...);
-
The method
Raven_Client::getServerEndpointhas been removed. You should useOptions::getDsninstead.Before:
$client->getServerEndpoint();
After:
use Sentry\State\Hub; $options = Hub::getCurrent()->getClient()->getOptions(); $options->getDsn();
-
The methods
Raven_Client::getTransportandRaven_Client::setTransporthave been removed. The transport is now a required dependency of the client and must be passed as required constructor argument. -
The method
Raven_Client::getUserAgenthas been removed. -
The method
Raven_Client::getErrorTypeshas been removed. You should useConfiguration::getErrorTypesinstead.Before:
$client->getErrorTypes();
After:
$client->getConfig()->getErrorTypes();
-
The
Raven_Client::getDefaultProcessorsmethod has been removed. -
The
Raven_Client::setProcessorsFromOptionsmethod has been removed. -
The
Raven_Client::getLastEventIDmethod has been removed. The ID of the last event that was captured is now returned by each of theClient::capture*methods. You can also useHub::getCurrent()->getLastEventId(). -
The
Raven_Client::parseDSNmethod has been removed. -
The
Raven_Client::getLastErrormethod has been removed. -
The
Raven_Client::getIdentmethod has been removed. -
The
Raven_Client::registerShutdownFunctionmethod has been removed. -
The
Raven_Client::is_http_requestmethod has been removed. -
The
Raven_Client::get_http_datamethod has been removed. -
The
Raven_Client::get_user_datamethod has been removed. -
The
Raven_Client::get_extra_datamethod has been removed. -
The
Raven_Client::get_default_datamethod has been removed. -
The
Raven_Client::messagemethod has been removed. -
The
Raven_Client::exceptionmethod has been removed. -
The
Raven_Client::captureQuerymethod has been removed. -
The
Raven_Client::captureMessagemethod has changed its signature.Before:
public function captureMessage($message, $params = array(), $data = array(), $stack = false, $vars = null) { // ... }
After:
public function captureMessage(string $message, ?Severity $level = null, ?Scope $scope = null): ?string { // ... }
-
The
Raven_Client::captureExceptionmethod has changed its signature.Before:
public function captureException($exception, $data = null, $logger = null, $vars = null) { // ... }
After:
public function captureException(\Throwable $exception, ?Scope $scope = null): ?string { // ... }
-
The
Raven_Client::captureLastErrormethod has changed its signature.Before:
public function captureLastError() { // ... }
After:
public function captureLastError(?Scope $scope = null): ?string { // ... }
-
The method
Raven_Client::capturehas been removed. -
The method
Raven_Client::sanitizehas been removed. -
The method
Raven_Client::processhas been removed. -
The method
Raven_Client::sendUnsentErrorshas been removed. -
The method
Raven_Client::encodehas been removed. -
The method
Raven_Client::sendhas been removed. -
The method
Raven_Client::send_remotehas been removed. -
The method
Raven_Client::get_default_ca_certhas been removed. -
The method
Raven_Client::get_curl_optionshas been removed. -
The method
Raven_Client::send_httphas been removed. -
The method
Raven_Client::buildCurlCommandhas been removed. -
The method
Raven_Client::send_http_asynchronous_curl_exechas been removed. -
The method
Raven_Client::send_http_synchronoushas been removed. -
The method
Raven_Client::get_auth_headerhas been removed. -
The method
Raven_Client::getAuthHeaderhas been removed. -
The method
Raven_Client::uuid4has been removed. -
The method
Raven_Client::get_current_urlhas been removed. -
The method
Raven_Client::isHttpshas been removed. -
The method
Raven_Client::translateSeverityhas been removed. -
The method
Raven_Client::registerSeverityMaphas been removed. -
The method
Raven_Client::set_user_datahas been removed. -
The method
Raven_Client::onShutdownhas been removed. -
The method
Raven_Client::createProcessorshas been removed. -
The method
Raven_Client::setProcessorshas been removed. -
The method
Raven_Client::getLastSentryErrorhas been removed. -
The method
Raven_Client::getShutdownFunctionHasBeenSethas been removed. -
The method
Raven_Client::close_curl_resourcehas been removed. -
The method
Raven_Client::setSerializerhas been removed. You can set it using the client builder.Before:
$client = new Raven_Client(); $client->setSerializer(...);
After:
use Sentry\ClientBuilder; $clientBuilder = ClientBuilder::create(); $clientBuilder->setSerializer(...);
-
The method
Raven_Client::setReprSerializerhas been removed. You can set it using the client builder.Before:
$client = new Raven_Client(); $client->setSerializer(...);
After:
use Sentry\ClientBuilder; $clientBuilder = ClientBuilder::create(); $clientBuilder->setRepresentationSerializer(...);
-
The method
Raven_Client::cleanup_php_versionhas been removed. -
The method
Raven_Client::registerDefaultBreadcrumbHandlershas been removed. -
The
Raven_Client::user_contextmethod has been removed. You can set this data in the current active scope.Before:
$client->user_context(array('foo', 'bar'));
After:
use Sentry\State\Hub; use Sentry\State\Scope; Hub::getCurrent()->configureScope(function (Scope $scope): void { $scope->setUser(['email' => 'foo@example.com']); });
-
The
Raven_Client::tags_contextmethod has been removed. You can set this data in the current active scope.Before:
$client->tags_context(array('foo', 'bar'));
After:
use Sentry\State\Hub; use Sentry\State\Scope; Hub::getCurrent()->configureScope(function (Scope $scope): void { $scope->setTag('tag_name', 'tag_value'); });
-
The
Raven_Client::extra_contextmethod has been removed. You can set this data in the current active scope.Before:
$client->extra_context(array('foo' => 'bar'));
After:
use Sentry\State\Hub; use Sentry\State\Scope; Hub::getCurrent()->configureScope(function (Scope $scope): void { $scope->setExtra('extra_key', 'extra_value'); });
-
The method
Raven_Client::installhas been removed. The error handler is registered automatically when using theExceptionListenerIntegrationandErrorListenerIntegrationintegrations (which are enabled by default).
-
The
Raven_Processor_RemoveCookiesProcessorclass has been removed. -
The
Raven_Processor_SanitizeStacktraceProcessorclass has been removed. -
The
Raven_Processor_SanitizeHttpHeadersProcessorclass has been removed. -
The
Raven_Processor_RemoveHttpBodyProcessorclass has been removed. -
The
Raven_Processor_SanitizeDataProcessorclass has been removed. -
The
Raven_Processorclass has been removed.
-
The
Raven_Contextclass has been renamed toContext. -
The
tags,extraanduserproperties of theRaven_Contextclass have been removed. Each instance of the new class represents now a single context type at once.
-
The
Raven_Breadcrumbs_ErrorHandlerclass has been removed. -
The
Raven_Breadcrumbs_MonologHandlerclass has been removed. -
The
Raven_ErrorHandlerclass has been renamed toErrorHandlerand has been madefinal. -
The method
Raven_ErrorHandler::handleErrorhas changed its signature by removing the$contextargument and it has been marked asinternalto make it clear that it should not be called publicly and its method visibility is subject to changes without any notice. -
The methods
Raven_ErrorHandler::registerErrorHandler,Raven_ErrorHandler::registerExceptionHandlerandRaven_ErrorHandler::registerShutdownFunctionhave been removed. You should use theErrorHandler::registermethod instead, but note that it registers all error handlers (error, exception and fatal error) at once and there is no way anymore to only use one of them.Before:
$errorHandler = new Raven_ErrorHandler($client); $errorHandler->registerErrorHandler(); $errorHandler->registerExceptionHandler(); $errorHandler->registerShutdownFunction();
After:
use Sentry\ErrorHandler; ErrorHandler::register(function (\Throwable $exception): void { // ... });
-
The method
Raven_ErrorHandler::handleErrorhas changed its signature by removing the$contextargument and it has been marked asinternalto make it clear that it should not be called publicly and its method visibility is subject to changes without any notice. -
The method
Raven_ErrorHandler::handleFatalErrorhas changed its signature by adding an optional argument named$errorand it has been marked asinternalto make it clear that it should not be called publicly and its method visibility is subject to changes without any notice. -
The method
Raven_ErrorHandler::handleExceptionhas changed its signature by removing the$isErrorand$varsarguments and it has been marked asinternalto make it clear that it should not be called publicly and its method visibility is subject to changes without any notice. -
The method
Raven_ErrorHandler::bitwiseOrhas been removed and there is no replacement for it. -
The method
Raven_ErrorHandler::shouldCaptureFatalErrorhas been removed and there is no replacement for it.
-
The
Raven_Serializerclass has been renamed toSerializerand its constructor changed signature.Before:
public function __construct($mb_detect_order = null, $message_limit = null) { // ... }
After:
public function __construct(int $maxDepth = 3, ?string $mbDetectOrder = null, int $messageLimit = Client::MESSAGE_MAX_LENGTH_LIMIT) { // ... }
-
The
Raven_ReprSerializerclass has been renamed toRepresentationSerializerand its constructor changed signature.Before:
public function __construct($mb_detect_order = null, $message_limit = null) { // ... }
After:
public function __construct(int $maxDepth = 3, ?string $mbDetectOrder = null, int $messageLimit = Client::MESSAGE_MAX_LENGTH_LIMIT) { // ... }