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

Add support for setting redacted keys via global #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion inc/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -922,8 +922,9 @@ function get_object_cache_stats() : array {
* @return array
*/
function redact_metadata( $metadata ) {
global $xray_redact_keys;

$redact_keys_default = [];
$redact_keys_default = (array) ( $xray_redact_keys ?? [] );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roborourke Though this works, but I feel there is potential downside with the use of global variable here.
For example, it could be overridden accidentally by other code.
I'm thinking to use constant here or composer env instead? So other engineers forced to add their key from one place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A constant would have the issue of preventing other code adding to it. It would be up to application developers to check for existing keys etc... This is a pattern pretty common in WP like $batcache for instance. It isn't ideal but I think it's the best balance between flexibility, extensibility and ease of use.

If you wanted to add to this from a plugin for instance you'd use:

global $xray_redact_keys;

$xray_redact_keys = array_merge_recursive( $xray_redact_keys ?? [], [
  '$_POST' => [ '... my custom keys ...' ],
] );

This can be documented in the Altis docs.

if ( function_exists( 'apply_filters' ) ) {
$redact_keys_default = apply_filters( 'aws_xray.redact_metadata_keys', $redact_keys_default );
}
Expand Down