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

Added custom & payload access to report_exception #47

Merged
merged 1 commit into from
Mar 31, 2015
Merged
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
35 changes: 22 additions & 13 deletions rollbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public static function init($config = array(), $set_exception_handler = true, $s
}
}

public static function report_exception($exc) {
public static function report_exception($exc, $extra_data = null, $payload_data = null) {
if (self::$instance == null) {
return;
}
return self::$instance->report_exception($exc);
return self::$instance->report_exception($exc, $extra_data, $payload_data);
}

public static function report_message($message, $level = 'error', $extra_data = null, $payload_data = null) {
Expand Down Expand Up @@ -134,7 +134,7 @@ class RollbarNotifier {
private $_iconv_available = null;

private $_mt_randmax;

private $_curl_ipresolve_supported;

public function __construct($config) {
Expand All @@ -156,7 +156,7 @@ public function __construct($config) {
if (defined('E_DEPRECATED')) {
$levels = array_merge($levels, array(E_DEPRECATED, E_USER_DEPRECATED));
}

// PHP 5.3.0
$this->_curl_ipresolve_supported = defined('CURLOPT_IPRESOLVE');

Expand All @@ -174,9 +174,9 @@ public function __construct($config) {
$this->_mt_randmax = mt_getrandmax();
}

public function report_exception($exc) {
public function report_exception($exc, $extra_data = null, $payload_data = null) {
try {
return $this->_report_exception($exc);
return $this->_report_exception($exc, $extra_data, $payload_data);
} catch (Exception $e) {
try {
$this->log_error("Exception while reporting exception");
Expand Down Expand Up @@ -227,7 +227,7 @@ public function flush() {
/**
* @param $exc Exception
*/
protected function _report_exception($exc) {
protected function _report_exception($exc, $extra_data = null, $payload_data = null) {
if (!$this->check_config()) {
return;
}
Expand All @@ -252,14 +252,23 @@ protected function _report_exception($exc) {
'class' => get_class($exc),
'message' => $message
)
)
),
'custom' => $extra_data
);

// request, server, person data
$data['request'] = $this->build_request_data();
$data['server'] = $this->build_server_data();
$data['person'] = $this->build_person_data();

// merge $payload_data into $data
// (overriding anything already present)
if ($payload_data !== null && is_array($payload_data)) {
foreach ($payload_data as $key => $val) {
$data[$key] = $val;
}
}

array_walk_recursive($data, array($this, '_sanitize_utf8'));

$payload = $this->build_payload($data);
Expand Down Expand Up @@ -549,7 +558,7 @@ protected function user_ip() {
*/
protected function build_exception_frames($exc) {
$frames = array();

if (!method_exists($exc, 'getTrace')) {
return $frames;
}
Expand Down Expand Up @@ -711,11 +720,11 @@ protected function build_payload($data) {
$payload = array(
'data' => $data
);

if ($this->access_token) {
$payload['access_token'] = $this->access_token;
}

return $payload;
}

Expand Down Expand Up @@ -817,11 +826,11 @@ protected function make_api_call($action, $access_token, $post_data) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy['username'] . ':' . $proxy['password']);
}
}

if ($this->_curl_ipresolve_supported) {
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
}

$result = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
Expand Down