composer require sitmpcz/sentry-logger
-
run Sentry, register your project and get client DSN url
-
in config neon add in section parameters
sentry_url: https://something@abc.sentry.io/someproject- in config neon add in section services
a) simple version
tracy.logger: Sitmpcz\SentryLogger(%sentry_url%)b) extended version - use additional attributes (example with release attribute)
tracy.logger:
create: Sitmpcz\SentryLogger(%sentry_url%)
setup:
- setAttribute('release', 'myApp@1.8.0')
- setAttribute('environment', 'production')Using DI load Sentry Logger Example for presenter
/** @var \Sitmpcz\SentryLogger @inject */
public \Sitmpcz\SentryLogger $sentryLogger;Then you can write error to Sentry manually:
$this->sentryLogger->log(new \Exception("test sentry"),\Tracy\ILogger::ERROR);If you want to write to log manually, you can use Tracy\Debugger::log too, but you must specify higher priority (Napr CRITICAL) Example
\Tracy\Debugger::log("Test zapistu do logu",\Tracy\ILogger::CRITICAL);Example for Nette - BasePresenter:
private ?object $sentryPerformance = null;
function startup(): void
{
parent::startup();
$this->sentryPerformance = Sitmpcz\SentryPerformance::startPerformaceMonitoring($this->getName(), $this->getAction());
}
function shutdown(Nette\Application\Response $response): void
{
parent::shutdown($response);
if ($this->sentryPerformance) Sitmpcz\SentryPerformance::endPerformaceMonitoring($this->sentryPerformance);
}