Skip to content

Commit

Permalink
Merge pull request #133 from humanmade/add-aws-xray-params-via-filter
Browse files Browse the repository at this point in the history
Log remote requests made by the AWS SDK
  • Loading branch information
roborourke authored Feb 19, 2020
2 parents d235cb9 + c67ba3e commit 12d660f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
29 changes: 29 additions & 0 deletions inc/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use const Altis\ROOT_DIR;
use function Altis\get_config as get_platform_config;
use function Altis\get_environment_architecture;
use function HM\Platform\XRay\on_aws_guzzle_request_stats;
use GuzzleHttp\TransferStats;
use HM\Platform\XRay;

/**
Expand Down Expand Up @@ -427,3 +429,30 @@ function remove_xray_metadata( array $metadata ) : array {

return $metadata;
}

/**
* Add the XRay logging callback to the AWS SDK HTTP configuration.
*
* @param array $params AWS SDK parameters.
* @return array
*/
function add_aws_sdk_xray_callback( array $params ) : array {
$params['stats'] = true;
$params['http']['on_stats'] = __NAMESPACE__ . '\\on_request_stats';
return $params;
}

/**
* Callback function for GuzzleHTTP's `on_stats` param.
*
* This allows us to send all AWS SDK requests to xray
*
* @param TransferStats $stats
*/
function on_request_stats( TransferStats $stats ) {
if ( ! function_exists( 'HM\\Platform\\XRay\\on_aws_guzzle_request_stats' ) ) {
return;
}

on_aws_guzzle_request_stats( $stats );
}
6 changes: 6 additions & 0 deletions load.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use function Altis\get_environment_architecture;
use function Altis\register_module;
use function HM\Platform\XRay\on_hm_platform_aws_sdk_params;

add_action( 'altis.modules.init', function () {
$is_cloud = in_array( get_environment_architecture(), [ 'ec2', 'ecs' ], true );
Expand Down Expand Up @@ -39,3 +40,8 @@

register_module( 'cloud', __DIR__, 'Cloud', $default_settings, __NAMESPACE__ . '\\bootstrap' );
} );

// Early hook for logging AWS SDK HTTP requests.
add_filter( 'altis.aws_sdk.params', __NAMESPACE__ . '\\add_aws_sdk_xray_callback' );
add_filter( 's3_uploads_s3_client_params', __NAMESPACE__ . '\\add_aws_sdk_xray_callback' );
add_filter( 'aws_ses_wp_mail_ses_client_params', __NAMESPACE__ . '\\add_aws_sdk_xray_callback' );

0 comments on commit 12d660f

Please sign in to comment.