Skip to content

Commit

Permalink
Merge pull request #82 from TheDMSGroup/improvement/add-tracing-logs
Browse files Browse the repository at this point in the history
Add trace details for debugging.
  • Loading branch information
heathdutton authored Jun 19, 2018
2 parents b32d8fb + 4d4e8cf commit 2269510
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions Integration/ClientIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,15 @@ public function sendContact(
);
}
$this->contactClient = $client;
$this->addTrace('contactClientId', $this->contactClient->getId());

if (!$contact && !$this->test) {
throw new \InvalidArgumentException(
$translator->trans('mautic.contactclient.sendcontact.error.contact.load')
);
}
$this->contact = $contact;
$this->addTrace('contactClientContactId', $this->contact->getId());

// Check all rules that may preclude sending this contact, in order of performance cost.

Expand Down Expand Up @@ -341,6 +343,19 @@ public function sendContact(
return $this;
}

/**
* If available add a parameter to NewRelic tracing to aid in debugging.
*
* @param $parameter
* @param $value
*/
private function addTrace($parameter, $value)
{
if (function_exists('newrelic_add_custom_parameter')) {
call_user_func('newrelic_add_custom_parameter', $parameter, $value);
}
}

/**
* Evaluates the schedule given the client type.
*
Expand Down Expand Up @@ -659,6 +674,7 @@ private function logResults()
// Stats - contactclient_stats
$errors = $this->getLogs('error');
$this->statType = !empty($this->statType) ? $this->statType : Stat::TYPE_ERROR;
$this->addTrace('contactClientStatType', $this->statType);
if ($this->valid) {
$statLevel = 'INFO';
switch ($this->contactClient->getType()) {
Expand All @@ -676,19 +692,15 @@ private function logResults()
}

// Session storage for external plugins (should probably be dispatcher instead).
$contactId = $this->contact->getId();
$session = $this->dispatcher->getContainer()->get('session');
$eventId = isset($this->event['id']) ? $this->event['id'] : 0;
$eventName = isset($this->event['name']) ? $this->event['name'] : null;
$events = $session->get('mautic.contactClient.events', []);
if (!isset($events[$contactId])) {
$events[$contactId] = [];
}
$events[$contactId][$eventId] = [
'name' => $eventName,
'valid' => $this->valid,
'statType' => $this->statType,
'errors' => $errors,
$events[] = [
'id' => isset($this->event['id']) ? $this->event['id'] : 'NA',
'name' => isset($this->event['name']) ? $this->event['name'] : null,
'valid' => $this->valid,
'statType' => $this->statType,
'errors' => $errors,
'contactId' => $this->contact->getId(),
];
$session->set('mautic.contactClient.events', $events);

Expand Down

0 comments on commit 2269510

Please sign in to comment.