Skip to content

feat(tracing): Improve @trace decorator. #4648

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

Open
wants to merge 55 commits into
base: master
Choose a base branch
from

Conversation

antonpirker
Copy link
Member

@antonpirker antonpirker commented Jul 30, 2025

Update the @trace decorator and make it more powerful. It accepts now the following parameters: op, name, attributes.

Example usage:

import sentry_sdk
from sentry_sdk.consts import OP

# Simple usage (like before)
@sentry_sdk.trace
def process_data():
    # Function implementation
    pass

# With custom parameters
@sentry_sdk.trace(
    op=OP.DB_QUERY,
    name="Get user data",
    attributes={"postgres": True}
)
def make_db_query(sql):
    # Function implementation
    pass

This creates better DX for our users.

Copy link

codecov bot commented Jul 30, 2025

Codecov Report

❌ Patch coverage is 97.29730% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.08%. Comparing base (19914cd) to head (dc63e43).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sentry_sdk/tracing.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4648      +/-   ##
==========================================
+ Coverage   85.07%   85.08%   +0.01%     
==========================================
  Files         156      156              
  Lines       15824    15836      +12     
  Branches     2677     2677              
==========================================
+ Hits        13462    13474      +12     
+ Misses       1583     1582       -1     
- Partials      779      780       +1     
Files with missing lines Coverage Δ
sentry_sdk/integrations/starlite.py 81.94% <100.00%> (ø)
sentry_sdk/tracing_utils.py 87.55% <100.00%> (+0.82%) ⬆️
sentry_sdk/tracing.py 86.39% <80.00%> (+0.02%) ⬆️

... and 1 file with indirect coverage changes

@antonpirker antonpirker changed the title Manual instrumentation improvements feat(tracing): Improve @trace decorator. Aug 5, 2025
@antonpirker antonpirker marked this pull request as ready for review August 5, 2025 12:46
@antonpirker antonpirker requested a review from a team as a code owner August 5, 2025 12:46
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Copy link
Member

@szokeasaurusrex szokeasaurusrex left a comment

Choose a reason for hiding this comment

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

Added a few small suggestions, can do a more in depth review once they're addressed

cursor[bot]

This comment was marked as outdated.

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.

2 participants