Skip to content

Commit f9174d2

Browse files
committed
updated after running style checks
1 parent 21e9312 commit f9174d2

16 files changed

+160
-275
lines changed

src/Sampler/Xray/src/AWSXRayRemoteSampler.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
<?php
2+
3+
declare(strict_types=1);
24
// src/Sampler/AWS/AWSXRayRemoteSampler.php
35

46
namespace OpenTelemetry\Contrib\Sampler\Xray;
57

68
use DateTimeImmutable;
79
use Exception;
8-
use OpenTelemetry\SDK\Trace\Sampler\ParentBased;
910
use OpenTelemetry\Context\ContextInterface;
1011
use OpenTelemetry\SDK\Common\Attribute\AttributesInterface;
11-
use OpenTelemetry\SDK\Trace\SamplerInterface;
1212
use OpenTelemetry\SDK\Resource\ResourceInfo;
13+
use OpenTelemetry\SDK\Trace\Sampler\ParentBased;
14+
use OpenTelemetry\SDK\Trace\SamplerInterface;
1315
use OpenTelemetry\SDK\Trace\SamplingResult;
1416

15-
16-
class AWSXRayRemoteSampler implements SamplerInterface {
17+
class AWSXRayRemoteSampler implements SamplerInterface
18+
{
1719
private SamplerInterface $root;
1820
public function __construct(
1921
ResourceInfo $resource,
20-
string $host,
21-
int $rulePollingIntervalMillis = 60
22+
string $host,
23+
int $rulePollingIntervalMillis = 60
2224
) {
2325
$this->root = new ParentBased(new _AWSXRayRemoteSampler($resource, $host, $rulePollingIntervalMillis));
2426
}
@@ -30,8 +32,7 @@ public function shouldSample(
3032
int $spanKind,
3133
AttributesInterface $attributes,
3234
array $links,
33-
): SamplingResult
34-
{
35+
): SamplingResult {
3536
return $this->root->shouldSample($parentContext, $traceId, $spanName, $spanKind, $attributes, $links);
3637
}
3738

@@ -76,8 +77,8 @@ class _AWSXRayRemoteSampler implements SamplerInterface
7677
*/
7778
public function __construct(
7879
ResourceInfo $resource,
79-
string $awsProxyEndpoint = self::DEFAULT_AWS_PROXY_ENDPOINT,
80-
int $pollingInterval = self::DEFAULT_RULES_POLLING_INTERVAL_SECONDS
80+
string $awsProxyEndpoint = self::DEFAULT_AWS_PROXY_ENDPOINT,
81+
int $pollingInterval = self::DEFAULT_RULES_POLLING_INTERVAL_SECONDS
8182
) {
8283
$this->clock = new Clock();
8384
$this->fallback = new FallbackSampler();
@@ -108,8 +109,8 @@ public function __construct(
108109

109110
// 2) Schedule next fetch times with jitter
110111
$now = $this->clock->now();
111-
$this->nextRulesFetchTime = $now->modify('+ '.$this->rulePollingJitterMillis + $this->rulePollingIntervalMillis.' milliseconds');
112-
$this->nextTargetFetchTime = $now->modify('+ '.$this->targetPollingJitterMillis + $this->targetPollingIntervalMillis.' milliseconds');
112+
$this->nextRulesFetchTime = $now->modify('+ ' . $this->rulePollingJitterMillis + $this->rulePollingIntervalMillis . ' milliseconds');
113+
$this->nextTargetFetchTime = $now->modify('+ ' . $this->targetPollingJitterMillis + $this->targetPollingIntervalMillis . ' milliseconds');
113114
}
114115

115116
/**
@@ -122,8 +123,7 @@ public function shouldSample(
122123
int $spanKind,
123124
AttributesInterface $attributes,
124125
array $links,
125-
): SamplingResult
126-
{
126+
): SamplingResult {
127127
$now = $this->clock->now();
128128

129129
// 1) Refresh rules if needed
@@ -166,7 +166,7 @@ public function shouldSample(
166166

167167
$nextTargetFetchInterval = $nextTargetFetchInterval * 1000;
168168

169-
$this->nextTargetFetchTime = $now->modify('+ '.$this->targetPollingJitterMillis + $nextTargetFetchInterval.' milliseconds');
169+
$this->nextTargetFetchTime = $now->modify('+ ' . $this->targetPollingJitterMillis + $nextTargetFetchInterval . ' milliseconds');
170170

171171
}
172172

@@ -175,6 +175,7 @@ public function shouldSample(
175175
if ($this->rulesCache->expired()) {
176176
return $this->fallback->shouldSample($parentContext, $traceId, $spanName, $spanKind, $attributes, $links);
177177
}
178+
178179
// delegate
179180
return $this->rulesCache->shouldSample($parentContext, $traceId, $spanName, $spanKind, $attributes, $links);
180181
}
@@ -187,7 +188,7 @@ private function getAndUpdateRules(DateTimeImmutable $now)
187188
} catch (Exception $e) {
188189
// ignore error
189190
}
190-
$this->nextRulesFetchTime = $now->modify('+ '.$this->rulePollingJitterMillis + $this->rulePollingIntervalMillis.' milliseconds');
191+
$this->nextRulesFetchTime = $now->modify('+ ' . $this->rulePollingJitterMillis + $this->rulePollingIntervalMillis . ' milliseconds');
191192
}
192193

193194
public function getDescription(): string

src/Sampler/Xray/src/AWSXRaySamplerClient.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
3+
declare(strict_types=1);
24
// src/Sampler/AWS/AWSXRaySamplerClient.php
35

46
namespace OpenTelemetry\Contrib\Sampler\Xray;
@@ -32,8 +34,8 @@ public function __construct(string $host)
3234
/**
3335
* Fetches all sampling rules from X-Ray by paging through NextToken.
3436
*
35-
* @return SamplingRule[] Array of SamplingRule instances.
3637
* @throws GuzzleException on HTTP errors.
38+
* @return SamplingRule[] Array of SamplingRule instances.
3739
*/
3840
public function getSamplingRules(): array
3941
{
@@ -68,8 +70,8 @@ public function getSamplingRules(): array
6870
* Sends current statistics documents to X-Ray and returns the decoded response.
6971
*
7072
* @param SamplingStatisticsDocument[] $statistics
71-
* @return object|null stdClass of the X-Ray GetSamplingTargets response.
7273
* @throws GuzzleException on HTTP errors.
74+
* @return object|null stdClass of the X-Ray GetSamplingTargets response.
7375
*/
7476
public function getSamplingTargets(array $statistics): ?object
7577
{

src/Sampler/Xray/src/Clock.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
2+
3+
declare(strict_types=1);
24
// src/Sampler/AWS/Clock.php
5+
36
namespace OpenTelemetry\Contrib\Sampler\Xray;
47

58
class Clock

src/Sampler/Xray/src/FallbackSampler.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
2+
3+
declare(strict_types=1);
24
// src/Sampler/AWS/FallbackSampler.php
5+
36
namespace OpenTelemetry\Contrib\Sampler\Xray;
47

58
use OpenTelemetry\Context\ContextInterface;
@@ -31,6 +34,7 @@ public function shouldSample(
3134
if ($res->getDecision() !== SamplingResult::DROP) {
3235
return $res;
3336
}
37+
3438
return $this->fixedRate->shouldSample($parentContext, $traceId, $spanName, $spanKind, $attributes, $links);
3539
}
3640

src/Sampler/Xray/src/Matcher.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace OpenTelemetry\Contrib\Sampler\Xray;
46

57
class Matcher
@@ -25,6 +27,7 @@ public static function attributeMatch(?array $tags, array $attributes): bool
2527
return false;
2628
}
2729
}
30+
2831
return true;
2932
}
3033

@@ -41,6 +44,7 @@ public static function wildcardMatch(?string $value, string $pattern): bool
4144
}
4245
// escape regex, then replace \* with .*
4346
$regex = '/^' . str_replace('\*', '.*', preg_quote($pattern, '/')) . '$/';
47+
4448
return (bool) preg_match($regex, $value);
4549
}
4650

src/Sampler/Xray/src/RateLimitingSampler.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
3+
declare(strict_types=1);
24
// src/Sampler/AWS/RateLimitingSampler.php
35

46
namespace OpenTelemetry\Contrib\Sampler\Xray;
@@ -31,8 +33,7 @@ public function shouldSample(
3133
int $spanKind,
3234
AttributesInterface $attributes,
3335
array $links,
34-
): SamplingResult
35-
{
36+
): SamplingResult {
3637
if ($this->limiter->tryAcquire()) {
3738
return new SamplingResult(SamplingResult::RECORD_AND_SAMPLE, [], null);
3839
}

src/Sampler/Xray/src/RulesCache.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<?php
2+
3+
declare(strict_types=1);
24
// src/Sampler/AWS/RulesCache.php
5+
36
namespace OpenTelemetry\Contrib\Sampler\Xray;
47

58
use OpenTelemetry\Context\ContextInterface;
69
use OpenTelemetry\SDK\Common\Attribute\AttributesInterface;
10+
use OpenTelemetry\SDK\Resource\ResourceInfo;
711
use OpenTelemetry\SDK\Trace\SamplerInterface;
812
use OpenTelemetry\SDK\Trace\SamplingResult;
9-
use OpenTelemetry\SDK\Resource\ResourceInfo;
1013

1114
class RulesCache implements SamplerInterface
1215
{
@@ -36,14 +39,15 @@ public function expired(): bool
3639

3740
public function updateRules(array $newRules): void
3841
{
39-
usort($newRules, fn(SamplingRule $a, SamplingRule $b) => $a->compareTo($b));
42+
usort($newRules, fn (SamplingRule $a, SamplingRule $b) => $a->compareTo($b));
4043
$newAppliers = [];
4144
foreach ($newRules as $rule) {
4245
// reuse existing applier if same ruleName
4346
$found = null;
4447
foreach ($this->appliers as $ap) {
4548
if ($ap->getRuleName() === $rule->RuleName) {
4649
$found = $ap;
50+
4751
break;
4852
}
4953
}
@@ -64,26 +68,27 @@ public function shouldSample(
6468
int $spanKind,
6569
AttributesInterface $attributes,
6670
array $links,
67-
): SamplingResult
68-
{
71+
): SamplingResult {
6972
foreach ($this->appliers as $applier) {
7073
if ($applier->matches($attributes, $this->resource)) {
7174
return $applier->shouldSample($parentContext, $traceId, $spanName, $spanKind, $attributes, $links);
7275
}
7376
}
77+
7478
// fallback if no rule matched
7579
return $this->fallbackSampler->shouldSample($parentContext, $traceId, $spanName, $spanKind, $attributes, $links);
7680
}
7781

7882
public function nextTargetFetchTime(): \DateTimeImmutable
7983
{
80-
$defaultPollingTime = $this->clock->now()->add(new \DateInterval('PT'.self::DEFAULT_TARGET_INTERVAL_SEC.'S'));
84+
$defaultPollingTime = $this->clock->now()->add(new \DateInterval('PT' . self::DEFAULT_TARGET_INTERVAL_SEC . 'S'));
8185

8286
if (empty($this->appliers)) {
8387
return $defaultPollingTime;
8488
}
85-
$times = array_map(fn($a) => $a->getNextSnapshotTime(), $this->appliers);
89+
$times = array_map(fn ($a) => $a->getNextSnapshotTime(), $this->appliers);
8690
$min = min($times);
91+
8792
return $min < $this->clock->now()
8893
? $defaultPollingTime
8994
: $min;
@@ -109,7 +114,6 @@ public function getAppliers(): array
109114
return $this->appliers;
110115
}
111116

112-
113117
public function getDescription(): string
114118
{
115119
return 'RulesCache';

src/Sampler/Xray/src/SamplingRule.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
2+
3+
declare(strict_types=1);
24
// src/Sampler/AWS/SamplingRule.php
5+
36
namespace OpenTelemetry\Contrib\Sampler\Xray;
47

58
class SamplingRule implements \JsonSerializable
@@ -19,17 +22,17 @@ class SamplingRule implements \JsonSerializable
1922

2023
public function __construct(
2124
string $ruleName,
22-
int $priority,
23-
float $fixedRate,
24-
int $reservoirSize,
25+
int $priority,
26+
float $fixedRate,
27+
int $reservoirSize,
2528
string $host,
2629
string $httpMethod,
2730
string $resourceArn,
2831
string $serviceName,
2932
string $serviceType,
3033
string $urlPath,
31-
int $version,
32-
array $attributes = []
34+
int $version,
35+
array $attributes = []
3336
) {
3437
$this->RuleName = $ruleName;
3538
$this->Priority = $priority;
@@ -53,6 +56,7 @@ public function jsonSerialize(): array
5356
public function compareTo($other): int
5457
{
5558
$cmp = $this->Priority <=> $other->Priority;
59+
5660
return $cmp !== 0 ? $cmp : strcmp($this->RuleName, $other->RuleName);
5761
}
5862
}

0 commit comments

Comments
 (0)