Skip to content

Instantly share code, notes, and snippets.

@d1rtym0nk3y
Created August 27, 2013 08:20
Show Gist options
  • Save d1rtym0nk3y/6351003 to your computer and use it in GitHub Desktop.
Save d1rtym0nk3y/6351003 to your computer and use it in GitHub Desktop.
//Application.cfc
component extends="fw1" {
// omiting all the usualy fw1 stuff..
function setupRequest() {
// this is just a wrapper around a singleton instance of the java class com.newrelic.api.agent.NewRelic
var nr = getBeanFactory().getBean("NewRelic");
// setup newrelic to track the this request
nr.setTransactionName( nullValue(), "/#getFullyQualifiedAction()#");
// track whatever custom values you need
nr.addCustomParameter( "session_id", session.sessionid );
nr.addCustomParameter( "request_id", request.unique_id);
nr.addCustomParameter( "username", rc.currentuser.username ?: 'anonymous' );
}
}
// error.cfc controller
component accessors="true" {
// autowired bean
property NewRelic;
// this is the default error handler for the app
function onError(rc) {
rc.error_id = lcase(createUUID());
if(!isNull(request.exception)) {
var re = request.exception;
var cause = re.getRootCause();
var params = {
error_id = rc.error_id,
type: re.type ?: '',
message: re.message ?: '',
detail: re.detail ?: '',
};
NewRelic.noticeError(cause, params);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment