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

ref(flags): register LD hook in setup instead of init, and don't check for initialization #3890

Merged
merged 5 commits into from
Dec 23, 2024

Conversation

aliu39
Copy link
Member

@aliu39 aliu39 commented Dec 22, 2024

Refactors setup code and removes an error case from the LaunchDarkly integration

register LD hook in setup instead of init

IMO we should only hook into LD once, when this integration is setup by sentry_sdk.init. It's rare, but this class could be instantiated more than once, from user error, tests, etc. It's reasonable to expect Sentry init is only called once in prod.

don't check for initialization

We shouldn't fail if LDClient hasn't initialized yet. Initialization is the async process of connecting to the LD server, and may take a moment. With the setup code from our docs, we configure LD right before calling Sentry init, and don't wait for initialization to complete. This could lead to a lot of errors / failure to start your app if you have a slow internet connection. It's ultimately the user's responsibility to ensure LD is initialized before evaluating flags. Even if the client's never initialized, flags will default to False, so nothing's breaking on our end.

Copy link

codecov bot commented Dec 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.88%. Comparing base (60fb6fc) to head (56e6eac).
Report is 1 commits behind head on master.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3890      +/-   ##
==========================================
- Coverage   79.89%   79.88%   -0.01%     
==========================================
  Files         139      139              
  Lines       15429    15429              
  Branches     2624     2623       -1     
==========================================
- Hits        12327    12326       -1     
- Misses       2228     2229       +1     
  Partials      874      874              
Files with missing lines Coverage Δ
sentry_sdk/integrations/launchdarkly.py 79.48% <100.00%> (ø)

... and 4 files with indirect coverage changes

@aliu39 aliu39 requested a review from cmanallen December 23, 2024 05:05
@aliu39 aliu39 marked this pull request as ready for review December 23, 2024 05:05
@aliu39 aliu39 requested review from a team and antonpirker December 23, 2024 05:05
Copy link
Member

@antonpirker antonpirker 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.

@antonpirker antonpirker merged commit c3516db into master Dec 23, 2024
137 checks passed
@antonpirker antonpirker deleted the aliu/ref-launchdarkly branch December 23, 2024 10:02
@cmanallen
Copy link
Member

@aliu39 This needs to be reverted. This is not the correct way to manage this behavior. Regardless, where is the documentation for this change? A notion doc or anything to describe why this is important?

@cmanallen
Copy link
Member

Reverted here: #3900. There are too many holes in this. How would a user track multiple clients? Multiple integrations? Does that work? There are no tests for it. Let's discuss on Monday.

antonpirker added a commit that referenced this pull request Jan 7, 2025
…n't chec…" (#3900)

Mutating a class attribute on `__init__` violates encapsulation and will lead to strange errors.  We need to rethink how we want to implement this before we merge any code.

A simple reproduction of the issue:

```python
>>> class X:
...     y = 0
...     def __init__(self, z):
...         self.__class__.y = z
... 
>>> a = X(1)
>>> b = X(2)
>>> X.y
2
>>> a.y
2
>>> b.y
2
```

Reverts #3890

This reverts commit c3516db.

Co-authored-by: Anton Pirker <[email protected]>
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.

3 participants