Skip to content

Conversation

@AsakerMohd
Copy link
Contributor

@AsakerMohd AsakerMohd commented Jul 10, 2025

Description:

Currently, there isn't any implementation of the AWS X-Ray Remote Sampler that allows customers to fetch their sampling rules and sample accordingly. This PR adds the implementation for that sampler. The customer is able to configure their sampling rules through AWS CloudWatch: https://docs.aws.amazon.com/xray/latest/devguide/xray-console-sampling.html. This implementation fetches the sampling rules using a set polling interval which is set when creating a new instance of AWSXRayRemoteSampler. This implementation is based on similar sampler implementations in other OTEL languages.

The sampling rule has two components: a reservoir and a fixed sampling rate. The idea here is once the sampling rule is matched and the reservoir is exhausted, the spans are sampled at a fixed rate according to their trace ids. As a result, the remote sampler samples the spans using two samplers: A reservoir sampler and a fixed rate sampler and chooses which one according to the reservoir quota.

Testing:

Unit Testing:

Wrote unit tests for the major classes to assert for correctness and they're all passing.

Manual Testing:

Wrote a sample app with manual instrumentation and hooked up the X-Ray Sampler to the Tracer. I then verified that requests are being sampled as expected using different sampling rules.

@AsakerMohd AsakerMohd requested a review from a team as a code owner July 10, 2025 07:58
@codecov
Copy link

codecov bot commented Jul 10, 2025

Codecov Report

❌ Patch coverage is 78.23344% with 69 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.05%. Comparing base (30ed261) to head (b222507).
⚠️ Report is 22 commits behind head on main.

Files with missing lines Patch % Lines
src/Sampler/Xray/src/AWSXRayRemoteSampler.php 66.17% 23 Missing ⚠️
src/Sampler/Xray/src/RulesCache.php 59.18% 20 Missing ⚠️
src/Sampler/Xray/src/SamplingRuleApplier.php 91.75% 8 Missing ⚠️
src/Sampler/Xray/src/FallbackSampler.php 30.00% 7 Missing ⚠️
src/Sampler/Xray/src/RateLimitingSampler.php 25.00% 6 Missing ⚠️
src/Sampler/Xray/src/Matcher.php 81.25% 3 Missing ⚠️
src/Sampler/Xray/src/SamplingRule.php 71.42% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #405      +/-   ##
============================================
+ Coverage     79.35%   83.05%   +3.70%     
- Complexity     1262     1517     +255     
============================================
  Files           109      108       -1     
  Lines          5434     5997     +563     
============================================
+ Hits           4312     4981     +669     
+ Misses         1122     1016     -106     
Flag Coverage Δ
Aws 93.41% <ø> (+0.82%) ⬆️
Context/Swoole 0.00% <ø> (ø)
Exporter/Instana 49.42% <ø> (ø)
Instrumentation/AwsSdk 81.13% <ø> (ø)
Instrumentation/CakePHP 20.40% <ø> (ø)
Instrumentation/CodeIgniter 73.98% <ø> (+0.43%) ⬆️
Instrumentation/Curl 87.66% <ø> (-2.77%) ⬇️
Instrumentation/Doctrine 92.92% <ø> (ø)
Instrumentation/ExtAmqp 88.48% <ø> (ø)
Instrumentation/ExtRdKafka 86.11% <ø> (ø)
Instrumentation/Guzzle 75.58% <ø> (ø)
Instrumentation/HttpAsyncClient 78.04% <ø> (ø)
Instrumentation/IO 70.68% <ø> (ø)
Instrumentation/Laravel ?
Instrumentation/MongoDB ?
Instrumentation/MySqli 95.81% <ø> (ø)
Instrumentation/OpenAIPHP 87.21% <ø> (?)
Instrumentation/PDO 94.21% <ø> (ø)
Instrumentation/PostgreSql 93.54% <ø> (?)
Instrumentation/Psr14 76.47% <ø> (ø)
Instrumentation/Psr15 89.15% <ø> (ø)
Instrumentation/Psr16 97.50% <ø> (ø)
Instrumentation/Psr18 77.46% <ø> (ø)
Instrumentation/Psr3 67.01% <ø> (ø)
Instrumentation/Psr6 97.61% <ø> (?)
Instrumentation/ReactPHP 99.45% <ø> (ø)
Instrumentation/Slim 86.11% <ø> (ø)
Instrumentation/Symfony 84.88% <ø> (ø)
Instrumentation/Yii 77.86% <ø> (?)
Logs/Monolog 100.00% <ø> (ø)
Propagation/CloudTrace 89.77% <ø> (?)
Propagation/Instana 98.11% <ø> (?)
Propagation/ServerTiming 100.00% <ø> (?)
Propagation/TraceResponse 100.00% <ø> (ø)
ResourceDetectors/Azure 91.66% <ø> (ø)
ResourceDetectors/Container 93.02% <ø> (?)
ResourceDetectors/DigitalOcean 100.00% <ø> (?)
Sampler/RuleBased 33.51% <ø> (ø)
Sampler/Xray 78.23% <78.23%> (?)
Shims/OpenTracing 92.45% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/Sampler/Xray/src/AWSXRaySamplerClient.php 100.00% <100.00%> (ø)
src/Sampler/Xray/src/RateLimiter.php 100.00% <100.00%> (ø)
...rc/Sampler/Xray/src/SamplingStatisticsDocument.php 100.00% <100.00%> (ø)
src/Sampler/Xray/src/SamplingRule.php 71.42% <71.42%> (ø)
src/Sampler/Xray/src/Matcher.php 81.25% <81.25%> (ø)
src/Sampler/Xray/src/RateLimitingSampler.php 25.00% <25.00%> (ø)
src/Sampler/Xray/src/FallbackSampler.php 30.00% <30.00%> (ø)
src/Sampler/Xray/src/SamplingRuleApplier.php 91.75% <91.75%> (ø)
src/Sampler/Xray/src/RulesCache.php 59.18% <59.18%> (ø)
src/Sampler/Xray/src/AWSXRayRemoteSampler.php 66.17% <66.17%> (ø)

... and 45 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 30ed261...b222507. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@brettmc
Copy link
Contributor

brettmc commented Aug 25, 2025

Please add .gitsplit config so it can be published

@brettmc brettmc merged commit da7a997 into open-telemetry:main Aug 27, 2025
210 of 325 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants