Skip to content

Commit c019d6d

Browse files
authored
Merge branch 'master' into ivana/remove-decimal
2 parents a986f61 + 4640531 commit c019d6d

File tree

5 files changed

+556
-14
lines changed

5 files changed

+556
-14
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
steps:
2121
- name: Get auth token
2222
id: token
23-
uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6
23+
uses: actions/create-github-app-token@0f859bf9e69e887678d5bbfbee594437cb440ffe # v2.1.0
2424
with:
2525
app-id: ${{ vars.SENTRY_RELEASE_BOT_CLIENT_ID }}
2626
private-key: ${{ secrets.SENTRY_RELEASE_BOT_PRIVATE_KEY }}

sentry_sdk/consts.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ class CompressionAlgo(Enum):
100100
]
101101

102102

103+
class SPANTEMPLATE(str, Enum):
104+
DEFAULT = "default"
105+
AI_AGENT = "ai_agent"
106+
AI_TOOL = "ai_tool"
107+
AI_CHAT = "ai_chat"
108+
109+
def __str__(self):
110+
# type: () -> str
111+
return self.value
112+
113+
103114
class INSTRUMENTER:
104115
SENTRY = "sentry"
105116
OTEL = "otel"

sentry_sdk/tracing.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from enum import Enum
55

66
import sentry_sdk
7-
from sentry_sdk.consts import INSTRUMENTER, SPANSTATUS, SPANDATA
7+
from sentry_sdk.consts import INSTRUMENTER, SPANSTATUS, SPANDATA, SPANTEMPLATE
88
from sentry_sdk.profiler.continuous_profiler import get_profiler_id
99
from sentry_sdk.utils import (
1010
get_current_thread_meta,
@@ -1364,8 +1364,10 @@ def _set_initial_sampling_decision(self, sampling_context):
13641364
if TYPE_CHECKING:
13651365

13661366
@overload
1367-
def trace(func=None, *, op=None, name=None, attributes=None):
1368-
# type: (None, Optional[str], Optional[str], Optional[dict[str, Any]]) -> Callable[[Callable[P, R]], Callable[P, R]]
1367+
def trace(
1368+
func=None, *, op=None, name=None, attributes=None, template=SPANTEMPLATE.DEFAULT
1369+
):
1370+
# type: (None, Optional[str], Optional[str], Optional[dict[str, Any]], SPANTEMPLATE) -> Callable[[Callable[P, R]], Callable[P, R]]
13691371
# Handles: @trace() and @trace(op="custom")
13701372
pass
13711373

@@ -1376,8 +1378,10 @@ def trace(func):
13761378
pass
13771379

13781380

1379-
def trace(func=None, *, op=None, name=None, attributes=None):
1380-
# type: (Optional[Callable[P, R]], Optional[str], Optional[str], Optional[dict[str, Any]]) -> Union[Callable[P, R], Callable[[Callable[P, R]], Callable[P, R]]]
1381+
def trace(
1382+
func=None, *, op=None, name=None, attributes=None, template=SPANTEMPLATE.DEFAULT
1383+
):
1384+
# type: (Optional[Callable[P, R]], Optional[str], Optional[str], Optional[dict[str, Any]], SPANTEMPLATE) -> Union[Callable[P, R], Callable[[Callable[P, R]], Callable[P, R]]]
13811385
"""
13821386
Decorator to start a child span around a function call.
13831387
@@ -1406,14 +1410,21 @@ def trace(func=None, *, op=None, name=None, attributes=None):
14061410
attributes provide additional context about the span's execution.
14071411
:type attributes: dict[str, Any] or None
14081412
1413+
:param template: The type of span to create. This determines what kind of
1414+
span instrumentation and data collection will be applied. Use predefined
1415+
constants from :py:class:`sentry_sdk.consts.SPANTEMPLATE`.
1416+
The default is `SPANTEMPLATE.DEFAULT` which is the right choice for most
1417+
use cases.
1418+
:type template: :py:class:`sentry_sdk.consts.SPANTEMPLATE`
1419+
14091420
:returns: When used as ``@trace``, returns the decorated function. When used as
14101421
``@trace(...)`` with parameters, returns a decorator function.
14111422
:rtype: Callable or decorator function
14121423
14131424
Example::
14141425
14151426
import sentry_sdk
1416-
from sentry_sdk.consts import OP
1427+
from sentry_sdk.consts import OP, SPANTEMPLATE
14171428
14181429
# Simple usage with default values
14191430
@sentry_sdk.trace
@@ -1430,13 +1441,20 @@ def process_data():
14301441
def make_db_query(sql):
14311442
# Function implementation
14321443
pass
1444+
1445+
# With a custom template
1446+
@sentry_sdk.trace(template=SPANTEMPLATE.AI_TOOL)
1447+
def calculate_interest_rate(amount, rate, years):
1448+
# Function implementation
1449+
pass
14331450
"""
14341451
from sentry_sdk.tracing_utils import create_span_decorator
14351452

14361453
decorator = create_span_decorator(
14371454
op=op,
14381455
name=name,
14391456
attributes=attributes,
1457+
template=template,
14401458
)
14411459

14421460
if func:

0 commit comments

Comments
 (0)