Sentry extension

I noticed the Sentry extension as a pre-release install in the admin application area. I use Sentry for other projects so was obviously interested.

What I haven’t noticed is any info/docs regarding how to use it. Nothing I can see on the Support forum, and Google doesn’t seem to turn up anything.

Anyone got any tips?

once you install the extension, sentry appears as an option under the logging pages in the admin

2 Likes

On a related note, there is also a CF library for Sentry if you want to hoop your application up at the CFML level.
https://www.forgebox.io/view/sentry

1 Like

I just filed an enhancement request to add a log listener to Application.cfc

https://luceeserver.atlassian.net/browse/LDEV-3035

// Application.cfc
component {
	this.log.listener=function(caller, args){
		// args being the args or attributes from either writeLog() or <cflog>
		// then you could plug in something like https://github.com/GiancarloGomez/sentry-cfml
		application.sentry.captureMessage(
			message     : args.text,
			level       :  args.type,
			useThread   : true,
			userInfo    : {
				id          : 100,
				email       : "john.doe@test.com",
				type        : "administrator",
				username    : "john",
				ip_address  : cgi.remote_addr
			}
		);

		// if args is returned false, no further logging, thus only using sentry for application logs
		return false;
		// otherwise 
		return args; // these values could also be modified in the listener before being logged normally
	}
}

Is there a reason it wouldn’t work like the other listeners in Application.cfc such as onError()?

component {

  function onLog( string message, string type ) {
    ...
  }

}

That said, I’ve wanted to have the ability to programatically register any CF listener such as onError() from outside of the Application.cfc.

I just was following the pattern of the mail and query listeners.
https://luceeserver.atlassian.net/browse/LDEV-1881
https://luceeserver.atlassian.net/browse/LDEV-1452

The advantage of that syntax is that they support multiple listeners

component {
	this.log.listener={
		before = function(caller, args){
			// args being the args or attributes from either writeLog() or <cflog>
			// then you could plug in something like https://github.com/GiancarloGomez/sentry-cfml
			application.sentry.captureMessage(
				message     : args.text,
				level       :  args.type,
				useThread   : true,
				userInfo    : {
					id          : 100,
					email       : "john.doe@test.com",
					type        : "administrator",
					username    : "john",
					ip_address  : cgi.remote_addr
				}
			);

			// if args is returned false, no further logging, thus only using sentry for application logs
			return false;
			// otherwise 
			return args; // these values could also be modified in the listener before being logged normally
		},
		after = function(caller, args){},
		error = function(caller, args, exception){
			// do some recovery fallback magic when logging fails
			// or when writeLog(text=""); explodes due to "" being ignored
		}
	};
}

I don’t like the fact that those listeners break precedent either :slight_smile: It doesn’t make a great deal of sense to register more than one listener from the same Application.cfc file. However, i don’t think the overall ability to register more than one listener should require any particular syntax in the Application.cfc.

I also like onLog() :slight_smile: