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 7 commits into
base: main
Choose a base branch
from

Conversation

Tymek
Copy link
Member

@Tymek Tymek commented Jan 21, 2025

Description

Identification headers consistent with other Unleash SDKs.

This PR adds standardized client identification headers to the feature and metrics calls that the client makes to Unleash. The headers are:

  • x-unleash-appname: the name of the application that is using the client. UNLEASH-APPNAME will be deleted in another PR (expand/contract pattern)
  • x-unleash-connection-id: an internal unique identifier for the current instance of the client generated by the built-in crypto lib
  • x-unleash-sdk: sdk information in the format unleash-client-<language>:<version>

All the headers are intended for the Unleash team. Changes should be implemented in a way that does not change SDK behavior in a significant way.
The main use cases we have are:

  • capacity planning by knowing the number of unique connections made to the backend API
  • debugging misconfigured SDKs sending more traffic than expected

Reference implementation (work in progress): Unleash/unleash-client-node#690

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

  • Unit tests
  • Spec Tests
  • Integration tests / Manual Tests

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@Tymek
Copy link
Member Author

Tymek commented Jan 21, 2025

It's still a draft. I'm working on test coverage.

@Tymek Tymek requested a review from kwasniew January 21, 2025 15:16
@@ -510,6 +513,7 @@ private function fetchFeatures(): array
} else {
$request = $this->requestFactory
->createRequest('GET', (string) Url::appendPath($this->configuration->getUrl(), 'client/features'))
// TODO: remove non-standard headers
Copy link
Member Author

@Tymek Tymek Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe after some time, for example in a next major version

@@ -54,7 +57,7 @@ public function register(iterable $strategyHandlers): bool
'appName' => $this->configuration->getAppName(),
'instanceId' => $this->configuration->getInstanceId(),
'sdkVersion' => $this->sdkName . ':' . $this->sdkVersion,
'strategies' => array_map(fn (StrategyHandler $strategyHandler): string => $strategyHandler->getStrategyName(), $strategyHandlers),
'strategies' => array_map(fn(StrategyHandler $strategyHandler): string => $strategyHandler->getStrategyName(), $strategyHandlers),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linter auto-formatted

@@ -69,6 +70,8 @@ final class UnleashBuilder

private ?string $appName = null;

private string $connectionId = Uuid::v4();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to suggestions of there is a better way of having connectionId created only during initialization, and reuse it (alongside with SDK name and version) in both registration and getFeatures calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants