Skip to content

feat(flags): add Unleash feature flagging integration#3888

Merged
antonpirker merged 26 commits into
masterfrom
aliu/unleash
Jan 7, 2025
Merged

feat(flags): add Unleash feature flagging integration#3888
antonpirker merged 26 commits into
masterfrom
aliu/unleash

Conversation

@aliu39

@aliu39 aliu39 commented Dec 21, 2024

Copy link
Copy Markdown
Member

Adds an integration for tracking flag evaluations from Unleash customers.

Implementation
Unleash has no native support for evaluation hooks/listeners, unless the user opts in for each flag. Therefore we decided to patch the is_enabled and get_variant methods on the UnleashClient class. The methods are wrapped and the only side effect is writing to Sentry scope, so users shouldn't see any change in behavior.

We patch these methods on the UnleashClient class template.
We patch one UnleashClient instance instead of the whole class. The reasons for this are described in
- #3895
It's also safer to not modify the unleash import.

References

Documentation PR

@codecov

codecov Bot commented Dec 21, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 93.75000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 79.87%. Comparing base (7f73c9e) to head (95c72e9).
Report is 3 commits behind head on master.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sentry_sdk/integrations/unleash.py 93.75% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3888      +/-   ##
==========================================
+ Coverage   79.83%   79.87%   +0.03%     
==========================================
  Files         139      140       +1     
  Lines       15419    15451      +32     
  Branches     2623     2624       +1     
==========================================
+ Hits        12310    12341      +31     
- Misses       2235     2237       +2     
+ Partials      874      873       -1     
Files with missing lines Coverage Δ
sentry_sdk/integrations/unleash.py 93.75% <93.75%> (ø)

... and 1 file with indirect coverage changes

@aliu39 aliu39 added the New Integration Integrating with a new framework or library label Dec 22, 2024
@aliu39
aliu39 marked this pull request as ready for review December 23, 2024 04:51
@aliu39
aliu39 requested review from a team, antonpirker and cmanallen December 23, 2024 04:52
@antonpirker

Copy link
Copy Markdown
Contributor

Hey @aliu39 ! Thanks for the integration. This will be reviewed after the holiday season.

@aliu39

aliu39 commented Dec 23, 2024

Copy link
Copy Markdown
Member Author

Todo:

  • verify w manual test
  • threading and asyncio tests
  • determine if variant payload should factor into tracking (no, track every feature)
  • docs w/ sample verification code

@getsentry getsentry locked and limited conversation to collaborators Dec 27, 2024
@getsentry getsentry unlocked this conversation Dec 27, 2024

@cmanallen cmanallen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mutating class attributes in the __init__ method violates encapsulation. There are a whole category of problems which come from this. I've removed it and replaced with by mutating the UnleashClient class directly. I noticed in the tests you were testing for isolation between instances. While that's interesting it isn't the goal. We want to inject ourselves into every instance or none. This follows the behavior of our other integrations.

Also I've reverted the changes in conftest.py. There was nothing wrong with them. They are just out of scope for this unit of work. Feel free to do those in a follow up PR.

@aliu39
aliu39 marked this pull request as draft January 6, 2025 16:50

@cmanallen cmanallen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Blocking this. We're going to talk about how we handle this going forward and may close this.

@cmanallen cmanallen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Okay we're all good. We're going to keep this setup.

@cmanallen
cmanallen marked this pull request as ready for review January 6, 2025 18:27

@antonpirker antonpirker left a comment

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.

Looks good to me.
Nice integrations, and GREAT test suite! Thanks for that!

@antonpirker
antonpirker merged commit c6a89d6 into master Jan 7, 2025
@antonpirker
antonpirker deleted the aliu/unleash branch January 7, 2025 14:17
antonpirker pushed a commit that referenced this pull request Jan 14, 2025
Follow-up to #3888

The original PR patched 2 methods used for evaluating feature flags,
`is_enabled` (simple toggle on/off) and `get_variant` (returns a dict of
metadata, see
https://docs.getunleash.io/reference/sdks/python#getting-a-variant).

We want to remove all `get_variant` code since we only support boolean
flag evals atm. It seems like the main usecase for variants is reading
payloads (non-bool) for A/B/multivariate testing. This could lead to a
lot of extraneous flags, so until it is requested and/or we support
non-bool values, let's not patch this method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

New Integration Integrating with a new framework or library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants