Sentry logging for Airtime Pro

This commit is contained in:
Albert Santoni 2015-01-27 19:54:42 -05:00
parent 3324961e19
commit c9231e9136
4 changed files with 115 additions and 387 deletions

View file

@ -1,4 +1,5 @@
<?php
require_once('SentryLogging.php');
class Logging {
@ -82,6 +83,7 @@ class Logging {
{
$logger = self::getLogger();
$logger->err(self::getLinePrefix(true) . self::toString($p_msg));
SentryLogger::getInstance()->captureError(self::toString($p_msg));
}
public static function debug($p_msg)

View file

@ -0,0 +1,111 @@
<?php
/*
require('/path/to/Raven/Autoloader.php');
Raven_Autoloader::register();
*/
class SentryLogger
{
private static $instance = null;
private $sentryClient;
/** Singleton getter */
public static function getInstance()
{
if (!is_null(self::$instance)) {
return self::$instance;
} else {
self::$instance = new SentryLogger();
return self::$instance;
}
}
private function __construct()
{
// Instantiate a new client with a compatible DSN
$dsn = 'http://6a495f2d42b345f3a995b0c2219c3b9f:383164e96bb741998d8c2af468edf503@sentry.sourcefabric.org/12';
$this->sentryClient = new Raven_Client($dsn,
array(
//FIXME: This doesn't seem to be working...
'processorOptions' => array(
'Raven_SanitizeDataProcessor' => array(
'fields_re' => '/(user_password|user_token|user_secret)/i',
'values_re' => '/^(?:\d[ -]*?){15,16}$/'
)
)
));
$client = $this->sentryClient;
/* The Raven docs suggest not enabling these because they're "too noisy".
// Install error handlers and shutdown function to catch fatal errors
$error_handler = new Raven_ErrorHandler($client);
$error_handler->registerExceptionHandler(true);
$error_handler->registerErrorHandler(true);
$error_handler->registerShutdownFunction(true);
*/
$error_handler = new Raven_ErrorHandler($client);
$error_handler->registerExceptionHandler();
}
public function captureMessage($msg)
{
$client = $this->sentryClient;
// Capture a message
$event_id = $client->getIdent($client->captureMessage($msg));
if ($client->getLastError() !== null) {
//printf('There was an error sending the event to Sentry: %s', $client->getLastError());
}
}
public function captureException($exception)
{
$client = $this->sentryClient;
self::addUserData($client);
$event_id = $client->getIdent($client->captureException($exception, array(
'extra' => $this->getExtraData(),
'tags' => $this->getTags(),
)));
$client->context->clear();
}
public function captureError($errorMessage)
{
$client = $this->sentryClient;
// Provide some additional data with an exception
self::addUserData($client);
$event_id = $client->getIdent($client->captureMessage($errorMessage, array(
'extra' => $this->getExtraData(),
'tags' => $this->getTags(),
)));
$client->context->clear();
}
private static function getTags()
{
$tags = array();
$tags['dev_env'] = Config::getConfig()["dev_env"];
return $tags;
}
private static function addUserData($client)
{
$userData = array();
$userData['client_id'] = Application_Model_Preference::GetClientId();
$userData['station_url'] = array_key_exists('SERVER_NAME', $_SERVER) ? $_SERVER['SERVER_NAME'] : "";
$client->user_context($userData);
}
/** Extra data to log with Sentry */
private function getExtraData()
{
$extraData = array();
$extraData['php_version'] = phpversion();
$extraData['client_id'] = Application_Model_Preference::GetClientId();
return $extraData;
}
}

View file

@ -1,6 +1,7 @@
{
"require": {
"propel/propel1": "1.7.0-stable",
"aws/aws-sdk-php": "2.7.9"
"aws/aws-sdk-php": "2.7.9",
"raven/raven": "0.10.0"
}
}

386
composer.lock generated
View file

@ -1,386 +0,0 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "311983cf9bb84cfacbfcc6c5dfc9e841",
"packages": [
{
"name": "aws/aws-sdk-php",
"version": "2.7.9",
"source": {
"type": "git",
"url": "https://github.com/aws/aws-sdk-php.git",
"reference": "f39354df58eec97f0ef22ccf3caf753607a47dca"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/f39354df58eec97f0ef22ccf3caf753607a47dca",
"reference": "f39354df58eec97f0ef22ccf3caf753607a47dca",
"shasum": ""
},
"require": {
"guzzle/guzzle": "~3.7",
"php": ">=5.3.3"
},
"require-dev": {
"doctrine/cache": "~1.0",
"ext-openssl": "*",
"monolog/monolog": "~1.4",
"phpunit/phpunit": "~4.0",
"symfony/yaml": "~2.1"
},
"suggest": {
"doctrine/cache": "Adds support for caching of credentials and responses",
"ext-apc": "Allows service description opcode caching, request and response caching, and credentials caching",
"ext-openssl": "Allows working with CloudFront private distributions and verifying received SNS messages",
"monolog/monolog": "Adds support for logging HTTP requests and responses",
"symfony/yaml": "Eases the ability to write manifests for creating jobs in AWS Import/Export"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.7-dev"
}
},
"autoload": {
"psr-0": {
"Aws": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "Amazon Web Services",
"homepage": "http://aws.amazon.com"
}
],
"description": "AWS SDK for PHP - Use Amazon Web Services in your PHP project",
"homepage": "http://aws.amazon.com/sdkforphp",
"keywords": [
"amazon",
"aws",
"cloud",
"dynamodb",
"ec2",
"glacier",
"s3",
"sdk"
],
"time": "2014-12-08 21:56:46"
},
{
"name": "guzzle/guzzle",
"version": "v3.9.2",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle3.git",
"reference": "54991459675c1a2924122afbb0e5609ade581155"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle3/zipball/54991459675c1a2924122afbb0e5609ade581155",
"reference": "54991459675c1a2924122afbb0e5609ade581155",
"shasum": ""
},
"require": {
"ext-curl": "*",
"php": ">=5.3.3",
"symfony/event-dispatcher": "~2.1"
},
"replace": {
"guzzle/batch": "self.version",
"guzzle/cache": "self.version",
"guzzle/common": "self.version",
"guzzle/http": "self.version",
"guzzle/inflection": "self.version",
"guzzle/iterator": "self.version",
"guzzle/log": "self.version",
"guzzle/parser": "self.version",
"guzzle/plugin": "self.version",
"guzzle/plugin-async": "self.version",
"guzzle/plugin-backoff": "self.version",
"guzzle/plugin-cache": "self.version",
"guzzle/plugin-cookie": "self.version",
"guzzle/plugin-curlauth": "self.version",
"guzzle/plugin-error-response": "self.version",
"guzzle/plugin-history": "self.version",
"guzzle/plugin-log": "self.version",
"guzzle/plugin-md5": "self.version",
"guzzle/plugin-mock": "self.version",
"guzzle/plugin-oauth": "self.version",
"guzzle/service": "self.version",
"guzzle/stream": "self.version"
},
"require-dev": {
"doctrine/cache": "~1.3",
"monolog/monolog": "~1.0",
"phpunit/phpunit": "3.7.*",
"psr/log": "~1.0",
"symfony/class-loader": "~2.1",
"zendframework/zend-cache": "2.*,<2.3",
"zendframework/zend-log": "2.*,<2.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.9-dev"
}
},
"autoload": {
"psr-0": {
"Guzzle": "src/",
"Guzzle\\Tests": "tests/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Guzzle Community",
"homepage": "https://github.com/guzzle/guzzle/contributors"
}
],
"description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients",
"homepage": "http://guzzlephp.org/",
"keywords": [
"client",
"curl",
"framework",
"http",
"http client",
"rest",
"web service"
],
"time": "2014-08-11 04:32:36"
},
{
"name": "phing/phing",
"version": "2.9.1",
"source": {
"type": "git",
"url": "https://github.com/phingofficial/phing.git",
"reference": "393edeffa8a85d43636ce0c9b4deb1ff9ac60a5c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phingofficial/phing/zipball/393edeffa8a85d43636ce0c9b4deb1ff9ac60a5c",
"reference": "393edeffa8a85d43636ce0c9b4deb1ff9ac60a5c",
"shasum": ""
},
"require": {
"php": ">=5.2.0"
},
"require-dev": {
"ext-pdo_sqlite": "*",
"lastcraft/simpletest": "@dev",
"pdepend/pdepend": "1.x",
"pear-pear.php.net/http_request2": "2.2.x",
"pear-pear.php.net/net_growl": "2.7.x",
"pear-pear.php.net/pear_packagefilemanager": "1.7.x",
"pear-pear.php.net/pear_packagefilemanager2": "1.0.x",
"pear-pear.php.net/xml_serializer": "0.20.x",
"pear/pear_exception": "@dev",
"pear/versioncontrol_git": "@dev",
"pear/versioncontrol_svn": "@dev",
"phpdocumentor/phpdocumentor": "2.x",
"phploc/phploc": "2.x",
"phpunit/phpunit": ">=3.7",
"sebastian/phpcpd": "2.x",
"squizlabs/php_codesniffer": "1.5.x"
},
"suggest": {
"pdepend/pdepend": "PHP version of JDepend",
"pear/archive_tar": "Tar file management class",
"pear/versioncontrol_git": "A library that provides OO interface to handle Git repository",
"pear/versioncontrol_svn": "A simple OO-style interface for Subversion, the free/open-source version control system",
"phpdocumentor/phpdocumentor": "Documentation Generator for PHP",
"phploc/phploc": "A tool for quickly measuring the size of a PHP project",
"phpmd/phpmd": "PHP version of PMD tool",
"phpunit/php-code-coverage": "Library that provides collection, processing, and rendering functionality for PHP code coverage information",
"phpunit/phpunit": "The PHP Unit Testing Framework",
"sebastian/phpcpd": "Copy/Paste Detector (CPD) for PHP code",
"tedivm/jshrink": "Javascript Minifier built in PHP"
},
"bin": [
"bin/phing"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.9.x-dev"
}
},
"autoload": {
"classmap": [
"classes/phing/"
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
"classes"
],
"license": [
"LGPL-3.0"
],
"authors": [
{
"name": "Phing Community",
"homepage": "http://www.phing.info/trac/wiki/Development/Contributors"
},
{
"name": "Michiel Rook",
"email": "mrook@php.net"
}
],
"description": "PHing Is Not GNU make; it's a PHP project build system or build tool based on Apache Ant.",
"homepage": "http://www.phing.info/",
"keywords": [
"build",
"phing",
"task",
"tool"
],
"time": "2014-12-03 09:18:46"
},
{
"name": "propel/propel1",
"version": "1.7.0",
"source": {
"type": "git",
"url": "https://github.com/propelorm/Propel.git",
"reference": "09058f1443bc287e550b9342a4379aac2e0a0b8f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/propelorm/Propel/zipball/09058f1443bc287e550b9342a4379aac2e0a0b8f",
"reference": "09058f1443bc287e550b9342a4379aac2e0a0b8f",
"shasum": ""
},
"require": {
"phing/phing": "~2.4",
"php": ">=5.2.4"
},
"require-dev": {
"pear-pear.php.net/pear_packagefilemanager2": "@stable"
},
"bin": [
"generator/bin/propel-gen",
"generator/bin/propel-gen.bat"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.7-dev"
}
},
"autoload": {
"classmap": [
"runtime/lib",
"generator/lib"
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
"runtime/lib",
"generator/lib"
],
"license": [
"MIT"
],
"authors": [
{
"name": "William Durand",
"email": "william.durand1@gmail.com",
"homepage": "http://www.willdurand.fr"
}
],
"description": "Propel is an open-source Object-Relational Mapping (ORM) for PHP5.",
"homepage": "http://www.propelorm.org/",
"keywords": [
"Active Record",
"database",
"mapping",
"orm",
"persistence"
],
"time": "2013-10-21 12:52:56"
},
{
"name": "symfony/event-dispatcher",
"version": "v2.6.1",
"target-dir": "Symfony/Component/EventDispatcher",
"source": {
"type": "git",
"url": "https://github.com/symfony/EventDispatcher.git",
"reference": "720fe9bca893df7ad1b4546649473b5afddf0216"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/720fe9bca893df7ad1b4546649473b5afddf0216",
"reference": "720fe9bca893df7ad1b4546649473b5afddf0216",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"psr/log": "~1.0",
"symfony/config": "~2.0",
"symfony/dependency-injection": "~2.6",
"symfony/expression-language": "~2.6",
"symfony/stopwatch": "~2.2"
},
"suggest": {
"symfony/dependency-injection": "",
"symfony/http-kernel": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.6-dev"
}
},
"autoload": {
"psr-0": {
"Symfony\\Component\\EventDispatcher\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
},
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
}
],
"description": "Symfony EventDispatcher Component",
"homepage": "http://symfony.com",
"time": "2014-12-02 20:19:20"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"platform": [],
"platform-dev": []
}