Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No ability to prevent logs sending from Meta Extension to meta #33

Open
ihor-sviziev opened this issue Sep 27, 2023 · 2 comments
Open

Comments

@ihor-sviziev
Copy link

ihor-sviziev commented Sep 27, 2023

I noticed that this extension sends a part of the logs to Meta. There is supposed to be an ability to enable/disable this functionality.

Related functionality:

  • adding a log to meta flag
    public function logExceptionImmediatelyToMeta(Throwable $e, array $context = [])
    {
    $context['log_type'] = self::PERSIST_META_LOG_IMMEDIATELY;
    $this->logException($e, $context);
    }
  • adding log to the queue
    protected function write(array $record): void
    {
    $logTypeIsSet = isset($record['context']['log_type']);
    if ($logTypeIsSet && $record['context']['log_type'] === FBEHelper::PERSIST_META_LOG_IMMEDIATELY) {
    $this->publisher->publish('persist.meta.log.immediately', json_encode($record['context']));
    } elseif ($logTypeIsSet && $record['context']['log_type'] === 'persist_meta_telemetry_logs') {
    $this->publisher->publish('persist.meta.telemetry.logs', json_encode($record['context']));
    return;
    }
    parent::write($record);
  • message queue consumers
    <consumer name="persist.meta.log.immediately.consumer" queue="persist_meta_log_immediately" connection="db" handler="Meta\BusinessExtension\Model\PersistMetaLogImmediatelyHandler::persistMetaLogImmediately" consumerInstance="Magento\Framework\MessageQueue\Consumer"/>
    <consumer name="persist.meta.telemetry.logs.consumer" queue="persist_meta_telemetry_logs" connection="db" handler="Meta\BusinessExtension\Model\PersistMetaTelemetryLogsHandler::persistMetaTelemetryLogs" consumerInstance="Magento\Framework\MessageQueue\BatchConsumer" maxMessages="20" maxIdleTime="5"/>
  • sending logs to meta from the queue
    public function persistLogToMeta($context)
    {
    $extraData = $this->getContextData($context, 'extra_data', []);
    $token = $this->accessToken;
    if (!$token) {
    $token = $this->clientAccessToken;
    $extraData = array_merge($extraData, ['access_token_used' => 'client']);
    }
    $request = [
    'access_token' => $token,
    'event' => $this->getContextData($context, 'event'),
    'event_type' => $this->getContextData($context, 'event_type'),
    'commerce_merchant_settings_id' => $this->getContextData($context, 'commerce_merchant_settings_id'),
    'exception_message' => $this->getContextData($context, 'exception_message'),
    'exception_trace' => $this->getContextData($context, 'exception_trace'),
    'exception_code' => $this->getContextData($context, 'exception_code'),
    'exception_class' => $this->getContextData($context, 'exception_class'),
    'catalog_id' => $this->getContextData($context, 'catalog_id'),
    'order_id' => $this->getContextData($context, 'order_id'),
    'promotion_id' => $this->getContextData($context, 'promotion_id'),
    'flow_name' => $this->getContextData($context, 'flow_name'),
    'flow_step' => $this->getContextData($context, 'flow_step'),
    'incoming_params' => $this->getContextData($context, 'incoming_params'),
    'seller_platform_app_version' => $this->getContextData($context, 'seller_platform_app_version'),
    'extra_data' => $extraData,
    ];
    $response = $this->callApi('POST', "commerce_seller_logs", $request);
    $response = json_decode($response->getBody()->__toString(), true);
    return $response;
    }

Preconditions (*)

Steps to reproduce (*)

Expected result (*)

  1. [Screenshots, logs or description]

Actual result (*)

  1. [Screenshots, logs or description]
@ihor-sviziev ihor-sviziev changed the title No ability to not send logs to meta No ability to prevent logs sending from Meta Extension to meta Sep 27, 2023
@zlik
Copy link
Contributor

zlik commented Oct 3, 2023

@nrostrow-meta

@nrostrow-meta
Copy link
Contributor

nrostrow-meta commented Oct 3, 2023

@ihor-sviziev There currently is the ability to prevent the exception logs from being sent to Meta. Though it might not be adequate so please let me know if so. The logExceptionImmediatelyToMeta function just adds 'log_type' to the context and then calls the logException function. The logException function has a check for if sending logs to Meta is enabled and if it's not enabled then the log is just made locally and is not added to the queue to be persisted to Meta.

// If the log type is not set or Meta extension logging is not enabled just log the error message and trace.
if (!isset($context['log_type']) || !$this->systemConfig->isMetaExceptionLoggingEnabled()) {
$this->logger->error($errorMessage);
$this->logger->error($exceptionTrace);
return;
}

Enabling/disabling persisting exception logs to Meta can be controlled by updating the meta_exception_logging_enabled config value.

<meta_exception_logging_enabled>1</meta_exception_logging_enabled>

Currently this config value isn't shown in the UI though and can only be modified in code. By default the value is set to true to enable persisting exception logs to Meta. The reason for this is that the exception logging is pretty critical for us to be able to identify and diagnose issues with the extension so we were afraid that if we showed it in the UI that sellers would turn it off by default.

<field id="meta_exception_logging_enabled" type="select" sortOrder="40" showInDefault="1"
showInWebsite="0" showInStore="1">
<config_path>facebook/business_extension/meta_exception_logging_enabled</config_path>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<frontend_model>Meta\BusinessExtension\Block\Adminhtml\System\Config\Field\Hidden</frontend_model>
</field>

Is this acceptable or does disabling sending exception logs to Meta need to be prevalent in the UI? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants