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

Conversation

roborourke
Copy link
Contributor

@roborourke roborourke commented May 10, 2023

This solves the issue of the filter not being available for the first trace sent which happens prior to WP bootstrapping.

Usage:

// In .config/load-early.php
$xray_redact_keys = [ '$_POST' => [ 'key1', 'key2' ] ];

Relates to #80

This solves the issue of the filter not being available for the first trace sent which happens prior to WP bootstrapping.

Usage:

```
$xray_redact_keys = [ $_POST => [ key, key ] ];
```
@roborourke roborourke requested a review from kovshenin May 10, 2023 15:07

$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.

Copy link
Contributor

@ivankristianto ivankristianto left a comment

Choose a reason for hiding this comment

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

Good from me 👍🏼

@kovshenin
Copy link

If everything is sent so early in the request cycle, what's the use of the aws_xray.redact_metadata_keys filter anyway? If we're providing a filter to redact keys, it should work consistently. Could we remove $_POST and other superglobals from the initial trace, and only send them later when apply_filters is available?

@roborourke
Copy link
Contributor Author

@kovshenin fair point, could remove it as part of this update? @joehoyle what was the goal with sending all the metadata with the early request too? Is it necessary?

@kovshenin
Copy link

But if we're going to remove it as part of this update, then this update is no longer necessary :) We no longer need an additional way to influence the redacting if we can use the existing filter reliably. If we do, however, need these as part of the initial X-Ray dump, then I'm fine with the global approach.

@roborourke
Copy link
Contributor Author

@kovshenin depends if we consider this a bug, if we do need the metadata in the initial trace and it's going to be backported then it should retain the filter too.

@joehoyle
Copy link
Member

The end trace can fail, so the idea is to send the data with the in_progress trace as a "get the data tracked as reliably as possible". I wonder if actually though we should look at just loading xray after the user's altis config has been loaded. I don't see much downside with doing that, as it's unlikely to impact request timing too much.

@rmccue
Copy link
Member

rmccue commented May 16, 2023

I wonder if actually though we should look at just loading xray after the user's altis config has been loaded. I don't see much downside with doing that, as it's unlikely to impact request timing too much.

Presumably we're also starting the Excimer profile at that point though, so we'd miss flamegraph data for anything before that?

@joehoyle
Copy link
Member

Yes, though the "distance" between when we currently load it vs after the config is very small I think. Hence I think it's a small tradeoff

@rmccue
Copy link
Member

rmccue commented May 16, 2023

Presumably we can do something a bit more nuanced though: start Excimer as soon as possible, but defer the first push of metadata until we've loaded those early bits.

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

Successfully merging this pull request may close these issues.

5 participants