From c83246b85e5054572103f54e073479194a8aa4f9 Mon Sep 17 00:00:00 2001 From: Ankit Pathak Date: Thu, 12 Oct 2023 20:26:19 +0530 Subject: [PATCH] ACMS-1975: Sending acms logs to sumologic. --- .../acquia_cms_common.services.yml | 1 + .../KernelTerminate/AcquiaCmsTelemetry.php | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/modules/acquia_cms_common/acquia_cms_common.services.yml b/modules/acquia_cms_common/acquia_cms_common.services.yml index c7659804a..13eb2e6db 100644 --- a/modules/acquia_cms_common/acquia_cms_common.services.yml +++ b/modules/acquia_cms_common/acquia_cms_common.services.yml @@ -54,5 +54,6 @@ services: - '@state' - '%site.path%' - '@datetime.time' + - '@logger.factory' tags: - { name: event_subscriber } diff --git a/modules/acquia_cms_common/src/EventSubscriber/KernelTerminate/AcquiaCmsTelemetry.php b/modules/acquia_cms_common/src/EventSubscriber/KernelTerminate/AcquiaCmsTelemetry.php index b9d66db12..8d93fd87a 100644 --- a/modules/acquia_cms_common/src/EventSubscriber/KernelTerminate/AcquiaCmsTelemetry.php +++ b/modules/acquia_cms_common/src/EventSubscriber/KernelTerminate/AcquiaCmsTelemetry.php @@ -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; @@ -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. * @@ -93,6 +101,8 @@ 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, @@ -100,13 +110,15 @@ public function __construct( 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; } /** @@ -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; } } @@ -257,6 +272,7 @@ private function getAcquiaCmsTelemetryData(): array { 'extensions' => $this->getExtensionInfo(), ]; } + return $telemetryData; }