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(nextjs-insights): add endpoint to transform EAP response into array / tree structure #88665

Merged
merged 11 commits into from
Apr 9, 2025

Conversation

shellmayr
Copy link
Member

@shellmayr shellmayr commented Apr 3, 2025

  • Closes https://github.com/getsentry/projects/issues/878
  • Adds a new endpoint as subclass of OrganizationEventsEndpoint, because we basically just do post-processing on the result, and ensure that certain parameter values are set correctly.
  • Parses current span.description into its components using a regex, then split the path using string functions. Adds two new fields to the API response: nextjs.function.component_type and nextjs.function.path
  • Purpose of the endpoint is to generate an representation of the component type and path of a component that is both easily usable by the frontend and will not need a rewrite when EAP starts supporting arrays.

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 3, 2025
Copy link

codecov bot commented Apr 3, 2025

Codecov Report

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

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...sentry/api/endpoints/organization_insights_tree.py 93.93% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           master   #88665     +/-   ##
=========================================
  Coverage   87.75%   87.75%             
=========================================
  Files       10013    10044     +31     
  Lines      567352   569283   +1931     
  Branches    22297    22297             
=========================================
+ Hits       497860   499577   +1717     
- Misses      69075    69289    +214     
  Partials      417      417             

@shellmayr shellmayr requested review from lforst and a team April 4, 2025 13:07
@shellmayr shellmayr requested a review from Zylphrex April 4, 2025 13:11
@shellmayr shellmayr marked this pull request as ready for review April 4, 2025 13:11
@shellmayr shellmayr requested a review from a team as a code owner April 4, 2025 13:11

def _separate_span_description_info(self, response):
# Regex to split string into '{component_type}{space}({path})'
pattern = re.compile(r"^(.*?)\s+\((.*?)\)$")
Copy link
Member

Choose a reason for hiding this comment

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

This is potentially vulnerable to redos: re.compile(r"^(.*?)\s+\((.*?)\)$").match(('\t' * 50000) + ')')

sauce

Are we limiting the length of the description somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! I don't know off the top of my head if we do limit it and didn't find anything in the spec - I know we limit all strings generally though; I'll check what the limit is and rethink the regex somehow if it's an issue.

Copy link
Member

Choose a reason for hiding this comment

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

Imo it's fine if we limit the length here once more before we pass it to the regex. That way we don't depend on any upstream logic.

Copy link
Member Author

@shellmayr shellmayr Apr 4, 2025

Choose a reason for hiding this comment

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

I think EAP should have some size limit on it as well - would like to have those two to be consistent if we do a check here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Checked with ingest regarding size limits - this is trimmed to 8192 characters, and the other point to be made here is that the regex is only needed until we have separate fields from the SDK, so I think we can go ahead with this. I may refactor this to use string splitting instead soon though, just for performance and robustness.

@JoshFerge
Copy link
Member

could you provide more color as to what the end product result is? will this be generalized to other modules or is this next.js specific?

@shellmayr
Copy link
Member Author

shellmayr commented Apr 4, 2025

@JoshFerge the goal is to replicate the tree of server side rendered backend components in insights - which for now is pretty Next.js specific. We had a debate about doing this on the frontend vs the backend, but since there is a plan for EAP to support arrays at some point (which will make querying and aggregating this type of data easier) we wanted to do the intermediate solution that will cause the least troubles in migrating later - which is the backend. No plans for generalization at this point, but if the feature gets adopeted well, I can see us doing this for other platforms as well in a similar way. Are there specific concerns you'd like to see addressed?

@JoshFerge
Copy link
Member

@JoshFerge the goal is to replicate the tree of server side rendered backend components in insights - which for now is pretty Next.js specific. We had a debate about doing this on the frontend vs the backend, but since there is a plan for EAP to support arrays at some point (which will make querying and aggregating this type of data easier) we wanted to do the intermediate solution that will cause the least troubles in migrating later - which is the backend. No plans for generalization at this point, but if the feature gets adopeted well, I can see us doing this for other platforms as well in a similar war. Are there specific concerns you'd like to see addressed?

got it, that makes sense. mind just adding a note about this in the docstring? just want to make sure future folks understand the context of the endpoint.

when you do migrate, will this endpoint still be necessary?

@shellmayr
Copy link
Member Author

@JoshFerge yeah I'll add that - good point. The endpoint will not be needed once the feature exists in EAP and the feature can be migrated over.

@shellmayr shellmayr merged commit 99ac0d8 into master Apr 9, 2025
49 checks passed
@shellmayr shellmayr deleted the shellmayr/feat/nextjs-insights-tree-endpoint branch April 9, 2025 07:29
Copy link

sentry-io bot commented Apr 10, 2025

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ KeyError: 'span.description' /api/0/organizations/{organization_id_or_slug}/... View Issue

Did you find this useful? React with a 👍 or 👎

Christinarlong pushed a commit that referenced this pull request Apr 10, 2025
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.

4 participants