Skip to content

feat: send client info to Flagsmith #293

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

Merged
merged 1 commit into from
Apr 17, 2025
Merged

Conversation

tiagoapolo
Copy link
Contributor

@tiagoapolo tiagoapolo commented Mar 4, 2025

Ref: #2479

  • This pull request includes changes to the flagsmith-core.ts file to add support for appName and appVersion in the Flagsmith class.
  • Updated the getJSON method to include X-Customer-Application-Name and X-Customer-Application-Version headers if appName and appVersion are provided.
Screenshot 2025-03-04 at 15 05 54

@tiagoapolo tiagoapolo requested a review from Copilot March 4, 2025 17:38
@tiagoapolo tiagoapolo self-assigned this Mar 4, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@tiagoapolo tiagoapolo requested review from Copilot, rolodato and matthewelwell and removed request for rolodato March 4, 2025 18:07
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This pull request adds support for sending client application details (appName and appVersion) to Flagsmith through HTTP headers.

  • Updated Config type to include appName and appVersion fields.
  • Added corresponding properties and initializations to the Flagsmith class.
  • Updated getJSON to add the new headers based on the provided client info.

Reviewed Changes

File Description
flagsmith-core.ts Adds support for client info through headers and config updates

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

@tiagoapolo tiagoapolo requested a review from Copilot March 4, 2025 18:13
@khvn26
Copy link
Member

khvn26 commented Mar 4, 2025

Do we want to make the new properties a part of the shared evaluation context interface?

CC @matthewelwell @kyle-ssg

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR adds support for sending client information (appName and appVersion) to Flagsmith via HTTP headers, enhancing configuration flexibility when initializing the Flagsmith client.

  • Extended the Config type and Flagsmith class to support appName and appVersion.
  • Updated the getJSON method to send X-Customer-Application-Name and X-Customer-Application-Version headers.

Reviewed Changes

File Description
flagsmith-core.ts Updated configuration and HTTP request handling to include appName and appVersion

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

@tiagoapolo tiagoapolo requested a review from kyle-ssg March 6, 2025 10:40
@matthewelwell
Copy link
Contributor

matthewelwell commented Mar 7, 2025

Do we want to make the new properties a part of the shared evaluation context interface?

CC @matthewelwell @kyle-ssg

@khvn26 I'm not sure if these properties should be part of the evaluation context? Would we expect them to change?

@khvn26
Copy link
Member

khvn26 commented Mar 7, 2025

@matthewelwell We wouldn't during client runtime, but actually segmenting by app name and app version in evaluation could be desirable for the future?

@tiagoapolo
Copy link
Contributor Author

@matthewelwell We wouldn't during client runtime, but actually segmenting by app name and app version in evaluation could be desirable for the future?

That makes sense, we could use it the future

@matthewelwell
Copy link
Contributor

Ok, sounds good.

@khvn26 @tiagoapolo do you guys have an idea of the changes that are needed then?

@khvn26
Copy link
Member

khvn26 commented Mar 10, 2025

I've opened a PR to update the schema here: Flagsmith/flagsmith#5203

After it's merged, we'll be able to regenerate evaluation-context.ts

Copy link
Member

@rolodato rolodato left a comment

Choose a reason for hiding this comment

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

(ignore)

@tiagoapolo tiagoapolo force-pushed the feat/send-client-info-2479 branch from 086df1d to 0a24e98 Compare March 31, 2025 20:32
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request adds support for sending client information (app name and version) to Flagsmith via custom HTTP headers. Key changes include:

  • Updating the Flagsmith configuration to accept appName and appVersion.
  • Modifying the getJSON method to include the "X-Customer-Application-Name" and "X-Customer-Application-Version" headers when these values are provided.
  • Adding tests to validate that the headers are set appropriately based on provided configuration.

Reviewed Changes

Copilot reviewed 3 out of 5 changed files in this pull request and generated no comments.

File Description
test/init.test.ts Added tests to verify header inclusion and exclusion based on config; note that duplicate tests exist with the same description.
flagsmith-core.ts Extended configuration and getJSON functionality to support appName and appVersion headers.
Files not reviewed (2)
  • lib/flagsmith/package.json: Language not supported
  • lib/react-native-flagsmith/package.json: Language not supported
Comments suppressed due to low confidence (1)

test/init.test.ts:296

  • Duplicate test case detected with the same description as an earlier test (line 275). Consider merging or renaming one of the tests to ensure each test case verifies a unique scenario and to reduce potential maintenance overhead.
test('should send app name and version headers when provided', async () => {

Copy link
Member

@rolodato rolodato left a comment

Choose a reason for hiding this comment

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

The code itself looks fine, but I'm curious why we chose this approach instead of setting these attributes as traits. I can speculate as to why:

  • We don't have reserved trait names, so we can't guarantee there will not be collisions with existing customer traits. This is still a solvable problem, with some effort
  • Customers that track application attributes would always have to use the /identities endpoint (probably with transient traits), since /flags does not accept traits

My impression is that setting these attributes as traits is the better option; it has its challenges, but I don't see what we would gain by tracking them separate from traits. By using traits, every SDK (including OpenFeature) automatically supports this and we don't have to adapt clients in any way.

Another question of asking this would be - if customers want to target flags based on application name/version/platform/etc, they can do that right now with traits. What would they gain by using special headers instead? I'm sure I'm missing some context to be able to answer this question.

@tiagoapolo
Copy link
Contributor Author

tiagoapolo commented Apr 2, 2025

The code itself looks fine, but I'm curious why we chose this approach instead of setting these attributes as traits. I can speculate as to why:

  • We don't have reserved trait names, so we can't guarantee there will not be collisions with existing customer traits. This is still a solvable problem, with some effort
  • Customers that track application attributes would always have to use the /identities endpoint (probably with transient traits), since /flags does not accept traits

My impression is that setting these attributes as traits is the better option; it has its challenges, but I don't see what we would gain by tracking them separate from traits. By using traits, every SDK (including OpenFeature) automatically supports this and we don't have to adapt clients in any way.

Another question of asking this would be - if customers want to target flags based on application name/version/platform/etc, they can do that right now with traits. What would they gain by using special headers instead? I'm sure I'm missing some context to be able to answer this question.

The goal is to track usage and using headers for that case is more appropriate. Also, we don't want to store that information in traits for future evaluation for now, that can come up in a new task/PR.

cc: @matthewelwell

@tiagoapolo tiagoapolo requested a review from rolodato April 2, 2025 19:43
Copy link
Member

@rolodato rolodato left a comment

Choose a reason for hiding this comment

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

The code LGTM, but I'd like to understand more about how customers are expected to use this feature. It's difficult to judge this PR in isolation without understanding the full scope of this feature.

I also wonder if we should add a distinct identifier, separate from the application name. This would let customers rename their application "friendly name", and not be stuck forever with an outdated name.

For example, imagine if we set applicationMetadata.name: "Bullet Train", and we later want to rename this to Flagsmith. We would have to choose to either be stuck forever with this name, or lose continuity with any data collected until that point.

@matthewelwell matthewelwell removed their request for review April 15, 2025 11:19
@Zaimwa9
Copy link
Contributor

Zaimwa9 commented Apr 15, 2025

@rolodato I get your point. It would be critical when be used for traits to avoid any discontinuity in case of value change.

(I'm repeating also to confirm my understanding of the objective) In the context of gathering usage and tracking data, as long as they are informational it wouldn't bring any disruption of service to change the name of an application.
Because we have the API key on which we could rely to track [project,environment], I see this as a way to group together requests/usage of a sub-application on a given environment, answering the question:

  • For my production environment, with 4 different applications using the same key, how is my usage distributed.

So with a name change, it would cause a spike change (from bullet to flagsmith) but the actionability of the underlying data would stay the same imo ("we need to decrease our usage in this one").

I agree with you though, as soon as this is used for traits and evaluation it will need to have a persistent key over time even with name changing etc

In the context of this PR I personally think it's not blocking and it's a base for future finetuning

Copy link
Contributor

@Zaimwa9 Zaimwa9 left a comment

Choose a reason for hiding this comment

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

LGTM codewise and working as a charm on my side 👍 . Would just need to update the doc accordingly. And to monitor whether values should be validated (max nb of characters, trimming etc)
Approving if no behavioral changes related to the discussion.

image

Task: #2479

updates lib versions

remove console log

adds tests

- implement applicationMetadata object
- remove X- prefix from custom headers

fix type and test

makes applicationMetadata.version optional

updates version
@tiagoapolo tiagoapolo force-pushed the feat/send-client-info-2479 branch from 3593e59 to 3ed33bd Compare April 17, 2025 13:00
@tiagoapolo tiagoapolo merged commit 15826ca into main Apr 17, 2025
1 check passed
@tiagoapolo tiagoapolo deleted the feat/send-client-info-2479 branch April 17, 2025 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants