1. Go to this page and download the library: Download webvork/yii-sentry 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/ */
webvork / yii-sentry example snippets
declare(strict_types=1);
use GuzzleHttp\Client as GuzzleClient;
use Http\Adapter\Guzzle7\Client as GuzzleClientAdapter;
use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient;
use HttpSoft\Message\RequestFactory;
use HttpSoft\Message\ResponseFactory;
use HttpSoft\Message\StreamFactory;
use HttpSoft\Message\UriFactory;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\UriFactoryInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Yiisoft\Definitions\Reference;
return [
// HTTP Factories
StreamFactoryInterface::class => StreamFactory::class,
RequestFactoryInterface::class => RequestFactory::class,
LoggerInterface::class => NullLogger::class,
UriFactoryInterface::class => UriFactory::class,
ResponseFactoryInterface::class => ResponseFactory::class,
// HTTP Client
HttpClient::class => GuzzleClient::class,
HttpAsyncClient::class => [
'class' => GuzzleClientAdapter::class,
'__construct()' => [
Reference::to(HttpClient::class),
],
],
];
GuzzleHttp\Client::class => static function (ContainerInterface $container) {
$stack = new HandlerStack();
$stack->setHandler(new CurlHandler());
$factory = $container->get(GuzzleMiddlewareFactory::class);
$middleware = static function (callable $handler) use ($factory): callable {
return $factory->factory($handler);
};
$stack->push($middleware);
return new GuzzleHttp\Client([
'handler' => $stack,
]);
},
'yiisoft/yii-cycle' => [
// DBAL config
'dbal' => [
// SQL query logger. Definition of Psr\Log\LoggerInterface
// For example, \Yiisoft\Yii\Cycle\Logger\StdoutQueryLogger::class
'query-logger' => \Yiisoft\Yii\Sentry\PostgresLoggerDecorator::class,
/**
* ...
* your another db settings
**/
]
]
'middlewares' => [
ErrorCatcher::class,
\Yiisoft\Yii\Sentry\Http\SetRequestIpMiddleware::class, //add this
Router::class,
],
RouteCollectionInterface::class => static function (RouteCollectorInterface $collector) use ($config) {
$collector
->middleware(FormatDataResponse::class)
->middleware(JsonParseMiddleware::class)
->middleware(ExceptionMiddleware::class)
->middleware(\Yiisoft\Yii\Sentry\Tracing\SentryTraceMiddleware::class) // add this
->addGroup(
Group::create('')
->routes(...$config->get('routes'))
);
return new RouteCollection($collector);
},
/** some code with default transaction */
/** commit default transaction and send data to sentry server */
$sentryTraceString = $this->sentryTransactionAdapter->commit();
while ($currentDate <= $endDate) {
$this->sentryTransactionAdapter->begin($sentryTraceString)
->setName('my_heavy_operation/iteration')
->setData(['date' => $currentDate->format('Y-m-d')]);
$this->process($currentDate, $sentryTraceString);
$this->sentryTransactionAdapter->commit();
}
$this->sentryTransactionAdapter->begin($sentryTraceString)
->setName('my_heavy_operation done, terminating application');
/** transaction will commit when application is terminated */
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.