PHP code example of baraja-core / tracy-sentry-bridge
1. Go to this page and download the library: Download baraja-core/tracy-sentry-bridge 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/ */
baraja-core / tracy-sentry-bridge example snippets
use Baraja\TracySentryBridge\SentryLogger;
public static function boot(): Configurator
{
$configurator = new Configurator;
// Initialize Sentry first
if (\function_exists('\Sentry\init')) {
\Sentry\init([
'dsn' => 'https://[email protected]/project-id',
'attach_stacktrace' => true,
]);
}
// Register the Tracy-Sentry bridge
SentryLogger::register();
return $configurator;
}
use Tracy\Debugger;
use Baraja\TracySentryBridge\SentryLogger;
// Enable Tracy
Debugger::enable();
// Initialize Sentry
\Sentry\init([
'dsn' => 'https://[email protected]/project-id',
]);
// Register the bridge
SentryLogger::register();
// Now all Tracy logs will be sent to Sentry
Debugger::log('Something happened', Debugger::WARNING);
use Tracy\Debugger;
use Baraja\TracySentryBridge\SentryLogger;
$originalLogger = Debugger::getLogger();
$sentryLogger = new SentryLogger($originalLogger);
Debugger::setLogger($sentryLogger);
// Example of how errors are handled internally
public function log(mixed $value, mixed $level = self::INFO): void
{
// Always log to fallback first (guaranteed to work)
$this->fallback->log($value, $level);
try {
// Then attempt Sentry logging
$this->logToSentry($value, $level);
} catch (\Throwable $e) {
// If Sentry fails, log the error locally
$this->fallback->log($e, ILogger::CRITICAL);
}
}