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

feat(flags): Add integration for custom tracking of flag evaluations #3860

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

aliu39
Copy link
Member

@aliu39 aliu39 commented Dec 5, 2024

Follow-up to

  1. Adds an integration for buffering feature flags manually with an API (add_feature_flag), and automatically capturing them on error events.

  2. Adds improved test coverage to launchdarkly and openfeature by testing end to end with capture_events fixture, rather than asserting the flags are stored to scope.

@aliu39 aliu39 requested a review from cmanallen December 5, 2024 19:57
Copy link

codecov bot commented Dec 5, 2024

❌ 4 Tests Failed:

Tests completed Failed Passed Skipped
15097 4 15093 4390
View the top 3 failed tests by shortest run time
tests.integrations.featureflags.test_featureflags test_featureflags_integration_asyncio
Stack Traces | 0.067s run time
.../integrations/featureflags/test_featureflags.py:103: in test_featureflags_integration_asyncio
    asyncio.run(runner())
E   AttributeError: module 'asyncio' has no attribute 'run'
tests.integrations.featureflags.test_featureflags test_featureflags_integration_asyncio
Stack Traces | 0.068s run time
.../integrations/featureflags/test_featureflags.py:103: in test_featureflags_integration_asyncio
    asyncio.run(runner())
E   AttributeError: module 'asyncio' has no attribute 'run'
tests.integrations.launchdarkly.test_launchdarkly test_launchdarkly_integration_threaded
Stack Traces | 0.102s run time
.../integrations/launchdarkly/test_launchdarkly.py:91: in test_launchdarkly_integration_threaded
    assert len(events) == 3
E   AssertionError: assert 4 == 3
E    +  where 4 = len([{'breadcrumbs': {'values': []}, 'contexts': {'flags': {'values': [{'flag': 'hello', 'result': True}, {'flag': 'world', 'result': False}]}, 'runtime': {'build': '3.13.1 (main, Dec  4 2024, 06:21:55) [GCC 9.4.0]', 'name': 'CPython', 'version': '3.13.1'}, 'trace': {'parent_span_id': None, 'span_id': 'ba4ad5d3dddfa4d7', 'trace_id': 'b86666664d6b43c1bc85d8ef609d935b'}}, 'environment': 'production', 'event_id': '8c36fb14cdc24ff288468a25754dd532', ...}, {'breadcrumbs': {'values': []}, 'contexts': {'flags': {'values': [{'flag': 'hello', 'result': True}, {'flag': 'other', 'result': False}]}, 'runtime': {'build': '3.13.1 (main, Dec  4 2024, 06:21:55) [GCC 9.4.0]', 'name': 'CPython', 'version': '3.13.1'}, 'trace': {'parent_span_id': None, 'span_id': 'ba4ad5d3dddfa4d7', 'trace_id': 'b86666664d6b43c1bc85d8ef609d935b'}}, 'environment': 'production', 'event_id': 'ca0792695a3f48c2a96dd00cab882c33', ...}, {'breadcrumbs': {'values': []}, 'contexts': {'runtime': {'build': '3.13.1 (main, Dec  4 2024, 06:21:55) [GCC 9.4.0]', 'name': 'CPython', 'version': '3.13.1'}, 'trace': {'parent_span_id': None, 'span_id': '923e0ac338cd7129', 'trace_id': '5cb46fe1165a4118be8eaa9e3515ad0a'}}, 'environment': 'production', 'event_id': '7efc4ce3d76d442f95698cca800b0ad2', ...}, {'breadcrumbs': {'values': []}, 'contexts': {'flags': {'values': [{'flag': 'hello', 'result': True}]}, 'runtime': {'build': '3.13.1 (main, Dec  4 2024, 06:21:55) [GCC 9.4.0]', 'name': 'CPython', 'version': '3.13.1'}, 'trace': {'parent_span_id': None, 'span_id': 'ba4ad5d3dddfa4d7', 'trace_id': 'b86666664d6b43c1bc85d8ef609d935b'}}, 'environment': 'production', 'event_id': '3e76e036f5d241ec966b26955d8b693f', ...}])

To view more test analytics, go to the Test Analytics Dashboard
📢 Thoughts on this report? Let us know!

sentry_sdk/integrations/featureflags.py Show resolved Hide resolved
tests/integrations/featureflags/test_featureflags.py Outdated Show resolved Hide resolved
tests/test_lru_cache.py Outdated Show resolved Hide resolved
sentry_sdk/_lru_cache.py Outdated Show resolved Hide resolved
@aliu39 aliu39 changed the title Aliu/ff integration and added coverage feat(flags): Add integration for custom tracking of flag evaluations Dec 5, 2024
@aliu39 aliu39 force-pushed the aliu/ff-integration-and-added-coverage branch from 320e49e to 4651b6a Compare December 6, 2024 19:05
@aliu39 aliu39 requested a review from cmanallen December 6, 2024 19:31
@aliu39 aliu39 marked this pull request as ready for review December 6, 2024 19:31
@aliu39 aliu39 requested review from antonpirker and a team December 6, 2024 19:57
sentry_sdk/integrations/featureflags.py Outdated Show resolved Hide resolved
tests/integrations/featureflags/test_featureflags.py Outdated Show resolved Hide resolved
@aliu39 aliu39 requested a review from cmanallen December 6, 2024 20:18


@pytest.fixture
def uninstall_integration():
Copy link
Member Author

@aliu39 aliu39 Dec 6, 2024

Choose a reason for hiding this comment

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

Note on this fixture: I found using the reset_integrations fixture in conftest.py caused issues with the default dedupe integration. We just want the integration being tested to be setup at the start of every new test.

Without using this, the error processor isn't added correctly. This isn't a concern for real use, since user apps only call init once

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 OK

@antonpirker
Copy link
Member

We also need to add docs for this, can you prepare a PR in the docs repo?

@aliu39
Copy link
Member Author

aliu39 commented Dec 18, 2024

Sounds good! I've opened getsentry/sentry-docs#12152, will do a last check in the morning to make sure it's up to date!

@aliu39
Copy link
Member Author

aliu39 commented Dec 18, 2024

Do you know anything about the failing ubuntu tests @antonpirker ?

@antonpirker
Copy link
Member

Do you know anything about the failing ubuntu tests @antonpirker ?

In Python 3.6 there is probably no asyncio.run().

Can you fix this somehow, or skip this test in Python 3.6 (then this integration will only be supported form Python 3.7 and up)

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.

4 participants