Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions includes/Framework/ErrorLogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,16 @@ public function __construct() {
*/
public function process_error_log( $raw_context ) {
$context = self::set_core_log_context( $raw_context );
facebook_for_woocommerce()->get_api()->log_to_meta( $context );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( 'Error log: ' . wp_json_encode( $context ) );
try {
$response = facebook_for_woocommerce()->get_api()->log_to_meta( $context );
if ( $response->success ) {
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( 'Error log: ' . wp_json_encode( $context ) );
} else {
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( 'Bad response from log_to_meta request' );
}
} catch ( \Exception $e ) {
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( 'Error persisting error logs: ' . $e->getMessage() );
}
}

/**
Expand All @@ -57,25 +65,21 @@ public function process_error_log( $raw_context ) {
* @since 3.5.0
*
* @param Throwable $error error object
* @param array $context context example: ['catalog_id' => '1234567890', 'order_id' => '1234567890',
* 'promotion_id' => '1234567890', 'flow_name' => 'checkout', 'flow_step' => 'verification',
* 'extra_data' => ['dictionary type' => 'any data that is not fall into our pre-defined format.']
* @param array $context wiki: https://www.internalfb.com/wiki/Commerce_Platform/Teams/3P_Ecosystems_(3PE)/3rd_Party_platforms/Woo_Commerce/How_To_Use_WooCommerce_Side_Logging/
*/
public static function log_exception_to_meta( Throwable $error, array $context = [] ) {
$extra_data = WC_Facebookcommerce_Utils::getContextData( $context, 'extra_data', [] );
$extra_data['php_version'] = phpversion();

$request_data = [
'event' => 'error_log',
'event' => WC_Facebookcommerce_Utils::getContextData( $context, 'event', 'error_log' ),
'event_type' => WC_Facebookcommerce_Utils::getContextData( $context, 'event_type' ),
'exception_message' => $error->getMessage(),
'exception_trace' => $error->getTraceAsString(),
'exception_code' => $error->getCode(),
'exception_class' => get_class( $error ),
'order_id' => WC_Facebookcommerce_Utils::getContextData( $context, 'order_id' ),
'promotion_id' => WC_Facebookcommerce_Utils::getContextData( $context, 'promotion_id' ),
'flow_name' => WC_Facebookcommerce_Utils::getContextData( $context, 'flow_name' ),
'flow_step' => WC_Facebookcommerce_Utils::getContextData( $context, 'flow_step' ),
'incoming_params' => WC_Facebookcommerce_Utils::getContextData( $context, 'incoming_params' ),
'extra_data' => $extra_data,
];
Expand Down
7 changes: 4 additions & 3 deletions includes/fbutils.php
Original file line number Diff line number Diff line change
Expand Up @@ -864,9 +864,7 @@ public static function prepare_product_variation_data_items_batch( $product ) {
* @since 3.5.0
*
* @param Throwable $error error object
* @param array $context context example: ['catalog_id' => '1234567890', 'order_id' => '1234567890',
* 'promotion_id' => '1234567890', 'flow_name' => 'checkout', 'flow_step' => 'verification',
* 'extra_data' => ['dictionary type' => 'any data that is not fall into our pre-defined format.']
* @param array $context wiki: https://www.internalfb.com/wiki/Commerce_Platform/Teams/3P_Ecosystems_(3PE)/3rd_Party_platforms/Woo_Commerce/How_To_Use_WooCommerce_Side_Logging/
*/
public static function logExceptionImmediatelyToMeta(Throwable $error, array $context = []) {
ErrorLogHandler::log_exception_to_meta($error, $context);
Expand All @@ -875,6 +873,9 @@ public static function logExceptionImmediatelyToMeta(Throwable $error, array $co
/**
* Utility function for sending telemetry logs to Meta.
* @since 3.5.0
*
* @param string $message
* @param array $context wiki: https://www.internalfb.com/wiki/Commerce_Platform/Teams/3P_Ecosystems_(3PE)/3rd_Party_platforms/Woo_Commerce/How_To_Use_WooCommerce_Side_Logging/
*/
public static function logTelemetryToMeta(string $message, array $context = []) {
$extra_data = self::getContextData( $context, 'extra_data', [] );
Expand Down