/** * Report an error at this line of code, with a complete stack trace. * * @param string $message * @param \Exception|\Throwable $exception * * @return $this */ public function noticeError($message, $exception) { if ($this->active) { newrelic_notice_error($message, $exception); } return $this; }
/** * Write the log message to the file path set * in this writer. */ public function _write($event) { //Ignore Exceptions New Relic Catches these on it's own if (preg_match('/Uncaught ([A-Za-z]*)Exception: /', trim($errstr)) == true) { return; } $errno = $event['message']['errno']; $errstr = $event['message']['errstr']; $errfile = $event['message']['errfile']; $errline = $event['message']['errline']; $errcontext = $event['message']['errcontext']; switch ($event['priorityName']) { case 'ERR': $errtype = 'Error'; break; case 'WARN': $errtype = 'Warning'; break; case 'NOTICE': $errtype = 'Notice'; break; default: $errtype = $event['priorityName']; } $relfile = Director::makeRelative($errfile); if ($relfile && $relfile[0] == '/') { $relfile = substr($relfile, 1); } //If it's not an exception notice the error newrelic_notice_error($errno, "[{$errtype}] {$errstr} in {$relfile} line {$errline}", $errfile, $errline, $errcontext); }
/** * @param \Nette\Application\Application $application * @param \Exception|\Throwable $e */ public function __invoke(Application $application, $e) { if ($e instanceof \Nette\Application\BadRequestException) { // skip 4xx errors return; } newrelic_notice_error($e->getMessage(), $e); }
public function onError(Application $app, \Exception $e) { if ($e instanceof BadRequestException) { return; // ignore } newrelic_notice_error($e->getMessage(), $e); }
public function onError(Application $app, \Exception $e) { if (!extension_loaded('newrelic')) { return; } if ($e instanceof Nette\Application\BadRequestException) { return; } newrelic_notice_error($e->getMessage(), $e); }
protected function log($message, $type = 'notice', $exception = null) { $typeMap = array('error' => E_USER_ERROR, 'warning' => E_USER_WARNING, 'notice' => E_USER_NOTICE); file_put_contents(dirname(__FILE__) . '/../../../../error.log', $message . $exception, FILE_APPEND); error_log($message, $typeMap[$type]); if (extension_loaded('newrelic')) { newrelic_notice_error($message, $exception); } return $this; }
/** * Handles a given exception * * @param Throwable|Exception $exception A Throwable or Exception instance * @return void */ public function handle($exception) { $exception = call_user_func($this->config('exceptionCallback'), $exception); if (!$exception) { return; } if (extension_loaded('newrelic')) { newrelic_notice_error($exception); } }
public function log($message, $priority = self::INFO) { $res = parent::log($message, $priority); if ($priority === self::ERROR || $priority === self::CRITICAL) { if (is_array($message)) { $message = implode(' ', $message); } newrelic_notice_error($message); } return $res; }
/** * {@inheritdoc} */ public function noticeError($message, $exception = null) { if (!$this->extensionLoaded()) { return; } if (!$exception) { newrelic_notice_error($message); } else { newrelic_notice_error($message, $exception); } }
/** * Static since a store config exception (caused by a module config error) cannot call magento's model objects. * If a store config exception occurs, the exception class logs it drect. * * @param type $e */ public static function pushEvent($e, $setAppName = true) { if (extension_loaded('newrelic')) { $message = $e->getMessage(); $message = empty($message) ? get_class($e) : $message; if ($setAppName) { Mage::Helper('newrelic')->setAppName(); } newrelic_notice_error($message, $e); } }
/** * @param string|array $message * @param string $priority * @return string logged error filename */ public function log($message, $priority = NULL) { $exceptionFile = $this->oldLogger->log($message, $priority); if (in_array($priority, $this->logLevels)) { if (is_array($message)) { $message = implode(' ', $message); } newrelic_notice_error($message); } return $exceptionFile; }
/** * Record a log event to new relic * * @param type $event * @return type */ public function recordEvent($event) { if (extension_loaded('newrelic')) { if (Mage::getStoreConfig('newrelic/settings/record_system_log') && !Mage::helper('newrelic')->ignoreMessage($event['message'], 'system_log')) { if ($event['priorityName'] == 'DEBUG' && Mage::getStoreConfig('newrelic/settings/system_log_ignore_debug')) { return; } Mage::Helper('newrelic')->setAppName(); newrelic_notice_error($this->_eventType . ': [' . $event['priorityName'] . '] ' . $event['message']); } } }
public function log($message, $priority = self::INFO) { $res = parent::log($message, $priority); // pouze zprávy, které jsou označené jako chyby if ($priority === self::ERROR || $priority === self::CRITICAL) { if (is_array($message)) { $message = implode(' ', $message); } newrelic_notice_error($message); } return $res; }
public function onError(Application $app, \Exception $e) { if (!extension_loaded('newrelic')) { return; } if ($e instanceof Nette\Application\BadRequestException) { return; // skip } // logovat pouze výjimky, které se dostanou až k uživateli jako chyba 500 newrelic_notice_error($e->getMessage(), $e); }
public function log($message, $priority = self::INFO) { if (!extension_loaded('newrelic')) { return; } if ($priority === self::ERROR || $priority === self::CRITICAL) { if (is_array($message)) { $message = implode(' ', $message); } newrelic_notice_error($message); } }
/** * @param array $record */ private function noticeException(array &$record) { if (!empty($record['exception']) && $record['exception'] instanceof \Exception) { newrelic_notice_error($record['exception']->getMessage(), $record['exception']); unset($record['exception']); } elseif (!empty($record['context']['exception']) && $record['context']['exception'] instanceof \Exception) { newrelic_notice_error($record['context']['exception']->getMessage(), $record['context']['exception']); unset($record['context']['exception']); } elseif (!empty($record['extra']['exception']) && $record['extra']['exception'] instanceof \Exception) { newrelic_notice_error($record['extra']['exception']->getMessage(), $record['extra']['exception']); unset($record['extra']['exception']); } elseif (!empty($record['message'])) { newrelic_notice_error($record['message']); } }
/** * @param array $record * @throws Exception\RuntimeException */ public function write(array $record) { if (!$this->isEnabled()) { throw new Exception\RuntimeException('The newrelic PHP extension is required to use the NewRelicHandler'); } if ($name = $this->getName($record['context'])) { $this->setName($name); } if (isset($record['context']['exception']) && $record['context']['exception'] instanceof \Exception) { newrelic_notice_error($record['message'], $record['context']['exception']); unset($record['context']['exception']); } else { newrelic_notice_error($record['message']); } foreach ($record['context'] as $key => $parameter) { newrelic_add_custom_parameter($key, $parameter); } }
public function onKernelException(GetResponseForExceptionEvent $event) { if ($this->thrownAnError) { return; // do not throw more than one error, since it is going to be overwritten } $exception = $event->getException(); if ($exception instanceof HttpExceptionInterface) { return; // we should only log non-http exceptions } if (!extension_loaded('newrelic')) { return; // the extension is not loaded } newrelic_notice_error(null, $exception); $this->thrownAnError = true; }
public function handle($type, $message, $file, $line, $extra) { if ($this->canIgnoreError($type)) { return; } // Symfony HttpExceptionInterface status code filtering if (isset($extra['code']) && $extra['code'] < $this->httpExceptionCodeLevel) { return; } // Format message for better readability in NewRelic dashboard $formattedMessage = sprintf('%s: %s in %s line %s', $this->getDisplayName($extra), $message, $file, $line); if (isset($extra['exception'])) { newrelic_notice_error($formattedMessage, $extra['exception']); } else { newrelic_notice_error($formattedMessage); } return !$this->getCallNextHandler(); }
/** * Instantiate IPN model and pass IPN request to it */ public function indexAction() { if (!$this->getRequest()->isPost()) { return; } try { $data = $this->getRequest()->getPost(); Mage::getModel('paypal/ipn')->processIpnRequest($data, new Varien_Http_Adapter_Curl()); } catch (Exception $e) { if (function_exists('newrelic_notice_error')) { /** * Adds error to New Relic * @link https://newrelic.com/docs/php/the-php-api#api-notice-error */ newrelic_notice_error($e->getMessage(), $e); } Mage::logException($e); $this->getResponse()->setHttpResponseCode(500); } }
/** * {@inheritdoc} */ public function process(Message $message, array $options) { if ($this->extensionLoaded) { newrelic_start_transaction($options['new_relic_app_name'], $options['new_relic_license']); newrelic_name_transaction($options['new_relic_transaction_name']); newrelic_background_job(true); } try { $result = $this->processor->process($message, $options); } catch (\Exception $e) { if ($this->extensionLoaded) { newrelic_notice_error(null, $e); newrelic_end_transaction(); } throw $e; } if ($this->extensionLoaded) { newrelic_end_transaction(); } return $result; }
/** * {@inheritDoc} */ protected function write(array $record) { if (!$this->isNewRelicEnabled()) { throw new ehough_epilog_handler_MissingExtensionException('The newrelic PHP extension is required to use the NewRelicHandler'); } if ($appName = $this->getAppName($record['context'])) { $this->setNewRelicAppName($appName); } if (isset($record['context']['exception']) && $record['context']['exception'] instanceof Exception) { newrelic_notice_error($record['message'], $record['context']['exception']); unset($record['context']['exception']); } else { newrelic_notice_error($record['message']); } foreach ($record['context'] as $key => $parameter) { newrelic_add_custom_parameter($key, $parameter); } foreach ($record['extra'] as $key => $parameter) { newrelic_add_custom_parameter($key, $parameter); } }
function wp_die($message, $title = '', $args = array()) { $passedmessage = $message; if (function_exists('is_wp_error') && is_wp_error($message)) { $errors = $message->get_error_messages(); switch (count($errors)) { case 0: $message = ''; break; case 1: $message = "<p>{$errors[0]}</p>"; break; default: $message = "<ul>\n\t\t<li>" . join("</li>\n\t\t<li>", $errors) . "</li>\n\t</ul>"; break; } } newrelic_notice_error($title . ' ' . $message); if (function_exists('_default_wp_die_handler')) { _default_wp_die_handler($passedmessage, $title = '', $args); } else { die($message); } }
/** * @param Exception $exception */ public function setNoticeError(Exception $exception) { if ($this->getEnabled()) { newrelic_notice_error($exception->getMessage(), $exception); } }
public static function handleException($e) { if (extension_loaded('newrelic')) { newrelic_notice_error(null, $e); } // respond $report = sprintf("<h1>Unhandled Exception: %s</h1>\n", get_class($e)); $report .= sprintf("<h2>Message</h2>\n<pre>%s</pre>\n", htmlspecialchars($e->getMessage())); $report .= sprintf("<h2>Code</h2>\n<pre>%s</pre>\n", htmlspecialchars($e->getCode())); $report .= static::_getRequestReport(); $report .= sprintf("<h2>Backtrace</h2>\n<pre>%s</pre>\n", htmlspecialchars(print_r(debug_backtrace(), true))); if (!headers_sent()) { header('Status: 500 Internal Server Error'); } if (static::$debug) { die($report); } else { if (class_exists('Email')) { Email::send(static::$webmasterEmail, 'Unhandled exception on ' . static::$hostname, $report); } die('A problem has occurred and this request could not be handled, the webmaster has been sent a diagnostic report.'); } }
public function exception(\Exception $e) { return newrelic_notice_error($e->getMessage(), $e); }
public function start($id = "Some Random Process") { // If the __construct() test failed, retest now. // @TODO fix for PHP7 // if (!self::$have_ticks) { // $this->setup_ticks(); // } $pid = pcntl_fork(); if ($pid == -1) { die("Fork you!!"); } elseif ($pid) { $this->pids[$pid] = $id; $this->logger->debug("Announcing new process w/ pid ({$pid}): {$id}"); if (count(array_keys($this->pids)) >= $this->max_processes) { // wait for child to finish so we can start another. // PHP doesn't dispatch signals while we're waiting in pcntl_wait(). // All signals are queued up, and dispatched when it exits. // But that doesn't work for ForkManager, because I need to receive // the signal to start killing child processes... chicken and egg... // Instead, poll pcntl_wait() instead of blocking. If nothing // exitted, and we're still supposed to run, poll while ($this->alive()) { /** * @var $status int is a reference to a variable that stores $? * plus some more crap for the child that exitted */ $status = 0; $childpid = pcntl_wait($status, WNOHANG); // If nothing happened, or an error happened, send out signals and delay if ($childpid === 0) { pcntl_signal_dispatch(); time_nanosleep(0, 500000000); // Sleep for 0.5s } elseif ($childpid === -1) { // Go ahead and dispatch messages and sleep. We don't want to busy wait. pcntl_signal_dispatch(); time_nanosleep(0, 500000000); // Sleep for 0.5s } else { if (pcntl_wifexited($status)) { $code = pcntl_wexitstatus($status); if ($code != 0) { $msg = "Child exited abnormally with code {$code}"; if (extension_loaded('newrelic')) { newrelic_notice_error($msg); } $this->logger->critical("Process exited abnormally", ['process' => $id, 'code' => $code]); } } // If this is a known child, exit the loop, so we can re-spawn // If the child is not known, don't spawn a new child $respawn_child = array_key_exists($childpid, $this->pids); $this->reap($childpid); if ($respawn_child) { break; } } } } } else { //child ... // Setup signal handlers, if any foreach (self::$trapped_signals as $signo) { if (is_null($this->child_handler)) { pcntl_signal($signo, function ($signo) { exit($signo); }); } else { pcntl_signal($signo, $this->child_handler); } } //code should be in the caller } return $pid; }
/** * Added in v. 2.6 of the New Relic Agent. * * @link https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-api#api-notice-error * * @param string $message * @param Exception $exception */ public function noticeError($message, Exception $exception = null) { if ($this->isLoaded()) { newrelic_notice_error($message, $exception); } }
public function warning($message, Exception $e) { if (extension_loaded('newrelic')) { newrelic_notice_error($message, $e); } }
public function notify(atsumi_Observable $sender, atsumi_EventArgs $args) { if (extension_loaded('newrelic')) { newrelic_notice_error('', $args->exception); } }