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

Add decorator for Sentry tracing #1089

Merged
merged 51 commits into from Mar 15, 2023

Conversation

ynouri
Copy link
Contributor

@ynouri ynouri commented Apr 15, 2021

Draft proposal for #760

@github-actions
Copy link

This pull request has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@ynouri
Copy link
Contributor Author

ynouri commented Dec 24, 2021

This pull request has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

I would be happy to bring this to the finish line but probably best to get feedback from a maintainer first. Thank you

@janfabry
Copy link

Would it be better to have a separate decorators for transactions and spans? They have different concerns.

The transaction decorator:

  • Would ensure a transaction exists
  • Would overwrite the name (if passed)
  • Would ensure a passed sampled argument is adhered to (if True is passed, but the existing tx is not sampled, it should restart the transaction - because if you start with sampling disabled I think you can't enable it later on, the SpanRecorder is not enabled) (calling the decorator sentry_traced when it does not ensure it actually is traced is confusing)

The span decorator:

  • Would start a new span, with the passed args
  • Would only work if a transaction exists, but would not care if it doesn't

Maybe you could also have a decorator that combines both of these, but then it needs a clear name.

(I'm struggling with these questions right now as we are designing the decorators for our use case, so maybe it's a useful brain dump, but if not, feel free to ignore it)

sentry_sdk/decorators.py Outdated Show resolved Hide resolved
@mschfh
Copy link

mschfh commented Dec 22, 2022

What is the status of this PR?

@sl0thentr0py sl0thentr0py self-assigned this Jan 3, 2023
@ynouri ynouri marked this pull request as ready for review January 3, 2023 20:00
@ynouri
Copy link
Contributor Author

ynouri commented Jan 3, 2023

I would be happy to bring this to the finish line but probably best to get feedback from a maintainer first. I moved it from Draft to Ready for Review. Maybe it'll get picked up by someone with this new status. cc @sl0thentr0py

@antonpirker
Copy link
Member

Hey @ynouri !

Great work! I have moved the decorator into the tracing package and renamed it to align with how this is named in other Sentry SDKs.

We would need tests for the decorator, could you please write some?

@antonpirker antonpirker self-assigned this Mar 6, 2023
@antonpirker
Copy link
Member

Hey @ynouri
I will change the API, ab bit, because we have some things that should be working the same over different programming languages.

Also the span.op should not be set to an arbitrary value because we index spans based on this so we have a fixed set we can choose: https://develop.sentry.dev/sdk/performance/span-operations/

(I will change your code to set it to function)

Copy link
Member

@sl0thentr0py sl0thentr0py left a comment

Choose a reason for hiding this comment

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

some convention nits, I really think we don't wanna start splitting files for python 2/3

sentry_sdk/tracing.py Show resolved Hide resolved
sentry_sdk/tracing_utils.py Outdated Show resolved Hide resolved
@antonpirker antonpirker changed the base branch from master to antonpirker/top-level-get-current-span-transaction March 14, 2023 10:19
@sl0thentr0py
Copy link
Member

@antonpirker why are there so many test changes in this PR now? can you summarize them?

@antonpirker
Copy link
Member

Because I now install pytest_asyncio for running the common tests some tests (like test_asyncio) have been run for the first time (they where not run at all before) and this lead to some broken tests.

Now I changed the test setup to have a "common" test environment that is kind of like an integration, so I can install pytest_asyncio to only this "common" tests without having it also there in all the integration tests.

async def func_with_tracing(*args, **kwargs):
# type: (*Any, **Any) -> Any

span_or_trx = get_current_span_or_transaction(sentry_sdk.Hub.current)
Copy link
Member

Choose a reason for hiding this comment

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

also as discussed I think get_current_span here is sufficient

Copy link
Member

Choose a reason for hiding this comment

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

done in last commit

@antonpirker antonpirker deleted the branch getsentry:master March 15, 2023 13:48
@antonpirker antonpirker reopened this Mar 15, 2023
@antonpirker antonpirker changed the base branch from antonpirker/top-level-get-current-span-transaction to master March 15, 2023 13:58
@antonpirker antonpirker merged commit 251e27d into getsentry:master Mar 15, 2023
228 of 229 checks passed
@antonpirker
Copy link
Member

Hey @ynouri !

Thanks for the great contribution and the patience! Finally we have merged your contribution!

If you want to have a small gift for your work, please send me your shipping address and your t-shirt size to anton.pirker@sentry.io and I will send you something! Thanks!

@ynouri
Copy link
Contributor Author

ynouri commented Mar 15, 2023

Thanks @antonpirker for the heavy lifting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants