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(sentry-app): Allows default serializer to take a human readable list of features instead of int values #83200

Closed

Conversation

GabeVillalobos
Copy link
Member

@GabeVillalobos GabeVillalobos commented Jan 9, 2025

Updates the default SentryAppParser class (serializer) to include a new field named feature_set, which will supersede features eventually in our Sentry App APIs.

The features field has a couple of key problems:

  1. The field is not human readable as is, and requires a user to lookup the exact feature they want by int value in the code.
  2. The current implementation doesn't play well with drf spectacular + our docs markdown format, breaking our help text rendering.

By allowing our API users to specify feature_set with the string format of the names, this should address both of the above issues allowing us to fully publish the API.

To do this, I changed the implementation of the Feature class to include string representations of each int enum, by using a pattern from Python's std lib code for HTTP status enums: https://github.com/python/cpython/blob/main/Lib/http/__init__.py

The alternative would have been to create some sort of map of the hardcoded values in the original class, but this felt like a cleaner solution.

Note: feature_set and features are mutually exclusive fields which will raise validation errors if both are included in a PUT request body.

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jan 9, 2025
Comment on lines +24 to +45
API = 0, "integrations-api"
ISSUE_LINK = 1, "integrations-issue-link"
STACKTRACE_LINK = 2, "integrations-stacktrace-link"
EVENT_HOOKS = (
3,
"integrations-event-hooks",
)
PROJECT_MANAGEMENT = 4, "integrations-project-management"
INCIDENT_MANAGEMENT = 5, "integrations-incident-management"
FEATURE_FLAG = 6, "integrations-feature-flag"
ALERTS = 7, "integrations-alert-rule"
RELEASE_MANAGEMENT = 8, "integrations-release-management"
VISUALIZATION = 9, "integrations-visualization"
CHAT = 11, "integrations-chat"
SESSION_REPLAY = 12, "integrations-session-replay"

feature_name: str

def __new__(cls, value: int, feature_name: str) -> Feature:
obj = int.__new__(cls, value)
obj._value_ = value
obj.feature_name = feature_name
Copy link
Member Author

Choose a reason for hiding this comment

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

This implementation allows us to specify enums with both int and string values. Overriding __new__ facilitates constructing an int object, with enum values attached in a similar fashion as Python's std lib implementation for HTTP status codes: https://github.com/python/cpython/blob/main/Lib/http/__init__.py

Copy link

codecov bot commented Jan 9, 2025

Codecov Report

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

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
.../sentry/integrations/models/integration_feature.py 95.34% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #83200      +/-   ##
==========================================
+ Coverage   87.57%   87.59%   +0.01%     
==========================================
  Files        9469     9369     -100     
  Lines      536960   536430     -530     
  Branches    21119    21062      -57     
==========================================
- Hits       470249   469890     -359     
+ Misses      66352    66181     -171     
  Partials      359      359              

@GabeVillalobos GabeVillalobos marked this pull request as ready for review January 10, 2025 19:14
@GabeVillalobos GabeVillalobos requested review from a team as code owners January 10, 2025 19:14
Comment on lines 112 to 113
feature_list = result.get("features")
if feature_set := result.get("feature_set"):
Copy link
Contributor

@Christinarlong Christinarlong Jan 10, 2025

Choose a reason for hiding this comment

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

Should we be checking for equality of these 2 ?
EDIT: oh wait nvm, it seems like there can only be one ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep! I made the options mutually exclusive. There are more edge cases handling 2 than 1.

Copy link
Member

@cathteng cathteng left a comment

Choose a reason for hiding this comment

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

why is this the first time I've heard of the IntegrationFeature model 🤔

@@ -73,7 +73,10 @@ class SentryAppParser(Serializer):
status = serializers.CharField(required=False, allow_null=True)
events = EventListField(required=False, allow_null=True)
features = serializers.MultipleChoiceField(
Copy link
Member

Choose a reason for hiding this comment

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

will we deprecate this eventually?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, once the UI is migrated and working correctly, I'll drop this field

@GabeVillalobos
Copy link
Member Author

We're re-evaluating this patch entirely, closing for now but will reopen if we decide to publicize this functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants