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

Sanic integration performance #2419

Merged
merged 13 commits into from
Oct 13, 2023
Merged

Conversation

szokeasaurusrex
Copy link
Member

@szokeasaurusrex szokeasaurusrex commented Oct 6, 2023

Closes #2388

Before this PR is ready to merge, a few things need to be addressed.

  • Get errors to show up in the trace
  • Make sure the changes work when Sanic is running in ASGI mode
  • If the code doesn't just work in ASGI mode, investigate whether we need support here, or if the use case is uncommon enough that we decide not to support it
  • Add tests, both for normal Sanic and ASGI mode cases (for ASGI mode, at least verify that the SDK does not crash it)
  • TODO: Do we actually need tests for ASGI mode? ASGI mode appears to work out of the box, I did not need to add any additional code specific to ASGI
  • Delete commented-out code

@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/sanic-performance branch from 5f23719 to 119e251 Compare October 6, 2023 13:35
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, added some questions.

sentry_sdk/integrations/sanic.py Outdated Show resolved Hide resolved
scope.set_transaction_name(
route_name, source=TRANSACTION_SOURCE_COMPONENT
"/%s" % route.path, source=TRANSACTION_SOURCE_COMPONENT
Copy link
Member

Choose a reason for hiding this comment

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

What is in route.path? Because we should make sure that transaction names have low cardinality. (So /user/1231231 would be not good, but /users/{id} or similar would be good. (this is important for grouping events together on the backend.

Copy link
Member

Choose a reason for hiding this comment

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

Also if the transaction name is a route /users/{id} the source should be TRANSACTION_SOURCE_ROUTE. See https://develop.sentry.dev/sdk/event-payloads/transaction/#transaction-annotations

Copy link
Member

Choose a reason for hiding this comment

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

also applicable above in the continue_trace call.

Copy link
Member Author

Choose a reason for hiding this comment

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

The route.path is similar to what you wrote in your example, but for Sanic, it also includes the type of the URL parameter. So, for your example, the route.path would likely be users/{id:int}, and then we would prepend a / to obtain /users/{id:int} as the transaction name (prepending the / ensures that the root route displays as / instead of as an unnamed transaction, since the root route's route.path is an empty string).

Copy link
Member

Choose a reason for hiding this comment

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

I would not add a /. Because the user will know what is meant anyhow, and maybe his app runs on /api/user/... and then /user/... would be wrong.

@@ -133,6 +135,7 @@ def _setup_sanic():
# type: () -> None
Sanic._startup = _startup
ErrorHandler.lookup = _sentry_error_handler_lookup
# _patch_sanic_asgi()
Copy link
Member

Choose a reason for hiding this comment

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

should probably removed

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I have this in my list of to-do items before merge

sentry_sdk/integrations/sanic.py Outdated Show resolved Hide resolved
scope.set_transaction_name(
route_name, source=TRANSACTION_SOURCE_COMPONENT
"/%s" % route.path, source=TRANSACTION_SOURCE_COMPONENT
Copy link
Member

Choose a reason for hiding this comment

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

also applicable above in the continue_trace call.

@szokeasaurusrex szokeasaurusrex marked this pull request as ready for review October 12, 2023 12:11
Copy link
Contributor

@sentrivana sentrivana left a comment

Choose a reason for hiding this comment

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

Left a few comments/suggestions, but LGTM!

tox.ini Outdated Show resolved Hide resolved
tests/integrations/sanic/test_sanic.py Show resolved Hide resolved
@@ -54,6 +58,16 @@ class SanicIntegration(Integration):
identifier = "sanic"
version = None

def __init__(self, unsampled_statuses=frozenset({404})):
Copy link
Contributor

Choose a reason for hiding this comment

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

Please also add the new option to the Sanic docs if you haven't already.

tests/integrations/sanic/test_sanic.py Outdated Show resolved Hide resolved
tests/integrations/sanic/test_sanic.py Show resolved Hide resolved
sentry_sdk/integrations/sanic.py Show resolved Hide resolved
@szokeasaurusrex szokeasaurusrex enabled auto-merge (squash) October 13, 2023 10:28
@szokeasaurusrex szokeasaurusrex merged commit 0452535 into master Oct 13, 2023
283 of 284 checks passed
@szokeasaurusrex szokeasaurusrex deleted the szokeasaurusrex/sanic-performance branch October 13, 2023 10:38
@szokeasaurusrex szokeasaurusrex changed the title Sanic integration initial version Sanic integration performance Oct 13, 2023
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.

Performance instrumentation for Sanic Integration
3 participants