diff --git a/sentry_sdk/tracing_utils.py b/sentry_sdk/tracing_utils.py index b81d647c6d..f4e7e973b7 100644 --- a/sentry_sdk/tracing_utils.py +++ b/sentry_sdk/tracing_utils.py @@ -39,6 +39,12 @@ from types import FrameType +_MAPPING = { + SPANTEMPLATE.AI_CHAT: OP.GEN_AI_CHAT, + SPANTEMPLATE.AI_AGENT: OP.GEN_AI_INVOKE_AGENT, + SPANTEMPLATE.AI_TOOL: OP.GEN_AI_EXECUTE_TOOL, +} + SENTRY_TRACE_REGEX = re.compile( "^[ \t]*" # whitespace @@ -527,7 +533,9 @@ def _fill_sample_rand(self): ) return - self.dynamic_sampling_context["sample_rand"] = f"{sample_rand:.6f}" # noqa: E231 + self.dynamic_sampling_context["sample_rand"] = ( + f"{sample_rand:.6f}" # noqa: E231 + ) def _sample_rand(self): # type: () -> Optional[str] @@ -999,12 +1007,7 @@ def _get_span_op(template): """ Get the operation of the span based on the template. """ - mapping = { - SPANTEMPLATE.AI_CHAT: OP.GEN_AI_CHAT, - SPANTEMPLATE.AI_AGENT: OP.GEN_AI_INVOKE_AGENT, - SPANTEMPLATE.AI_TOOL: OP.GEN_AI_EXECUTE_TOOL, - } # type: dict[Union[str, SPANTEMPLATE], Union[str, OP]] - op = mapping.get(template, OP.FUNCTION) + op = _MAPPING.get(template, OP.FUNCTION) return str(op)