-
Notifications
You must be signed in to change notification settings - Fork 515
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
Would be helpful to have function decorators for transactions and spans #760
Comments
Yup, has been brought up a couple times. I feel like we may only want this
for spans for now.
For transactions I feel like the decorator could push a scope and set an
error boundary at the same time as well
…On Mon, Jul 13, 2020, 21:52 Mark Story ***@***.***> wrote:
The current context managers for starting transactions and marking spans
are great. However, there have been a few cases where having decorators for
transactions and spans would make code simpler to understand. For example
celery tasks could be written like
@***@***.***_sdk.transaction(transaction="celery.update.user" op="job")def update_user(user_id):
# Do things
Has less visual noise than the decorator does, and when adding/removing
instrumentation the entire function doesn't change. The same idea applies
to spans:
@sentry_sdk.span(description="github.fetch_users", op="github.api")def fetch_github_users(...):
# do the api request and data transformations.
The names of the decorators in this issue are likely rubbish, but I think
supporting decorators will help make adding instrumentation simpler for end
users as it generates less noisy differences and reduces the amount of
indentation in their code.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#760>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGMPRJB7ZDDYZ5YO2OPVATR3NQXHANCNFSM4OYZZRHQ>
.
|
My team is currently adopting Sentry for our Python code base and have been feeling the need for a decorator too. The main goal is to make it easier to start tracing any arbitrary function, and make the business logic more readable by removing instrumentation code. We came up with the decorator implementation attached in draft PR #1089. Does this match with what you had in mind by any chance? PS: I'm new to Sentry and to the |
Also curious if there are any existing alternatives or workarounds for this - we didn't mean to re-invent the wheel. |
We have been using those decorators in production on a Python 3.8 FastAPI app for a few months now and they seem to get the job done. I would be willing to push the PR to the finish line (linting, unit tests) but would prefer to get feedback first. @untitaker any thoughts? |
Hey all, since this is merged, any chance we can update the docs as well to show how to use these decorators? |
Hey @alecgerona Have a look at this documentation: https://docs.sentry.io/platforms/python/performance/instrumentation/custom-instrumentation/ There is described how to use the decorators to create spans. (We do not have a decorator to create transactions) |
The current context managers for starting transactions and marking spans are great. However, there have been a few cases where having decorators for transactions and spans would make code simpler to understand. For example celery tasks could be written like
Has less visual noise than the decorator does, and when adding/removing instrumentation the entire function doesn't change. The same idea applies to spans:
The names of the decorators in this issue are likely rubbish, but I think supporting decorators will help make adding instrumentation simpler for end users as it generates less noisy differences and reduces the amount of indentation in their code.
The text was updated successfully, but these errors were encountered: