@@ -831,41 +831,41 @@ def _sample_rand_range(parent_sampled, sample_rate):
831831
832832
833833def _get_span_name (template , name ):
834- # type: (str, str) -> str
834+ # type: (Union[ str, "SpanTemplate"] , str) -> str
835835 """
836836 Get the name of the span based on the template and the name.
837837 """
838838 span_name = name
839839
840- if template == "ai_chat" :
840+ if template == SpanTemplate . AI_CHAT :
841841 span_name = "chat [MODEL]"
842- elif template == "ai_agent" :
842+ elif template == SpanTemplate . AI_AGENT :
843843 span_name = f"invoke_agent { name } "
844- elif template == "ai_tool" :
844+ elif template == SpanTemplate . AI_TOOL :
845845 span_name = f"execute_tool { name } "
846846
847847 return span_name
848848
849849
850850def _get_span_op (template ):
851- # type: (str) -> str
851+ # type: (Union[ str, "SpanTemplate"] ) -> str
852852 """
853853 Get the operation of the span based on the template.
854854 """
855855 op = OP .FUNCTION
856856
857- if template == "ai_chat" :
857+ if template == SpanTemplate . AI_CHAT :
858858 op = OP .GEN_AI_CHAT
859- elif template == "ai_agent" :
859+ elif template == SpanTemplate . AI_AGENT :
860860 op = OP .GEN_AI_INVOKE_AGENT
861- elif template == "ai_tool" :
861+ elif template == SpanTemplate . AI_TOOL :
862862 op = OP .GEN_AI_EXECUTE_TOOL
863863
864864 return op
865865
866866
867867def _set_input_attributes (span , template , args , kwargs ):
868- # type: (Span, str, tuple[Any, ...], dict[str, Any]) -> None
868+ # type: (Span, Union[ str, "SpanTemplate"] , tuple[Any, ...], dict[str, Any]) -> None
869869 """
870870 Set span input attributes based on the given template.
871871
@@ -878,16 +878,16 @@ def _set_input_attributes(span, template, args, kwargs):
878878
879879 # TODO: Implement actual input parameters for those templates :)
880880
881- if template == "ai_agent" :
881+ if template == SpanTemplate . AI_AGENT :
882882 attributes = {
883883 SPANDATA .GEN_AI_OPERATION_NAME : "invoke_agent" ,
884884 SPANDATA .GEN_AI_AGENT_NAME : span .description ,
885885 }
886- elif template == "ai_chat" :
886+ elif template == SpanTemplate . AI_CHAT :
887887 attributes = {
888888 SPANDATA .GEN_AI_OPERATION_NAME : "chat" ,
889889 }
890- elif template == "ai_tool" :
890+ elif template == SpanTemplate . AI_TOOL :
891891 attributes = {
892892 SPANDATA .GEN_AI_OPERATION_NAME : "execute_tool" ,
893893 SPANDATA .GEN_AI_TOOL_NAME : span .description ,
@@ -897,7 +897,7 @@ def _set_input_attributes(span, template, args, kwargs):
897897
898898
899899def _set_output_attributes (span , template , result ):
900- # type: (Span, str, Any) -> None
900+ # type: (Span, Union[ str, "SpanTemplate"] , Any) -> None
901901 """
902902 Set span output attributes based on the given template.
903903
@@ -913,7 +913,7 @@ def _set_output_attributes(span, template, result):
913913
914914
915915def create_span_decorator (template , op = None , name = None , attributes = None ):
916- # type: (str, Optional[str], Optional[str], Optional[dict[str, Any]]) -> Any
916+ # type: (Union[ str, "SpanTemplate"] , Optional[str], Optional[str], Optional[dict[str, Any]]) -> Any
917917 """
918918 Create a span decorator that can wrap both sync and async functions.
919919
@@ -1013,6 +1013,7 @@ def sync_wrapper(*args, **kwargs):
10131013 LOW_QUALITY_TRANSACTION_SOURCES ,
10141014 SENTRY_TRACE_HEADER_NAME ,
10151015)
1016+ from sentry_sdk .consts import SpanTemplate
10161017
10171018if TYPE_CHECKING :
10181019 from sentry_sdk .tracing import Span
0 commit comments