diff --git a/Site/SiteApplication.php b/Site/SiteApplication.php index e517a338..7a0d2a7e 100644 --- a/Site/SiteApplication.php +++ b/Site/SiteApplication.php @@ -113,6 +113,11 @@ abstract class SiteApplication extends SiteObject */ protected $sentry_client; + /** + * @var SiteSentryReportDialog + */ + protected $sentry_report_dialog; + // }}} // {{{ public function __construct() @@ -468,6 +473,10 @@ protected function setUpSentryErrorHandling(SiteConfigModule $config) $error_handler->registerShutdownFunction(); $this->sentry_client = $client; + $this->sentry_report_dialog = new SiteSentryReportDialog( + $client, + $config->sentry->dsn + ); } // }}} @@ -1092,6 +1101,18 @@ public static function initVar($name, $default = null, $types = 0) return $var; } + // }}} + // {{{ public function addSentryBreadcrumb() + + public function addSentryBreadcrumb($message, $category) + { + $result = $this->sentry_client->breadcrumbs->record([ + 'message' => $message, + 'category' => $category, + 'level' => 'info' + ]); + } + // }}} } diff --git a/Site/SiteSentryReportDialog.php b/Site/SiteSentryReportDialog.php new file mode 100644 index 00000000..e89b6e18 --- /dev/null +++ b/Site/SiteSentryReportDialog.php @@ -0,0 +1,69 @@ +sentry_client = $sentry_client; + $this->sentry_dsn = $sentry_dsn; + } + + // }}} + // {{{ public function getInlineXhtml() + + public function getInlineXhtml() + { + $event_id = SwatString::quoteJavaScriptString( + $this->sentry_client->getLastEventID() + ); + + $sentry_dsn = SwatString::quoteJavaScriptString( + $this->sentry_dsn + ); + + $html = << + + + + +HTML; + + return sprintf( + $html, + $event_id, + $sentry_dsn + ); + } + + // }}} + } + + ?> diff --git a/Site/SiteWebApplication.php b/Site/SiteWebApplication.php index cea10cea..076e2243 100644 --- a/Site/SiteWebApplication.php +++ b/Site/SiteWebApplication.php @@ -136,6 +136,8 @@ public function run() } } + $sentryCategory = 'app steps'; + try { if (!$cached) { $page_data = array(); @@ -143,15 +145,33 @@ public function run() $this->setP3PHeaders(); $this->loadPage(); + $this->page->layout->init(); + $this->addSentryBreadcrumb('layout init()', $sentryCategory); + $this->page->init(); + $this->addSentryBreadcrumb('init()', $sentryCategory); + $this->page->layout->process(); + $this->addSentryBreadcrumb('layout process()', $sentryCategory); + $this->page->process(); + $this->addSentryBreadcrumb('process()', $sentryCategory); + $this->page->layout->build(); + $this->addSentryBreadcrumb('layout build()', $sentryCategory); + $this->page->build(); + $this->addSentryBreadcrumb('build()', $sentryCategory); + $this->page->layout->finalize(); + $this->addSentryBreadcrumb('layout finalize()', $sentryCategory); + $this->page->finalize(); + $this->addSentryBreadcrumb('finalize()', $sentryCategory); + $this->page->layout->complete(); + $this->addSentryBreadcrumb('layout complete()', $sentryCategory); // get page content ob_start(); @@ -186,6 +206,7 @@ public function run() if ($this->page instanceof SiteExceptionPage) { $this->page->setException($e); + $this->page->setReportDialog($this->sentry_report_dialog); } $this->page->layout->init(); @@ -198,6 +219,7 @@ public function run() // display exception page (never cached) $this->page->layout->display(); + $this->addSentryBreadcrumb('exception page displayed', $sentryCategory); } } @@ -1178,6 +1200,38 @@ private function hasSession() $this->session->isActive()); } + + // }}} + // {{{ protected function getServerName() + + /** + * Gets the servername + * + * @param string the page step type + */ + protected function recordPageStep($type) + { + $server_name = $_SERVER['HTTP_HOST']; + + if ($secure !== null && $this->secure !== $secure) { + /* Need to mangle servername for browsers tunnelling on + * non-standard ports. + */ + $regexp = '/localhost:[0-9]+/u'; + + if (preg_match($regexp, $server_name)) { + if ($secure) { + $server_name = 'localhost:8443'; + } else { + $server_name = 'localhost:8080'; + } + } + } + + return $server_name; + } + + // }}} } diff --git a/Site/pages/SiteExceptionPage.php b/Site/pages/SiteExceptionPage.php index 35145348..c2ab6710 100644 --- a/Site/pages/SiteExceptionPage.php +++ b/Site/pages/SiteExceptionPage.php @@ -16,6 +16,11 @@ class SiteExceptionPage extends SitePage */ protected $exception; + /** + * @var SiteSentryReportDialog + */ + protected $report_dialog; + // }}} // {{{ public function setException() @@ -28,6 +33,14 @@ public function setException($exception) } } + // }}} + // {{{ public function setReportDialog() + + public function setReportDialog($report_dialog) + { + $this->report_dialog = $report_dialog; + } + // }}} // init phase @@ -116,6 +129,16 @@ protected function getSuggestions() return array(); } + // }}} + // {{{ protected function displaySentryReportDialog() + + protected function displaySentryReportDialog() + { + if ($this->report_dialog instanceof SiteSentryReportDialog) { + echo $this->report_dialog->getInlineXhtml(); + } + } + // }}} } diff --git a/Site/pages/SiteXhtmlExceptionPage.php b/Site/pages/SiteXhtmlExceptionPage.php index 7b971ec4..8c0580b2 100644 --- a/Site/pages/SiteXhtmlExceptionPage.php +++ b/Site/pages/SiteXhtmlExceptionPage.php @@ -46,6 +46,8 @@ protected function display() $this->displaySuggestions(); + $this->displaySentryReportDialog(); + if ($this->exception instanceof SwatException && !($this->exception instanceof SiteNotAuthorizedException)) { $this->exception->processAndContinue();