Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sentry enhancements #281

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Site/SiteApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ abstract class SiteApplication extends SiteObject
*/
protected $sentry_client;

/**
* @var SiteSentryReportDialog
*/
protected $sentry_report_dialog;

// }}}
// {{{ public function __construct()

Expand Down Expand Up @@ -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
);
}

// }}}
Expand Down Expand Up @@ -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'
]);
}

// }}}
}

Expand Down
69 changes: 69 additions & 0 deletions Site/SiteSentryReportDialog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/**
* Generates Sentry Report Dialog for User Input
*
* @package Site
* @copyright 2018 silverorange
*/
class SiteSentryReportDialog
{
// {{{ protected properties

/**
* The Sentry client
*
* @var Raven_Client
*/
protected $sentry_client;

/**
* @var string
*/
protected $sentry_dsn;

// }}}
// {{{ public function __construct()

public function __construct($sentry_client, $sentry_dsn) {
$this->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
<div class="sentry-report-dialog">
<script src="https://cdn.ravenjs.com/2.3.0/raven.min.js"></script>

<script>
Raven.showReportDialog({
eventId: %s,
dsn: %s
});
</script>
</div>
HTML;

return sprintf(
$html,
$event_id,
$sentry_dsn
);
}

// }}}
}

?>
54 changes: 54 additions & 0 deletions Site/SiteWebApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,42 @@ public function run()
}
}

$sentryCategory = 'app steps';

try {
if (!$cached) {
$page_data = array();

$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();
Expand Down Expand Up @@ -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();
Expand All @@ -198,6 +219,7 @@ public function run()

// display exception page (never cached)
$this->page->layout->display();
$this->addSentryBreadcrumb('exception page displayed', $sentryCategory);
}
}

Expand Down Expand Up @@ -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;
}


// }}}
}

Expand Down
23 changes: 23 additions & 0 deletions Site/pages/SiteExceptionPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class SiteExceptionPage extends SitePage
*/
protected $exception;

/**
* @var SiteSentryReportDialog
*/
protected $report_dialog;

// }}}
// {{{ public function setException()

Expand All @@ -28,6 +33,14 @@ public function setException($exception)
}
}

// }}}
// {{{ public function setReportDialog()

public function setReportDialog($report_dialog)
{
$this->report_dialog = $report_dialog;
}

// }}}

// init phase
Expand Down Expand Up @@ -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();
}
}

// }}}
}

Expand Down
2 changes: 2 additions & 0 deletions Site/pages/SiteXhtmlExceptionPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ protected function display()

$this->displaySuggestions();

$this->displaySentryReportDialog();

if ($this->exception instanceof SwatException &&
!($this->exception instanceof SiteNotAuthorizedException)) {
$this->exception->processAndContinue();
Expand Down