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

Added ability to filter incoming requests #45

Merged
merged 8 commits into from
Dec 27, 2023

Conversation

nicDamours
Copy link
Contributor

Summary

Added the ability to filter incoming requests, in case some of them doesn't have to be capture in Amazon Xray. This can be useful to reduce noise when using a health check url.

To add a new filter, simply call the addRequestFilterCallback function, on the Xray facade, and pass a callback. The current request will be evaluated against this callback. If the callback returns false, the XrayServiceProvider will return before registering the collectors.

I've added informations about this new feature in the doc. If you could, kindly, review the doc to make sure I havn't done any grammatical errors, I would highly appreciate it. English is not my primary language.

I've also added tests for the newly added behaviour.

Closes #44

Steps to tests.

  1. Load a project with the library and connect it to Amazon XRay.
  2. In your AppServiceProvider, add a new filter, in the register function, like so:
use Napp\Xray\Facades\Xray;
use Symfony\Component\HttpFoundation\Request;

class AppServiceProvider extends ServiceProvider
{
    public function register()
    {
        Xray::addRequestFilterCallback(function (Request $request) {
            return $request->getRequestUri() !== '/some/url';
        });
    } 
}
  1. call the url you don't want to capture, a couple time, so it would have been sent to Amazon Xray
  2. call another url that is not filtered out.
  3. Only the request that is not filtered out should be capture in Amazon Xray.

Nicolas D'Amours added 8 commits November 1, 2023 11:21
Changed `getCallerClass`, on Backtracer trait to return null if the backtrace is empty.
Changed DatebaseQueryCollector and CacheCollector to add '(too deeply nested)' to their respective segment name, if the caller name is deeper than 50 calls in the backtrace.

Added tests for all affected classes.
Applied suggested diff.
WIP: working on adding support to filter request to capture.
Finished adding support to filter requests.
Added new filtering option to the doc.
Added `addRequestFilterCallback` as an available function on the Xray facade.
Changed XrayServiceProvider to check request in the `boot` function rather than the `registerCollectors`.
@viezel viezel merged commit 2e7176b into Napp:master Dec 27, 2023
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.

Allow request filtering
2 participants