1. Go to this page and download the library: Download compono-kit/sentry-client 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/ */
use ComponoKit\SentryClient\Interfaces\InformsSentry;
class OrderService
{
public function __construct(private InformsSentry $sentry) {}
public function place(Order $order): void
{
try {
// ...
} catch (\Throwable $exception) {
$this->sentry->captureException($exception);
throw $exception;
}
}
}
use ComponoKit\SentryClient\NullSentryClient;
$service = new OrderService(new NullSentryClient());
use ComponoKit\SentryClient\Models\Types\Severity;
$client->captureException($exception);
// with severity
$client->captureException($exception, Severity::fatal());
use ComponoKit\SentryClient\Models\Types\Message;
use ComponoKit\SentryClient\Models\Types\Severity;
$client->captureMessage(new Message('Queue depth exceeded threshold'), Severity::warning());
@file_get_contents('/missing/file');
$client->captureLastError(); // severity defaults to error
$client->captureLastError(Severity::warning());
use ComponoKit\SentryClient\Models\Tags;
$client->useTags(Tags::fromKeyValueArray([
'app' => 'checkout-service',
'version' => '2.1.0',
]));
use ComponoKit\SentryClient\Models\Context;
use ComponoKit\SentryClient\Models\ContextEntry;
use ComponoKit\SentryClient\Models\ContextGroup;
$context = new Context([
new ContextGroup('order', [
new ContextEntry('id', '#1042'),
new ContextEntry('amount', '149.90 EUR'),
]),
]);
$client->captureException($exception, Severity::error(), $context);
$client->captureMessage(new Message('Payment declined'), Severity::warning(), $context);
use ComponoKit\SentryClient\Models\Fingerprint;
$client->captureException(
$exception,
Severity::error(),
null,
new Fingerprint('PaymentService', 'timeout'),
);
use ComponoKit\SentryClient\Interfaces\ConfiguresSentryClient;
use ComponoKit\SentryClient\Models\Types\Dsn;
use ComponoKit\SentryClient\Models\Types\Environment;
use ComponoKit\SentryClient\Models\Types\Release;
class EnvSentryConfig implements ConfiguresSentryClient
{
public function getDsn(): Dsn { return new Dsn($_ENV['SENTRY_DSN']); }
public function getEnvironment(): Environment { return new Environment($_ENV['APP_ENV']); }
public function getRelease(): Release { return new Release($_ENV['APP_VERSION']); }
public function getErrorReporting(): int { return E_ALL; }
public function shouldDisplayErrors(): bool { return false; }
public function getExtraOptions(): array { return []; }
}
new SentryClientConfig([
// ...traces_sample_rate' => 0.2,
'before_send' => function (\Sentry\Event $event): ?\Sentry\Event {
// drop events from bots
if (str_contains((string) $event->getRequest()?->getHeaders()['User-Agent'] ?? '', 'bot')) {
return null;
}
return $event;
},
],
]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.