question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Would be helpful to have function decorators for transactions and spans

See original GitHub issue

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

@celery.task
@sentry_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.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:13
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ynouricommented, Jul 12, 2021

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?

1reaction
untitakercommented, Jul 13, 2020

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 notifications@github.com 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

@celery.task@sentry_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 https://github.com/getsentry/sentry-python/issues/760, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGMPRJB7ZDDYZ5YO2OPVATR3NQXHANCNFSM4OYZZRHQ .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Primer on Python Decorators
In this tutorial on decorators, we'll look at what they are and how to create and use them. Decorators provide a simple syntax...
Read more >
Custom instrumentation for Elixir | AppSignal documentation
Decorators decorator module, it's possible add custom instrumentation to your Elixir applications without changing the functions' contents. Transaction events.
Read more >
Instrument a custom method to get deep visibility into your ...
In Java, Datadog APM allows you to instrument your code to generate custom spans—either by using method decorators, or by instrumenting specific code...
Read more >
Instrumenting custom code | APM Python Agent Reference [6.x]
Creating Additional Spans in a Transactionedit ... elasticapm.capture_span can be used either as a decorator or as a context manager.
Read more >
OpenTelemetry NodeJS | Lightstep Blog
Apply this walkthrough to your application, and you are good to go. ... Once you have a tracer, you can use it to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found