Created
April 22, 2013 16:30
-
-
Save mastermatt/5436504 to your computer and use it in GitHub Desktop.
A class wrapper for the NewRelic PHP API
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
<?php | |
/** | |
* A wrapper for the NewRelic API | |
* | |
* Method descriptions are partials. Check the site for more. | |
* @link https://newrelic.com/docs/php/the-php-api | |
* | |
* Started out as a gist from devster {@link https://gist.github.com/devster/1885331} | |
* I removed its static functionality and added the docblock method annotations | |
* | |
* @method bool setAppname(string $name, string $license = '', bool $xmit = false) Sets the name of the application to name | |
* @method void noticeError(string $message, Exception $exception) Report an error at this line of code, with a complete stack trace | |
* @method void nameTransaction(string $string) Sets the name of the transaction to the specified strin | |
* @method void endOfTransaction() Stop recording the web transaction immediately | |
* @method void endTransaction(bool $ignore = false ) Marks the end time of the transaction but takes no other action | |
* @method void startTransaction(string $appname, string $license = '' ) This will perform the same operations that occur when the script was first started | |
* @method void ignoreTransaction() Do not generate metrics for this transaction | |
* @method void ignoreApdex() Do not generate Apdex metrics for this transaction | |
* @method void backgroundJob(bool $flag = true) Mark the current transaction as a background job | |
* @method void captureParams(string $enable = 'on') Enables the capturing of URL parameters for displaying in transaction traces | |
* @method void customMetric(string $metric_name, Double $value) Adds a custom metric with the specified name and value | |
* @method void addCustomParameter(string $key, string $value ) Add a custom parameter to the current web transaction with the specified value | |
* @method void addCustomTracer(callable $function_name) Allows you to add user defined functions or methods to the list to be instrumented | |
* @method String getBrowserTimingHeader(bool $in_script_tags = true) Returns the JavaScript string to inject as part of the header for browser timing (real user monitoring) | |
* @method String getBrowserTimingFooter(bool $in_script_tags = true) Returns the JavaScript string to inject at the very end of the HTML output for browser timing (real user monitoring) | |
* @method void disableAutorum() Prevents the output filter from attempting to insert RUM JavaScript for this current transaction, useful for AJAX calls | |
* @method void setUserAttributes(String $user, String, $account, String $product) Adds the three parameter strings to collected browser traces | |
*/ | |
class NewRelic | |
{ | |
protected $_useService; | |
public function __construct( $allow = true ) | |
{ | |
$this->_useService = $allow && extension_loaded( 'newrelic' ); | |
} | |
public function __call($method, $params) | |
{ | |
if(!$this->_useService) | |
return false; | |
$function = $this->transformFunctionName($method); | |
return call_user_func_array($function, $params); | |
} | |
protected function transformFunctionName($name) | |
{ | |
$tab = preg_split('/(?=[A-Z])/', $name, -1, PREG_SPLIT_NO_EMPTY); | |
if ($tab[0] == 'newrelic') array_shift ($tab); | |
$loweredTab = array_map('strtolower', $tab); | |
return 'newrelic_' . implode('_', $loweredTab); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment