Created
September 25, 2019 12:13
-
-
Save bennadel/a048b15635e89934e1324ff65194d0fa to your computer and use it in GitHub Desktop.
Tracking Page Request Metrics With Framework One (FW/1) And Lucee CFML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void function before( required struct rc ) { | |
rc.requestInitiatedAt = getTickCount(); | |
rc.actionToTrack = getActionToTrack(); | |
if ( rc.actionToTrack.len() ) { | |
getBeanFactory() | |
.getBean( "RequestMetricsService" ) | |
.recordRequestStart( rc.actionToTrack ) | |
; | |
} | |
} | |
public void function after( required struct rc ) { | |
if ( rc.actionToTrack.len() ) { | |
getBeanFactory() | |
.getBean( "RequestMetricsService" ) | |
.recordRequestEnd( rc.actionToTrack, ( getTickCount() - rc.requestInitiatedAt ) ) | |
; | |
} | |
} | |
// --- | |
// PRIVATE METHODS. | |
// --- | |
/** | |
* I return the action to track as part of the request-metrics tracking. Returns an | |
* empty-string if there is no action to track. | |
*/ | |
private string function getActionToTrack() { | |
// NOTE: I'm using Try/Catch because I'm using a non-public API, which makes | |
// me nervous! | |
try { | |
// Get the last queued controller - this should be the controller that | |
// represents the actual request intent. | |
var lastController = request._fw1.controllers.last(); | |
// Since FW1 uses convention over configuration, it allows the user to make | |
// requests to controller methods that don't exist. However, for the purposes | |
// of request tracking, we're only going to care about controllers that have | |
// a corresponding item handler. | |
// -- | |
// NOTE: This will disregard any requests for View-Only end-points; but, we | |
// don't yet know if the view even exists at this point in the controller | |
// processing workflow. | |
if ( ! structKeyExists( lastController.controller, lastController.item ) ) { | |
return( "" ); | |
} | |
return( "#lastController.subsystem#:#lastController.section#.#lastController.item#" ); | |
} catch ( any error ) { | |
return( "" ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment