|
|
@@ -27,6 +27,13 @@ class NewRelicHandler extends AbstractProcessingHandler
|
|
|
*/
|
|
|
protected $appName;
|
|
|
|
|
|
+ /**
|
|
|
+ * Name of the current transaction
|
|
|
+ *
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ protected $transactionName;
|
|
|
+
|
|
|
/**
|
|
|
* Some context and extra data is passed into the handler as arrays of values. Do we send them as is
|
|
|
* (useful if we are using the API), or explode them for display on the NewRelic RPM website?
|
|
|
@@ -39,14 +46,21 @@ class NewRelicHandler extends AbstractProcessingHandler
|
|
|
* {@inheritDoc}
|
|
|
*
|
|
|
* @param string $appName
|
|
|
- * @param boolean $implodeArrays
|
|
|
+ * @param boolean $explodeArrays
|
|
|
+ * @param string $transactionName
|
|
|
*/
|
|
|
- public function __construct($level = Logger::ERROR, $bubble = true, $appName = null, $explodeArrays = false)
|
|
|
- {
|
|
|
+ public function __construct(
|
|
|
+ $level = Logger::ERROR,
|
|
|
+ $bubble = true,
|
|
|
+ $appName = null,
|
|
|
+ $explodeArrays = false,
|
|
|
+ $transactionName = null
|
|
|
+ ) {
|
|
|
parent::__construct($level, $bubble);
|
|
|
|
|
|
$this->appName = $appName;
|
|
|
$this->explodeArrays = $explodeArrays;
|
|
|
+ $this->transactionName = $transactionName;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -62,6 +76,11 @@ class NewRelicHandler extends AbstractProcessingHandler
|
|
|
$this->setNewRelicAppName($appName);
|
|
|
}
|
|
|
|
|
|
+ if ($transactionName = $this->getTransactionName($record['context'])) {
|
|
|
+ $this->setNewRelicTransactionName($transactionName);
|
|
|
+ unset($record['context']['transaction_name']);
|
|
|
+ }
|
|
|
+
|
|
|
if (isset($record['context']['exception']) && $record['context']['exception'] instanceof \Exception) {
|
|
|
newrelic_notice_error($record['message'], $record['context']['exception']);
|
|
|
unset($record['context']['exception']);
|
|
|
@@ -102,7 +121,7 @@ class NewRelicHandler extends AbstractProcessingHandler
|
|
|
|
|
|
/**
|
|
|
* Returns the appname where this log should be sent. Each log can override the default appname, set in this
|
|
|
- * handler's constructor, by providing the appname in its context.
|
|
|
+ * handler's constructor, by providing the appname in it's context.
|
|
|
*
|
|
|
* @param array $context
|
|
|
* @return null|string
|
|
|
@@ -116,6 +135,23 @@ class NewRelicHandler extends AbstractProcessingHandler
|
|
|
return $this->appName;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns the name of the current transaction. Each log can override the default transaction name, set in this
|
|
|
+ * handler's constructor, by providing the transaction_name in it's context
|
|
|
+ *
|
|
|
+ * @param array $context
|
|
|
+ *
|
|
|
+ * @return null|string
|
|
|
+ */
|
|
|
+ protected function getTransactionName(array $context)
|
|
|
+ {
|
|
|
+ if (isset($context['transaction_name'])) {
|
|
|
+ return $context['transaction_name'];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->transactionName;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Sets the NewRelic application that should receive this log.
|
|
|
*
|
|
|
@@ -125,4 +161,14 @@ class NewRelicHandler extends AbstractProcessingHandler
|
|
|
{
|
|
|
newrelic_set_appname($appName);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Overwrites the name of the current transaction
|
|
|
+ *
|
|
|
+ * @param $transactionName
|
|
|
+ */
|
|
|
+ protected function setNewRelicTransactionName($transactionName)
|
|
|
+ {
|
|
|
+ newrelic_name_transaction($transactionName);
|
|
|
+ }
|
|
|
}
|