Commit 0b3d0b63 authored by agata's avatar agata

rimosso plugin wordpress-sentry

parent e58e40a2
wordpress-sentry
================
A WordpRess plugin to handle reporting php error to Django's Sentry
\ No newline at end of file
<?php
require_once( dirname(__FILE__).'/raven/lib/Raven/Client.php' );
require_once( dirname(__FILE__).'/raven/lib/Raven/Compat.php' );
require_once( dirname(__FILE__).'/raven/lib/Raven/ErrorHandler.php' );
require_once( dirname(__FILE__).'/raven/lib/Raven/Stacktrace.php' );
class WP_Raven_Client extends Raven_Client {
function __construct() {
if ( !isset( $this->settings['dsn'] )) return;
if ( $this->settings['dsn'] == '' ) return;
parent::__construct('http://ae2f418cf46f4910bf2c549335828557:9fc4940e00b34b9dade1bf0636846eec@evasione-vpn:3000/11');
$this->setErrorReportingLevel( 'E_ALL );
$this->setHandlers();
}
function setHandlers() {
$error_handler = new Raven_ErrorHandler( $this );
set_error_handler( array( $error_handler, 'handleError' ));
set_exception_handler( array( $error_handler, 'handleException' ));
}
function setErrorReportingLevel( $level = 'E_WARNING' ) {
$errorLevelMap = array(
'E_NONE' => 0,
'E_WARNING' => 2,
'E_NOTICE' => 8,
'E_USER_ERROR' => 256,
'E_USER_WARNING' => 512,
'E_USER_NOTICE' => 1024,
'E_RECOVERABLE_ERROR' => 4096,
'E_ALL' => 8191
);
if ( array_key_exists( $level, $errorLevelMap ) )
$this->_max_error_reporting_level = $errorLevelMap[ $level ];
}
}
?>
<div class="wrap">
<h2>Sentry Error Reporting Settings</h2>
<form action="" method="post">
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row">
<label for="sentry_dsn">Sentry DSN</label>
</th>
<td>
<input name="sentry_dsn" type="text" id="sentry-dsn" value="<?php echo $dsn; ?>" class="regular-text">
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="sentry_dsn">Error Reporting Level</label>
</th>
<td>
<select name="sentry_reporting_level">
<option value="E_NONE" <?php echo ($reporting_level == 'E_NONE') ? 'selected="selected"' : '';?>>None</option>
<option value="E_WARNING" <?php echo ($reporting_level == 'E_WARNING') ? 'selected="selected"' : '';?>>Warnings</option>
<option value="E_NOTICE" <?php echo ($reporting_level == 'E_NOTICE') ? 'selected="selected"' : '';?>>Notices</option>
<option value="E_USER_ERROR" <?php echo ($reporting_level == 'E_USER_ERROR') ? 'selected="selected"' : '';?>>User Errors</option>
<option value="E_USER_WARNING" <?php echo ($reporting_level == 'E_USER_WARNING') ? 'selected="selected"' : '';?>>User Warnings</option>
<option value="E_USER_NOTICE" <?php echo ($reporting_level == 'E_USER_NOTICE') ? 'selected="selected"' : '';?>>User Notices</option>
<option value="E_RECOVERABLE_ERROR" <?php echo ($reporting_level == 'E_RECOVERABLE_ERROR') ? 'selected="selected"' : '';?>>Recoverable Errors</option>
<option value="E_ALL" <?php echo ($reporting_level == 'E_ALL') ? 'selected="selected"' : '';?>>All Errors</option>
</select>
("User Notices" is recommended)
</td>
</tr>
</tbody>
</table>
<p class="submit">
<input type="submit" name="submit" id="submit" class="button-primary" value="Save Changes">
</p>
</form>
</div>
\ No newline at end of file
*.lock
package.xml
/vendor
\ No newline at end of file
language: php
php:
- 5.2
- 5.3
- 5.4
notifications:
irc:
channels: "irc.freenode.org#sentry"
on_success: change
on_failure: change
\ No newline at end of file
The Raven PHP client was originally written by Michael van Tellingen
and is maintained by the Sentry Team.
http://github.com/getsentry/raven-php/contributors
\ No newline at end of file
Copyright (c) 2012 Sentry Team and individual contributors.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the Raven nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
raven-php
=========
.. image:: https://secure.travis-ci.org/getsentry/raven-php.png?branch=master
:target: http://travis-ci.org/getsentry/raven-php
raven-php is an experimental PHP client for `Sentry <http://aboutsentry.com/>`_.
::
// Instantiate a new client with a compatible DSN
$client = new Raven_Client('http://public:secret@example.com/1');
// Capture a message
$event_id = $client->getIdent($client->captureMessage('my log message'));
// Capture an exception
$event_id = $client->getIdent($client->captureException($ex));
// Give the user feedback
echo "Sorry, there was an error!";
echo "Your reference ID is " . $event_id;
// Install error handlers
$error_handler = new Raven_ErrorHandler($client);
$error_handler->registerExceptionHandler();
$error_handler->registerErrorHandler();
Installation
------------
Install with Composer
~~~~~~~~~~~~~~~~~~~~~
If you're using `Composer <https://github.com/composer/composer>`_ to manage
dependencies, you can add Raven with it.
::
{
"require": {
"raven/raven": ">=0.2.0"
}
}
or to get the latest version off the master branch:
::
{
"require": {
"raven/raven": "dev-master"
}
}
Install source from GitHub
~~~~~~~~~~~~~~~~~~~~~~~~~~
To install the source code:
::
$ git clone git://github.com/getsentry/raven-php.git
And include it in your scripts:
::
require_once '/path/to/Raven/library/Raven.php';
Or, alternatively use the autoloader:
::
require_once '/path/to/Raven/library/Raven/Autoloader.php';
Raven_Autoloader::register();
Or, if you're using `Composer <https://github.com/composer/composer>`_:
::
require_once 'vendor/autoload.php';
Resources
---------
* `Bug Tracker <http://github.com/getsentry/raven-php/issues>`_
* `Code <http://github.com/getsentry/raven-php>`_
* `Mailing List <https://groups.google.com/group/getsentry>`_
* `IRC <irc://irc.freenode.net/sentry>`_ (irc.freenode.net, #sentry)
{
"name": "raven/raven",
"type": "library",
"description": "A PHP client for Sentry (http://getsentry.com)",
"keywords": ["log", "logging"],
"homepage": "http://getsentry.com",
"version": "0.2.0",
"license": "Apache License 2",
"authors": [
{
"name": "Michael van Tellingen",
"email": ""
},
{
"name": "David Cramer",
"email": "dcramer@gmail.com"
}
],
"require": {
"php": ">=5.2.4"
},
"autoload": {
"psr-0" : {
"Raven_" : "lib/"
}
}
}
\ No newline at end of file
<?php
/*
* This file is part of Raven.
*
* (c) Sentry Team
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Autoloads Raven classes.
*
* @package raven
*/
class Raven_Autoloader
{
/**
* Registers Raven_Autoloader as an SPL autoloader.
*/
static public function register()
{
ini_set('unserialize_callback_func', 'spl_autoload_call');
spl_autoload_register(array(new self, 'autoload'));
}
/**
* Handles autoloading of classes.
*
* @param string $class A class name.
*
* @return boolean Returns true if the class has been loaded
*/
static public function autoload($class)
{
if (0 !== strpos($class, 'Raven')) {
return;
}
if (is_file($file = dirname(__FILE__).'/../'.str_replace(array('_', "\0"), array('/', ''), $class).'.php')) {
require $file;
}
}
}
\ No newline at end of file
<?php
/*
* This file is part of Raven.
*
* (c) Sentry Team
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Raven PHP Client
*
* @package raven
*/
class Raven_Client
{
const DEBUG = 10;
const INFO = 20;
const WARN = 30;
const WARNING = 30;
const ERROR = 40;
function __construct($options_or_dsn=null, $options=array())
{
if (is_null($options_or_dsn)) {
// Read from environment
$options_or_dsn = $_SERVER['SENTRY_DSN'];
}
if (!is_array($options_or_dsn)) {
// Must be a valid DSN
$options_or_dsn = self::parseDSN($options_or_dsn);
}
$options = array_merge($options_or_dsn, $options);
$this->servers = (!empty($options['servers']) ? $options['servers'] : null);
$this->secret_key = (!empty($options['secret_key']) ? $options['secret_key'] : null);
$this->public_key = (!empty($options['public_key']) ? $options['public_key'] : null);
$this->project = (isset($options['project']) ? $options['project'] : 1);
$this->auto_log_stacks = (isset($options['auto_log_stacks']) ? $options['auto_log_stacks'] : false);
$this->name = (!empty($options['name']) ? $options['name'] : Raven_Compat::gethostname());
$this->site = (!empty($options['site']) ? $options['site'] : $this->_server_variable('SERVER_NAME'));
$this->_lasterror = null;
}
/**
* Parses a Raven-compatible DSN and returns an array of its values.
*/
public static function parseDSN($dsn)
{
$url = parse_url($dsn);
$scheme = (isset($url['scheme']) ? $url['scheme'] : '');
if (!in_array($scheme, array('http', 'https', 'udp'))) {
throw new InvalidArgumentException('Unsupported Sentry DSN scheme: ' . $scheme);
}
$netloc = (isset($url['host']) ? $url['host'] : null);
$netloc.= (isset($url['port']) ? ':'.$url['port'] : null);
$rawpath = (isset($url['path']) ? $url['path'] : null);
if ($rawpath) {
$pos = strrpos($rawpath, '/', 1);
if ($pos !== false) {
$path = substr($rawpath, 0, $pos);
$project = substr($rawpath, $pos + 1);
}
else {
$path = '';
$project = substr($rawpath, 1);
}
}
else {
$project = null;
$path = '';
}
$username = (isset($url['user']) ? $url['user'] : null);
$password = (isset($url['pass']) ? $url['pass'] : null);
if (empty($netloc) || empty($project) || empty($username) || empty($password)) {
throw new InvalidArgumentException('Invalid Sentry DSN: ' . $dsn);
}
return array(
'servers' => array(sprintf('%s://%s%s/api/store/', $scheme, $netloc, $path)),
'project' => $project,
'public_key' => $username,
'secret_key' => $password,
);
}
/**
* Given an identifier, returns a Sentry searchable string.
*/
public function getIdent($ident)
{
// XXX: We dont calculate checksums yet, so we only have the ident.
return $ident;
}
/**
* Deprecated
*/
public function message($message, $params=array(), $level=self::INFO,
$stack=false)
{
return $this->captureMessage($message, $params, $level, $stack);
}
/**
* Deprecated
*/
public function exception($exception)
{
return $this->captureException($exception);
}
/**
* Log a message to sentry
*/
public function captureMessage($message, $params=array(), $level=self::INFO,
$stack=false)
{
$data = array(
'message' => vsprintf($message, $params),
'level' => $level,
'sentry.interfaces.Message' => array(
'message' => $message,
'params' => $params,
)
);
return $this->capture($data, $stack);
}
/**
* Log an exception to sentry
*/
public function captureException($exception, $culprit=null, $logger=null)
{
$exc_message = $exception->getMessage();
if (empty($exc_message)) {
$exc_message = '<unknown exception>';
}
$data = array(
'message' => $exc_message
);
$data['sentry.interfaces.Exception'] = array(
'value' => $exc_message,
'type' => $exception->getCode(),
'module' => $exception->getFile() .':'. $exception->getLine(),
);
if ($culprit){
$data["culprit"] = $culprit;
}
if ($logger){
$data["logger"] = $logger;
}
/**'sentry.interfaces.Exception'
* Exception::getTrace doesn't store the point at where the exception
* was thrown, so we have to stuff it in ourselves. Ugh.
*/
$trace = $exception->getTrace();
$frame_where_exception_thrown = array(
'file' => $exception->getFile(),
'line' => $exception->getLine(),
);
array_unshift($trace, $frame_where_exception_thrown);
return $this->capture($data, $trace);
}
public function capture($data, $stack)
{
$event_id = $this->uuid4();
if (!isset($data['timestamp'])) $data['timestamp'] = gmdate('Y-m-d\TH:i:s\Z');
if (!isset($data['level'])) $data['level'] = self::ERROR;
// The function getallheaders() is only available when running in a
// web-request. The function is missing when run from the commandline..
$headers = array();
if (function_exists('getallheaders')) {
$headers = getallheaders();
}
$data = array_merge($data, array(
'server_name' => $this->name,
'event_id' => $event_id,
'project' => $this->project,
'site' => $this->site,
'sentry.interfaces.Http' => array(
'method' => $this->_server_variable('REQUEST_METHOD'),
'url' => $this->get_current_url(),
'query_string' => $this->_server_variable('QUERY_STRNG'),
'data' => $_POST,
'cookies' => $_COOKIE,
'headers' => $headers,
'env' => $_SERVER,
)
));
if ((!$stack && $this->auto_log_stacks) || $stack === True) {
$stack = debug_backtrace();
// Drop last stack
array_shift($stack);
}
/**
* PHP's way of storing backstacks seems bass-ackwards to me
* 'function' is not the function you're in; it's any function being
* called, so we have to shift 'function' down by 1. Ugh.
*/
for ($i = 0; $i < count($stack) - 1; $i++) {
$stack[$i]['function'] = $stack[$i + 1]['function'];
}
$stack[count($stack) - 1]['function'] = null;
if ($stack && !isset($data['sentry.interfaces.Stacktrace'])) {
$data['sentry.interfaces.Stacktrace'] = array(
'frames' => Raven_Stacktrace::get_stack_info($stack)
);
}
if (function_exists('mb_convert_encoding')) {
$data = $this->remove_invalid_utf8($data);
}
$this->send($data);
return $event_id;
}
public function send($data)
{
$message = base64_encode(gzcompress(Raven_Compat::json_encode($data)));
foreach($this->servers as $url) {
$timestamp = microtime(true);
$signature = $this->get_signature(
$message, $timestamp, $this->secret_key);
$headers = array(
'X-Sentry-Auth' => $this->get_auth_header(
$signature, $timestamp, 'raven-php/0.1', $this->public_key),
'Content-Type' => 'application/octet-stream'
);
$this->send_remote($url, $message, $headers);
}
}
private function send_remote($url, $data, $headers=array())
{
$parts = parse_url($url);
$parts['netloc'] = $parts['host'].(isset($parts['port']) ? ':'.$parts['port'] : null);
if ($parts['scheme'] === 'udp')
return $this->send_udp($parts['netloc'], $data, $headers['X-Sentry-Auth']);
return $this->send_http($url, $data, $headers);
}
private function send_udp($netloc, $data, $headers)
{
list($host, $port) = explode(':', $netloc);
$raw_data = $headers."\n\n".$data;
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_sendto($sock, $raw_data, strlen($raw_data), 0, $host, $port);
socket_close($sock);
return true;
}
/**
* Send the message over http to the sentry url given
*/
private function send_http($url, $data, $headers=array())