sitmpcz/sentry-logger

There is no license information available for the latest version (v1.6.1) of this package.

v1.6.1 2024-02-26 11:45 UTC

This package is auto-updated.

Last update: 2025-04-26 14:07:11 UTC


README

Install

composer require sitmpcz/sentry-logger

Sentry event logger usage

  1. run Sentry, register your project and get client DSN url

  2. in config neon add in section parameters

sentry_url: https://something@abc.sentry.io/someproject
  1. 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')

Manual write to Sentry Error log

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);

Sentry performance usage (optional)

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);
}