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
2 changes: 1 addition & 1 deletion includes/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function load_checkout_permalink_template( $template ) {
);
}
} else {
\WC_Facebookcommerce_Utils::logTelemetryToMeta(
\WC_Facebookcommerce_Utils::logToMeta(
'Failed to add product to cart',
array(
'flow_name' => 'checkout',
Expand Down
6 changes: 3 additions & 3 deletions includes/Feed/FeedUploadUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static function get_ratings_and_reviews_data( array $query_args ): array
'product.productIdentifiers.skus' => "['" . implode( "','", $product_skus ) . "']",
);
} catch ( \Exception $e ) {
\WC_Facebookcommerce_Utils::logTelemetryToMeta(
\WC_Facebookcommerce_Utils::logToMeta(
'Exception while trying to map product review data for feed',
array(
'flow_name' => self::RATINGS_AND_REVIEWS_SYNC_LOGGING_FLOW_NAME,
Expand Down Expand Up @@ -145,7 +145,7 @@ public static function get_coupons_data( array $query_args ): array {
$value_type = self::VALUE_TYPE_FIXED_AMOUNT;
$fixed_amount_off = $coupon->get_amount(); // TODO we may want to pass in optional currency code for multinational support
} else {
\WC_Facebookcommerce_Utils::logTelemetryToMeta(
\WC_Facebookcommerce_Utils::logToMeta(
'Unknown discount type encountered during feed processing',
array(
'promotion_id' => $coupon_post->ID,
Expand Down Expand Up @@ -238,7 +238,7 @@ public static function get_coupons_data( array $query_args ): array {

$coupons_data[] = $data;
} catch ( \Exception $e ) {
\WC_Facebookcommerce_Utils::logTelemetryToMeta(
\WC_Facebookcommerce_Utils::logToMeta(
'Exception while trying to get coupon data for feed',
array(
'promotion_id' => $coupon_post->ID,
Expand Down
20 changes: 10 additions & 10 deletions includes/Framework/BatchLogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BatchLogHandler extends LogHandlerBase {
* @since 3.5.0
*/
public function __construct() {
add_action( Heartbeat::EVERY_5_MINUTES, array( $this, 'process_telemetry_logs_batch' ) );
add_action( Heartbeat::EVERY_5_MINUTES, array( $this, 'process_logs_batch' ) );
}

/**
Expand All @@ -39,9 +39,9 @@ public function __construct() {
*
* @since 3.5.0
*/
public function process_telemetry_logs_batch() {
if ( get_transient( 'global_telemetry_message_queue' ) !== false && ! empty( get_transient( 'global_telemetry_message_queue' ) ) ) {
$logs = get_transient( 'global_telemetry_message_queue' );
public function process_logs_batch() {
if ( get_transient( 'global_logging_message_queue' ) !== false && ! empty( get_transient( 'global_logging_message_queue' ) ) ) {
$logs = get_transient( 'global_logging_message_queue' );
$chunked_logs = array_chunk( $logs, 20 );

$chunked_failed_logs = array_map(
Expand All @@ -54,21 +54,21 @@ function ( $log ) {
);

$context = [
'event' => 'persist_meta_telemetry_logs',
'extra_data' => [ 'telemetry_logs' => wp_json_encode( $logs_chunk_with_core_context ) ],
'event' => 'persist_meta_logs',
'extra_data' => [ 'meta_logs' => wp_json_encode( $logs_chunk_with_core_context ) ],
];

try {
$response = facebook_for_woocommerce()->get_api()->log_to_meta( $context );
if ( $response->success ) {
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( 'Telemetry logs: ' . wp_json_encode( $context ) );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( 'Meta logs: ' . wp_json_encode( $context ) );
return [];
} else {
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( 'Bad response from log_to_meta request' );
return $logs_chunk;
}
} catch ( \Exception $e ) {
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( 'Error persisting telemetry logs: ' . $e->getMessage() );
WC_Facebookcommerce_Utils::logWithDebugModeEnabled( 'Error persisting meta logs: ' . $e->getMessage() );
return $logs_chunk;
}
},
Expand All @@ -82,11 +82,11 @@ function ( $log ) {
}

if ( ! empty( $failed_logs ) ) {
set_transient( 'global_telemetry_message_queue', $failed_logs, HOUR_IN_SECONDS );
set_transient( 'global_logging_message_queue', $failed_logs, HOUR_IN_SECONDS );
return;
}
}

set_transient( 'global_telemetry_message_queue', [], HOUR_IN_SECONDS );
set_transient( 'global_logging_message_queue', [], HOUR_IN_SECONDS );
}
}
8 changes: 4 additions & 4 deletions includes/fbutils.php
Original file line number Diff line number Diff line change
Expand Up @@ -871,21 +871,21 @@ public static function logExceptionImmediatelyToMeta(Throwable $error, array $co
}

/**
* Utility function for sending telemetry logs to Meta.
* Utility function for sending 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 = []) {
public static function logToMeta(string $message, array $context = []) {
$extra_data = self::getContextData( $context, 'extra_data', [] );
$extra_data['message'] = $message;
$context['extra_data'] = $extra_data;

// Push logging request to global message queue function.
$logs = get_transient( 'global_telemetry_message_queue' );
$logs = get_transient( 'global_logging_message_queue' );
$logs[] = $context;
set_transient( 'global_telemetry_message_queue', $logs, HOUR_IN_SECONDS );
set_transient( 'global_logging_message_queue', $logs, HOUR_IN_SECONDS );
}

/**
Expand Down