Skip to content

Instantly share code, notes, and snippets.

View brianr's full-sized avatar

Brian Rue brianr

View GitHub Profile
@brianr
brianr / gist:db44a4efb99d00d0c4b1
Created July 8, 2014 06:41
Rollbar with custom php error handler
<?php
Rollbar::init($config, true, false); // config array, true to install uncaught exception handler, false to not install error handler
function my_error_handler($errno, $errstr, $errfile, $errline) {
Rollbar::report_php_error($errno, $errstr, $errfile, $errline);
// add your own error handling code here
}
set_error_handler('my_error_handler');
@brianr
brianr / rollbar.rb
Last active August 29, 2015 14:03
Disabling logging for Rollbar in Ruby
# put all of this in config/initializers/rollbar.rb
# from http://hawkins.io/2013/08/using-the-ruby-logger/
class NullLogger < Logger
def initialize(*args)
end
def add(*args, &block)
end
end
@brianr
brianr / request_code_as_context.diff
Created July 9, 2014 18:13
rollbar.php - diff to use request.code as 'context' so it is searchable
diff --git a/rollbar.php b/rollbar.php
index f7d7de0..858bf75 100644
--- a/rollbar.php
+++ b/rollbar.php
@@ -249,6 +249,11 @@ class RollbarNotifier {
$data['server'] = $this->build_server_data();
$data['person'] = $this->build_person_data();
+ // use request.code as 'context', so it is searchable
+ if ($data['request'] && isset($data['request']['code'])) {
@brianr
brianr / gist:c90e615d03da45c81fb5
Created July 15, 2014 23:46
Rollbar custom grouping to group separately by server.software
[
{
"title": "{{ default_title }} in version {{ server.software }}",
"fingerprint": "{{ default_fingerprint }} {{ server.software }}",
"condition": {"path": "server.software", "neq": null}
}
]
@brianr
brianr / example.js
Created July 17, 2014 17:47
node_rollbar log server-to-server requests and responses
var rollbar = require('rollbar');
rollbar.init("access token here");
function makeRequest(url, args) {
// third param is a callback fired upon completion
doMakeRequest(url, args, function(response) {
// log the request and response to rollbar
rollbar.reportMessageWithPayloadData("Made request to " + url,
{level: 'info', custom: {request_args: args, response: response}});
})
@brianr
brianr / gist:5f985b7df9facc9484c4
Created July 22, 2014 20:23
rollbar.js context config
_rollbarConfig = {
accessToken: "token here",
captureUncaught: true,
payload: {
environment: "production",
// you'll be able to search for this by prefix
// i.e. searching for context:home will return items
// with occurrences where the context is home#index, home#about, etc.
context: "home#index"
}
@brianr
brianr / gist:7828ffb0bd4f2212b247
Created September 5, 2014 22:47
rollbar.js checkIgnore configuration to ignore IE7 errors
_rollbarConfig = {
accessToken: "token here",
checkIgnore: function(isUncaught, args, payload) {
var isIE7 = (window.navigator.userAgent.indexOf("MSIE 7") !== -1);
if (isUncaught && isIE7) {
// uncaught error, and we are in IE 7. return true to ignore.
return true;
}
// don't ignore anything else
return false;
import rollbar.logger
class SaferRollbarHandler(rollbar.logger.RollbarHandler):
def emit(self, record):
if record.name == 'rollbar':
return
super(SaferRollbarHandler, self).emit(record)
@brianr
brianr / gist:82ff15b17c839ff14748
Created October 27, 2014 18:14
Rollbar RQL: Search for occurrences in last 24 hours by url pattern
select *
from item_occurrence
where timestamp >= unix_timestamp() - 24 * 60 * 60
and request.url like '%mydomain.com%'
@brianr
brianr / rollbarconfig.js
Last active August 29, 2015 14:09
Rollbar transform to normalize filenames for multitenant sourcemap support
var _rollbarConfig = {
// ...
transform: function(payload) {
var trace = payload.data.body.trace;
if (trace && trace.frames) {
for (var i = 0; i < trace.frames.length; i++) {
var filename = trace.frames[i].filename;
if (filename) {
// we have a frame with a filename
// 1. TODO - check if the filename looks like it's part of our app (and not some external js)