Skip to content

Add decorator for Sentry tracing#1089

Merged
antonpirker merged 51 commits into
getsentry:masterfrom
ynouri:feature/tracing-decorator
Mar 15, 2023
Merged

Add decorator for Sentry tracing#1089
antonpirker merged 51 commits into
getsentry:masterfrom
ynouri:feature/tracing-decorator

Conversation

@ynouri

@ynouri ynouri commented Apr 15, 2021

Copy link
Copy Markdown
Contributor

Draft proposal for #760

@github-actions

Copy link
Copy Markdown
Contributor

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

ynouri commented Dec 24, 2021

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown

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)

Comment thread sentry_sdk/decorators.py Outdated
@mschfh

mschfh commented Dec 22, 2022

Copy link
Copy Markdown

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

ynouri commented Jan 3, 2023

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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)

@sl0thentr0py sl0thentr0py left a comment

Copy link
Copy Markdown
Member

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

Comment thread sentry_sdk/tracing.py
Comment thread sentry_sdk/tracing_utils.py Outdated
@antonpirker
antonpirker changed the base branch from master to antonpirker/top-level-get-current-span-transaction March 14, 2023 10:19
@sl0thentr0py

Copy link
Copy Markdown
Member

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

@antonpirker

Copy link
Copy Markdown
Contributor

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.

Comment thread sentry_sdk/tracing_utils_py3.py Outdated
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
Copy Markdown
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
Copy Markdown
Contributor

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
@antonpirker

Copy link
Copy Markdown
Contributor

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

ynouri commented Mar 15, 2023

Copy link
Copy Markdown
Contributor Author

Thanks @antonpirker for the heavy lifting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants