Skip to content

Commit c2d47bc

Browse files
committed
renaming
1 parent ee845b1 commit c2d47bc

File tree

5 files changed

+31
-42
lines changed

5 files changed

+31
-42
lines changed

sentry_sdk/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@
5151
"end_session",
5252
"set_transaction_name",
5353
"update_current_span",
54-
"SpanTemplate",
55-
"SpanAttr",
56-
"SpanOp",
5754
]
5855

5956
# Initialize the debug support after everything is loaded

sentry_sdk/api.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@
44

55
from sentry_sdk import tracing_utils, Client
66
from sentry_sdk._init_implementation import init
7-
from sentry_sdk.consts import ( # noqa: N811
8-
INSTRUMENTER,
9-
OP as SpanOp,
10-
SPANDATA as SpanAttr,
11-
SpanTemplate,
12-
)
7+
from sentry_sdk.consts import INSTRUMENTER
138
from sentry_sdk.scope import Scope, _ScopeManager, new_scope, isolation_scope
149
from sentry_sdk.tracing import NoOpSpan, Transaction, trace
1510
from sentry_sdk.crons import monitor
@@ -91,9 +86,6 @@ def overload(x):
9186
"end_session",
9287
"set_transaction_name",
9388
"update_current_span",
94-
"SpanTemplate",
95-
"SpanAttr",
96-
"SpanOp",
9789
]
9890

9991

sentry_sdk/consts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class CompressionAlgo(Enum):
100100
]
101101

102102

103-
class SpanTemplate(str, Enum):
103+
class SPANTEMPLATE(str, Enum):
104104
SPAN = "span"
105105
AI_AGENT = "ai_agent"
106106
AI_TOOL = "ai_tool"

sentry_sdk/tracing.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from enum import Enum
66

77
import sentry_sdk
8-
from sentry_sdk.consts import INSTRUMENTER, SPANSTATUS, SPANDATA, SpanTemplate
8+
from sentry_sdk.consts import INSTRUMENTER, SPANSTATUS, SPANDATA, SPANTEMPLATE
99
from sentry_sdk.profiler.continuous_profiler import get_profiler_id
1010
from sentry_sdk.tracing_utils import create_span_decorator
1111
from sentry_sdk.utils import (
@@ -1350,21 +1350,21 @@ def _set_initial_sampling_decision(self, sampling_context):
13501350

13511351
@overload
13521352
def trace(
1353-
func=None, *, template=SpanTemplate.SPAN, op=None, name=None, attributes=None
1353+
func=None, *, template=SPANTEMPLATE.SPAN, op=None, name=None, attributes=None
13541354
):
1355-
# type: (Optional[Callable[P, R]], SpanTemplate, Optional[str], Optional[str], Optional[dict[str, Any]]) -> Callable[[Callable[P, R]], Callable[P, R]]
1355+
# type: (Optional[Callable[P, R]], SPANTEMPLATE, Optional[str], Optional[str], Optional[dict[str, Any]]) -> Callable[[Callable[P, R]], Callable[P, R]]
13561356
pass
13571357

13581358
@overload
1359-
def trace(func, *, template=SpanTemplate.SPAN, op=None, name=None, attributes=None):
1360-
# type: (Callable[P, R], SpanTemplate, Optional[str], Optional[str], Optional[dict[str, Any]]) -> Callable[P, R]
1359+
def trace(func, *, template=SPANTEMPLATE.SPAN, op=None, name=None, attributes=None):
1360+
# type: (Callable[P, R], SPANTEMPLATE, Optional[str], Optional[str], Optional[dict[str, Any]]) -> Callable[P, R]
13611361
pass
13621362

13631363

13641364
def trace(
1365-
func=None, *, template=SpanTemplate.SPAN, op=None, name=None, attributes=None
1365+
func=None, *, template=SPANTEMPLATE.SPAN, op=None, name=None, attributes=None
13661366
):
1367-
# type: (Optional[Callable[P, R]], SpanTemplate, Optional[str], Optional[str], Optional[dict[str, Any]]) -> Union[Callable[P, R], Callable[[Callable[P, R]], Callable[P, R]]]
1367+
# type: (Optional[Callable[P, R]], SPANTEMPLATE, Optional[str], Optional[str], Optional[dict[str, Any]]) -> Union[Callable[P, R], Callable[[Callable[P, R]], Callable[P, R]]]
13681368
"""
13691369
Decorator to start a child span.
13701370

sentry_sdk/tracing_utils.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -832,13 +832,13 @@ def _sample_rand_range(parent_sampled, sample_rate):
832832

833833

834834
def _get_span_name(template, name, kwargs=None):
835-
# type: (Union[str, "SpanTemplate"], str, Optional[dict[str, Any]]) -> str
835+
# type: (Union[str, "SPANTEMPLATE"], str, Optional[dict[str, Any]]) -> str
836836
"""
837837
Get the name of the span based on the template and the name.
838838
"""
839839
span_name = name
840840

841-
if template == SpanTemplate.AI_CHAT:
841+
if template == SPANTEMPLATE.AI_CHAT:
842842
model = None
843843
if kwargs and "model" in kwargs and isinstance(kwargs["model"], str):
844844
model = kwargs["model"]
@@ -849,42 +849,42 @@ def _get_span_name(template, name, kwargs=None):
849849

850850
span_name = f"chat {model}" if model else "chat"
851851

852-
elif template == SpanTemplate.AI_AGENT:
852+
elif template == SPANTEMPLATE.AI_AGENT:
853853
span_name = f"invoke_agent {name}"
854854

855-
elif template == SpanTemplate.AI_TOOL:
855+
elif template == SPANTEMPLATE.AI_TOOL:
856856
span_name = f"execute_tool {name}"
857857

858858
return span_name
859859

860860

861861
def _get_span_op(template):
862-
# type: (Union[str, "SpanTemplate"]) -> str
862+
# type: (Union[str, "SPANTEMPLATE"]) -> str
863863
"""
864864
Get the operation of the span based on the template.
865865
"""
866866
op = OP.FUNCTION
867867

868-
if template == SpanTemplate.AI_CHAT:
868+
if template == SPANTEMPLATE.AI_CHAT:
869869
op = OP.GEN_AI_CHAT
870870

871-
elif template == SpanTemplate.AI_AGENT:
871+
elif template == SPANTEMPLATE.AI_AGENT:
872872
op = OP.GEN_AI_INVOKE_AGENT
873873

874-
elif template == SpanTemplate.AI_TOOL:
874+
elif template == SPANTEMPLATE.AI_TOOL:
875875
op = OP.GEN_AI_EXECUTE_TOOL
876876

877877
return op
878878

879879

880880
def _get_input_attributes(template, send_pii, args, kwargs):
881-
# type: (Union[str, "SpanTemplate"], bool, tuple[Any, ...], dict[str, Any]) -> dict[str, Any]
881+
# type: (Union[str, "SPANTEMPLATE"], bool, tuple[Any, ...], dict[str, Any]) -> dict[str, Any]
882882
"""
883883
Get input attributes for the given span template.
884884
"""
885885
attributes = {} # type: dict[str, Any]
886886

887-
if template in [SpanTemplate.AI_AGENT, SpanTemplate.AI_TOOL, SpanTemplate.AI_CHAT]:
887+
if template in [SPANTEMPLATE.AI_AGENT, SPANTEMPLATE.AI_TOOL, SPANTEMPLATE.AI_CHAT]:
888888
for key, value in list(kwargs.items()):
889889
if key == "model" and isinstance(value, str):
890890
attributes[SPANDATA.GEN_AI_REQUEST_MODEL] = value
@@ -923,7 +923,7 @@ def _get_input_attributes(template, send_pii, args, kwargs):
923923
attributes[SPANDATA.GEN_AI_REQUEST_MESSAGES]
924924
)
925925

926-
if template == SpanTemplate.AI_TOOL:
926+
if template == SPANTEMPLATE.AI_TOOL:
927927
if send_pii:
928928
attributes[SPANDATA.GEN_AI_TOOL_INPUT] = safe_repr(
929929
{"args": args, "kwargs": kwargs}
@@ -956,13 +956,13 @@ def _get_usage_attributes(usage):
956956

957957

958958
def _get_output_attributes(template, send_pii, result):
959-
# type: (Union[str, "SpanTemplate"], bool, Any) -> dict[str, Any]
959+
# type: (Union[str, "SPANTEMPLATE"], bool, Any) -> dict[str, Any]
960960
"""
961961
Get output attributes for the given span template.
962962
"""
963963
attributes = {} # type: dict[str, Any]
964964

965-
if template in [SpanTemplate.AI_AGENT, SpanTemplate.AI_TOOL, SpanTemplate.AI_CHAT]:
965+
if template in [SPANTEMPLATE.AI_AGENT, SPANTEMPLATE.AI_TOOL, SPANTEMPLATE.AI_CHAT]:
966966
attributes.update(_get_usage_attributes(result))
967967
if hasattr(result, "usage"):
968968
attributes.update(_get_usage_attributes(result.usage))
@@ -975,15 +975,15 @@ def _get_output_attributes(template, send_pii, result):
975975
elif hasattr(result, "model_name") and isinstance(result.model_name, str):
976976
attributes[SPANDATA.GEN_AI_RESPONSE_MODEL] = result.model_name
977977

978-
if template == SpanTemplate.AI_TOOL:
978+
if template == SPANTEMPLATE.AI_TOOL:
979979
if send_pii:
980980
attributes[SPANDATA.GEN_AI_TOOL_OUTPUT] = safe_repr(result)
981981

982982
return attributes
983983

984984

985985
def _set_input_attributes(span, template, send_pii, name, f, args, kwargs):
986-
# type: (Span, Union[str, "SpanTemplate"], bool, str, Any, tuple[Any, ...], dict[str, Any]) -> None
986+
# type: (Span, Union[str, "SPANTEMPLATE"], bool, str, Any, tuple[Any, ...], dict[str, Any]) -> None
987987
"""
988988
Set span input attributes based on the given span template.
989989
@@ -996,16 +996,16 @@ def _set_input_attributes(span, template, send_pii, name, f, args, kwargs):
996996
"""
997997
attributes = {} # type: dict[str, Any]
998998

999-
if template == SpanTemplate.AI_AGENT:
999+
if template == SPANTEMPLATE.AI_AGENT:
10001000
attributes = {
10011001
SPANDATA.GEN_AI_OPERATION_NAME: "invoke_agent",
10021002
SPANDATA.GEN_AI_AGENT_NAME: name,
10031003
}
1004-
elif template == SpanTemplate.AI_CHAT:
1004+
elif template == SPANTEMPLATE.AI_CHAT:
10051005
attributes = {
10061006
SPANDATA.GEN_AI_OPERATION_NAME: "chat",
10071007
}
1008-
elif template == SpanTemplate.AI_TOOL:
1008+
elif template == SPANTEMPLATE.AI_TOOL:
10091009
attributes = {
10101010
SPANDATA.GEN_AI_OPERATION_NAME: "execute_tool",
10111011
SPANDATA.GEN_AI_TOOL_NAME: name,
@@ -1020,7 +1020,7 @@ def _set_input_attributes(span, template, send_pii, name, f, args, kwargs):
10201020

10211021

10221022
def _set_output_attributes(span, template, send_pii, result):
1023-
# type: (Span, Union[str, "SpanTemplate"], bool, Any) -> None
1023+
# type: (Span, Union[str, "SPANTEMPLATE"], bool, Any) -> None
10241024
"""
10251025
Set span output attributes based on the given span template.
10261026
@@ -1031,15 +1031,15 @@ def _set_output_attributes(span, template, send_pii, result):
10311031
"""
10321032
attributes = {} # type: dict[str, Any]
10331033

1034-
if template == SpanTemplate.AI_AGENT and isinstance(result, str):
1034+
if template == SPANTEMPLATE.AI_AGENT and isinstance(result, str):
10351035
attributes[SPANDATA.GEN_AI_TOOL_OUTPUT] = result
10361036

10371037
attributes.update(_get_output_attributes(template, send_pii, result))
10381038
span.set_data(attributes)
10391039

10401040

10411041
def create_span_decorator(template, op=None, name=None, attributes=None):
1042-
# type: (Union[str, "SpanTemplate"], Optional[str], Optional[str], Optional[dict[str, Any]]) -> Any
1042+
# type: (Union[str, "SPANTEMPLATE"], Optional[str], Optional[str], Optional[dict[str, Any]]) -> Any
10431043
"""
10441044
Create a span decorator that can wrap both sync and async functions.
10451045
@@ -1146,7 +1146,7 @@ def sync_wrapper(*args, **kwargs):
11461146

11471147

11481148
# Circular imports
1149-
from sentry_sdk.consts import SpanTemplate
1149+
from sentry_sdk.consts import SPANTEMPLATE
11501150
from sentry_sdk.tracing import (
11511151
BAGGAGE_HEADER_NAME,
11521152
LOW_QUALITY_TRANSACTION_SOURCES,

0 commit comments

Comments
 (0)