Skip to content

Commit

Permalink
feat: add extended metrics metadata (#222)
Browse files Browse the repository at this point in the history
Co-authored-by: Rikudou_Sage <[email protected]>
  • Loading branch information
sighphyre and RikudouSage authored Jul 29, 2024
1 parent e10aed9 commit f178a77
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Client/DefaultRegistrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public function register(iterable $strategyHandlers): bool
'strategies' => array_map(fn (StrategyHandler $strategyHandler): string => $strategyHandler->getStrategyName(), $strategyHandlers),
'started' => (new DateTimeImmutable())->format('c'),
'interval' => $this->configuration->getMetricsInterval(),
'platformName' => PHP_SAPI,
'platformVersion' => PHP_VERSION,
'yggdrasilVersion' => null,
'specVersion' => Unleash::SPECIFICATION_VERSION,
], JSON_THROW_ON_ERROR)));
foreach ($this->configuration->getHeaders() as $name => $value) {
$request = $request->withHeader($name, $value);
Expand Down
5 changes: 5 additions & 0 deletions src/Metrics/DefaultMetricsSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Psr\Http\Message\RequestFactoryInterface;
use Unleash\Client\Configuration\UnleashConfiguration;
use Unleash\Client\Helper\StringStream;
use Unleash\Client\Unleash;

final readonly class DefaultMetricsSender implements MetricsSender
{
Expand All @@ -32,6 +33,10 @@ public function sendMetrics(MetricsBucket $bucket): void
'appName' => $this->configuration->getAppName(),
'instanceId' => $this->configuration->getInstanceId(),
'bucket' => $bucket->jsonSerialize(),
'platformName' => PHP_SAPI,
'platformVersion' => PHP_VERSION,
'yggdrasilVersion' => null,
'specVersion' => Unleash::SPECIFICATION_VERSION,
], JSON_THROW_ON_ERROR)));
foreach ($this->configuration->getHeaders() as $name => $value) {
$request = $request->withHeader($name, $value);
Expand Down
3 changes: 2 additions & 1 deletion src/Repository/DefaultUnleashRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Unleash\Client\Exception\HttpResponseException;
use Unleash\Client\Exception\InvalidValueException;
use Unleash\Client\Helper\Url;
use Unleash\Client\Unleash;

/**
* @phpstan-type ConstraintArray array{
Expand Down Expand Up @@ -511,7 +512,7 @@ private function fetchFeatures(): array
->createRequest('GET', (string) Url::appendPath($this->configuration->getUrl(), 'client/features'))
->withHeader('UNLEASH-APPNAME', $this->configuration->getAppName())
->withHeader('UNLEASH-INSTANCEID', $this->configuration->getInstanceId())
->withHeader('Unleash-Client-Spec', '4.3.2');
->withHeader('Unleash-Client-Spec', Unleash::SPECIFICATION_VERSION);

foreach ($this->configuration->getHeaders() as $name => $value) {
$request = $request->withHeader($name, $value);
Expand Down
2 changes: 2 additions & 0 deletions src/Unleash.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ interface Unleash
{
public const string SDK_VERSION = '2.5.1';

public const string SPECIFICATION_VERSION = '4.3.2';

public function isEnabled(string $featureName, ?Context $context = null, bool $default = false): bool;

public function getVariant(string $featureName, ?Context $context = null, ?Variant $fallbackVariant = null): Variant;
Expand Down

0 comments on commit f178a77

Please sign in to comment.