patrickkerrigan / php-xray

A PHP instrumentation library for AWS X-Ray
BSD 3-Clause "New" or "Revised" License
63 stars 26 forks source link

Custom sampling rules #10

Closed icelava closed 2 years ago

icelava commented 3 years ago

Any idea how to query X-Ray for specific predefined sampling rules?

patrickkerrigan commented 3 years ago

Currently this library doesn't have any kind of built-in support for retrieving sampling rules from X-Ray, but it should be possible to retreive them yourself using the AWS PHP SDK (with some form of caching so you don't have to do it on every request) and then call setSampled on the trace depending on the outcome of applying the rules.

https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-xray-2016-04-12.html#getsamplingrules

There was a previous attempt to add support to this library which unfortunately neither I nor the author had the time to test under a production workload, but you might be able to use it as an example of how to retrieve and apply sampling rules:

https://github.com/patrickkerrigan/php-xray/pull/3/files

icelava commented 2 years ago

Yea that seems to be AWS recommended approach too; use AWS SDK to grab all sampling rules, then apply own custom logic to pick the "preferred". Thanks.

https://forums.aws.amazon.com/thread.jspa?threadID=347394