Skip to content

Commit

Permalink
ACMS-1975: Sending acms logs to sumologic.
Browse files Browse the repository at this point in the history
  • Loading branch information
apathak18 committed Oct 17, 2023
1 parent 59786a3 commit 28ba090
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions modules/acquia_cms_common/acquia_cms_common.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ services:
- '@state'
- '%site.path%'
- '@datetime.time'
- '@logger.factory'
tags:
- { name: event_subscriber }
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Site\Settings;
use Drupal\Core\State\StateInterface;
use GuzzleHttp\ClientInterface;
Expand Down Expand Up @@ -78,6 +79,13 @@ class AcquiaCmsTelemetry implements EventSubscriberInterface {
*/
protected $time;

/**
* Logger factory.
*
* @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
*/
protected $logger;

/**
* Constructs an Acquia CMS telemetry object.
*
Expand All @@ -93,20 +101,24 @@ class AcquiaCmsTelemetry implements EventSubscriberInterface {
* Drupal Site Path.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger
* The logger factory.
*/
public function __construct(
ModuleExtensionList $module_list,
ClientInterface $http_client,
ConfigFactoryInterface $config_factory,
StateInterface $state,
string $site_path,
TimeInterface $time) {
TimeInterface $time,
LoggerChannelFactoryInterface $logger) {
$this->moduleList = $module_list;
$this->httpClient = $http_client;
$this->configFactory = $config_factory;
$this->state = $state;
$this->sitePath = $site_path;
$this->time = $time;
$this->logger = $logger;
}

/**
Expand Down Expand Up @@ -193,12 +205,15 @@ public function sendTelemetry(string $event_type, array $event_properties = []):
$this->sendEvent($event);
$this->state->set('acquia_cms_common.telemetry.data', json_encode($event_properties));
$this->state->set('acquia_cms_common.telemetry.timestamp', $this->time->getCurrentTime());
$this->logger->get($event_type)->info(json_encode($event, JSON_PRETTY_PRINT));

return TRUE;
}
catch (\Exception $e) {
if ($this->state->get('acquia_connector.telemetry.loud')) {
throw new \Exception($e->getMessage(), $e->getCode(), $e);
}

return FALSE;
}
}
Expand Down Expand Up @@ -257,6 +272,7 @@ private function getAcquiaCmsTelemetryData(): array {
'extensions' => $this->getExtensionInfo(),
];
}

return $telemetryData;
}

Expand Down

0 comments on commit 28ba090

Please sign in to comment.