Skip to content

feat: Process User-Agent strings#5823

Merged
khvn26 merged 4 commits intomainfrom
feat/sdk-metrics-parse-uas
Jul 25, 2025
Merged

feat: Process User-Agent strings#5823
khvn26 merged 4 commits intomainfrom
feat/sdk-metrics-parse-uas

Conversation

@khvn26
Copy link
Copy Markdown
Member

@khvn26 khvn26 commented Jul 23, 2025

Thanks for submitting a PR! Please check the boxes below:

  • I have added information to docs/ if required so people know about the feature!
  • I have filled in the "Changes" section below?
  • I have filled in the "How did you test this code" section below?
  • I have used a Conventional Commit title for this Pull Request

Changes

Closes #5735.

This adds User-Agent processing ahead of labelling the usage and feature evaluation data. Browser UA strings are stripped, the rest are considered server-side SDKs, and a new Flagsmith-SDK-User-Agent header is expected to denote a browser SDK version.

How did you test this code?

Updated existing view unit test to reflect the new behaviour.

@khvn26 khvn26 requested a review from a team as a code owner July 23, 2025 17:20
@khvn26 khvn26 requested review from emyller and removed request for a team July 23, 2025 17:20
@vercel
Copy link
Copy Markdown

vercel Bot commented Jul 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs ⬜️ Ignored (Inspect) Visit Preview Jul 23, 2025 10:51pm
flagsmith-frontend-preview ⬜️ Ignored (Inspect) Visit Preview Jul 23, 2025 10:51pm
flagsmith-frontend-staging ⬜️ Ignored (Inspect) Visit Preview Jul 23, 2025 10:51pm

@github-actions github-actions Bot added api Issue related to the REST API feature New feature or request labels Jul 23, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jul 23, 2025

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-e2e:pr-5823 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api-test:pr-5823 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api:pr-5823 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-frontend:pr-5823 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-5823 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-5823 Finished ✅ Results

@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.82%. Comparing base (c5fc2c7) to head (0b7e0d8).
Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5823   +/-   ##
=======================================
  Coverage   97.82%   97.82%           
=======================================
  Files        1258     1258           
  Lines       44729    44745   +16     
=======================================
+ Hits        43755    43771   +16     
  Misses        974      974           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@emyller emyller left a comment

Choose a reason for hiding this comment

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

Looks good in general! Let's choose a safer option to parse UAs if you agree.

Comment thread api/pyproject.toml
Comment on lines +123 to +128
elif label == "user_agent":
parsed_ua_string: str = parse_ua(value)
# Assume UA strings categorised as "Other" to represent server-side SDKs.
# Skip browser SDKs that don't send the special header.
if parsed_ua_string.split(" - ")[0] != "Other":
continue
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure what's happening here, despite the comment, sorry. I assume it's domain-specific to fastuaparser?

The alternative uap-parser (mentioned in the other thread) might offer a cleaner API, e.g.

Suggested change
elif label == "user_agent":
parsed_ua_string: str = parse_ua(value)
# Assume UA strings categorised as "Other" to represent server-side SDKs.
# Skip browser SDKs that don't send the special header.
if parsed_ua_string.split(" - ")[0] != "Other":
continue
# Assume unrecognized User Agents to represent server-side SDKs
elif label == "user_agent" and not parse_user_agent(value):
continue

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure what's happening here, despite the comment, sorry.

Let me know how can we improve the comment.

The alternative uap-parser (mentioned in the other thread) might offer a cleaner API, e.g.

Sure, but see considerations above.

Copy link
Copy Markdown
Contributor

@emyller emyller Jul 23, 2025

Choose a reason for hiding this comment

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

Let me know how can we improve the comment.

The suggested snippet includes a suggestion of comment, though its readability largely depends on not having to explain how fastuaparser works. If you're adamant in keeping fastuaparser considering my last question, I think a slightly longer comment here could help. Also, sorry, my suggestion was incomplete in respect to the "skip browser SDKs" bit.

Suggested change
elif label == "user_agent":
parsed_ua_string: str = parse_ua(value)
# Assume UA strings categorised as "Other" to represent server-side SDKs.
# Skip browser SDKs that don't send the special header.
if parsed_ua_string.split(" - ")[0] != "Other":
continue
elif label == "user_agent":
# fastuaparser classifies unrecognized UAs as "Other" — assume these to
# represent server-side SDKs.
parsed_ua_string: str = parse_ua(value)
is_server_side_sdk = parsed_ua_string.startswith("Other - ")
# Skip browser SDKs that don't send the special header
if not is_server_side_sdk:
continue

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sorry, applying the suggestion broke the logic. Fixed in 0b7e0d8, but need a re-approval now.

@khvn26 khvn26 requested a review from emyller July 23, 2025 20:57
khvn26 and others added 2 commits July 23, 2025 22:20
Co-authored-by: Evandro Myller <22429+emyller@users.noreply.github.com>
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Jul 23, 2025
emyller
emyller previously approved these changes Jul 23, 2025
Copy link
Copy Markdown
Contributor

@emyller emyller left a comment

Choose a reason for hiding this comment

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

Well let's :shipit:

@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Jul 23, 2025
@khvn26 khvn26 requested a review from emyller July 23, 2025 22:53
Copy link
Copy Markdown
Contributor

@emyller emyller left a comment

Choose a reason for hiding this comment

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

image

@khvn26 khvn26 merged commit 1411f54 into main Jul 25, 2025
29 checks passed
@khvn26 khvn26 deleted the feat/sdk-metrics-parse-uas branch July 25, 2025 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Process User-Agent strings

2 participants