sentry-python icon indicating copy to clipboard operation
sentry-python copied to clipboard

Add OpenFeature integration

Open cmanallen opened this issue 1 year ago • 1 comments

Adds OpenFeature integration and extends the Scope with a flags property.

As flags are evaluated by an application they are stored within the Sentry SDK (lru cache). When an error occurs we fetch the flags stored in the SDK and serialize them on the event.

Some open questions:

  • How do I seed the buffer's capacity from the SDKs (or Integrations) init arguments? Right now its hard-coded at 100. The buffer is stored on the scope so its hard to know which integration should be used.

cmanallen avatar Oct 11 '24 15:10 cmanallen

Codecov Report

Attention: Patch coverage is 89.52381% with 11 lines in your changes missing coverage. Please review.

Project coverage is 84.33%. Comparing base (d06a189) to head (200917f). Report is 4 commits behind head on master.

:white_check_mark: All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sentry_sdk/flag_utils.py 82.60% 4 Missing :warning:
sentry_sdk/integrations/openfeature.py 84.00% 2 Missing and 2 partials :warning:
sentry_sdk/integrations/launchdarkly.py 91.17% 2 Missing and 1 partial :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3648      +/-   ##
==========================================
+ Coverage   84.29%   84.33%   +0.04%     
==========================================
  Files         133      136       +3     
  Lines       14262    14367     +105     
  Branches     2405     2417      +12     
==========================================
+ Hits        12022    12117      +95     
- Misses       1489     1497       +8     
- Partials      751      753       +2     
Files with missing lines Coverage Δ
sentry_sdk/_lru_cache.py 100.00% <100.00%> (ø)
sentry_sdk/consts.py 99.51% <ø> (ø)
sentry_sdk/scope.py 88.51% <100.00%> (+0.30%) :arrow_up:
sentry_sdk/integrations/launchdarkly.py 91.17% <91.17%> (ø)
sentry_sdk/flag_utils.py 82.60% <82.60%> (ø)
sentry_sdk/integrations/openfeature.py 84.00% <84.00%> (ø)

codecov[bot] avatar Oct 11 '24 16:10 codecov[bot]

Hey @cmanallen ! This is the best PR I have received ever! Great work.

The integrations should not change the Scope.

I have created an commit on your branch to illustrate how the flags could live on the integration rather than the scope (I hope you don't mind): https://github.com/getsentry/sentry-python/pull/3648/commits/430387fbbdc996328cce0f177fc537df88534ced

This way all the functionality is contained in the integration. I also added some tests to show how you can now set the capacity of the buffer when initializing the Integration.

wdyt?

Feel free to make changes to my commit if you want to do things differently.

antonpirker avatar Oct 24 '24 13:10 antonpirker

@antonpirker Reverted your commit per our conversation on Slack. Tl;dr the commit didn't work because we need to be tied to the scope to maintain flag isolation. After @sl0thentr0py's comment about it being fine to keep the flags on the scope if this change is permanent I think its appropriate to revert that change.

cmanallen avatar Oct 28 '24 14:10 cmanallen

Thanks @antonpirker and welcome back!

cmanallen avatar Nov 04 '24 12:11 cmanallen