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

feat: client identification headers #232

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
14 changes: 12 additions & 2 deletions src/Client/DefaultRegistrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,24 @@
use Unleash\Client\Enum\CacheKey;
use Unleash\Client\Helper\StringStream;
use Unleash\Client\Helper\Url;
use Unleash\Client\Helper\Uuid;
use Unleash\Client\Strategy\StrategyHandler;
use Unleash\Client\Unleash;

final class DefaultRegistrationService implements RegistrationService
{
private string $connectionId;

public function __construct(
private readonly ClientInterface $httpClient,
private readonly RequestFactoryInterface $requestFactory,
private readonly UnleashConfiguration $configuration,
private ?string $sdkName = null,
private ?string $sdkVersion = null,
) {
$this->sdkName ??= 'unleash-client-php';
$this->sdkName ??= 'unleash-php';
$this->sdkVersion ??= Unleash::SDK_VERSION;
$this->connectionId = Uuid::v4();
}

/**
Expand All @@ -51,9 +55,15 @@ public function register(iterable $strategyHandlers): bool
->createRequest('POST', (string) Url::appendPath($this->configuration->getUrl(), 'client/register'))
->withHeader('Content-Type', 'application/json')
->withBody(new StringStream(json_encode([
// TODO: delete non-standard redundant headers
'appName' => $this->configuration->getAppName(),
'instanceId' => $this->configuration->getInstanceId(),
'sdkVersion' => $this->sdkName . ':' . $this->sdkVersion,
'sdkVersion' => 'unleash-client-php:' . $this->sdkVersion,
Tymek marked this conversation as resolved.
Show resolved Hide resolved

'x-unleash-appname' => $this->configuration->getAppName(),
'x-unleash-sdk' => $this->sdkName . '@' . $this->sdkVersion,
'x-unleash-connection-id' => $this->connectionId,

'strategies' => array_map(fn (StrategyHandler $strategyHandler): string => $strategyHandler->getStrategyName(), $strategyHandlers),
'started' => (new DateTimeImmutable())->format('c'),
'interval' => $this->configuration->getMetricsInterval(),
Expand Down
Loading