@@ -28,14 +28,26 @@ class TracingProcessor: # type: ignore[misc]
2828from opentelemetry .trace import Span , SpanKind , Tracer , set_span_in_context
2929from opentelemetry .trace .status import Status , StatusCode
3030
31+ SPAN_TYPE_GENERATION = "generation"
32+ SPAN_TYPE_RESPONSE = "response"
33+ SPAN_TYPE_AGENT = "agent"
34+ SPAN_TYPE_AGENT_CREATION = "agent_creation"
35+ SPAN_TYPE_FUNCTION = "function"
36+ SPAN_TYPE_SPEECH = "speech"
37+ SPAN_TYPE_TRANSCRIPTION = "transcription"
38+ SPAN_TYPE_SPEECH_GROUP = "speech_group"
39+ SPAN_TYPE_GUARDRAIL = "guardrail"
40+ SPAN_TYPE_HANDOFF = "handoff"
41+ SPAN_TYPE_MCP_TOOLS = "mcp_tools"
42+
3143_CLIENT_SPAN_TYPES = frozenset (
3244 {
33- "generation" ,
34- "response" ,
35- "speech" ,
36- "transcription" ,
37- "agent" ,
38- "agent_creation" ,
45+ SPAN_TYPE_GENERATION ,
46+ SPAN_TYPE_RESPONSE ,
47+ SPAN_TYPE_SPEECH ,
48+ SPAN_TYPE_TRANSCRIPTION ,
49+ SPAN_TYPE_AGENT ,
50+ SPAN_TYPE_AGENT_CREATION ,
3951 }
4052)
4153
@@ -160,21 +172,21 @@ def _operation_name(self, span_data: Any) -> str:
160172 if isinstance (explicit_operation , str )
161173 else None
162174 )
163- if span_type == "generation" :
175+ if span_type == SPAN_TYPE_GENERATION :
164176 if _looks_like_chat (getattr (span_data , "input" , None )):
165177 return GenAI .GenAiOperationNameValues .CHAT .value
166178 return GenAI .GenAiOperationNameValues .TEXT_COMPLETION .value
167- if span_type == "agent" :
179+ if span_type == SPAN_TYPE_AGENT :
168180 if normalized_operation in {"create" , "create_agent" }:
169181 return GenAI .GenAiOperationNameValues .CREATE_AGENT .value
170182 if normalized_operation in {"invoke" , "invoke_agent" }:
171183 return GenAI .GenAiOperationNameValues .INVOKE_AGENT .value
172184 return GenAI .GenAiOperationNameValues .INVOKE_AGENT .value
173- if span_type == "agent_creation" :
185+ if span_type == SPAN_TYPE_AGENT_CREATION :
174186 return GenAI .GenAiOperationNameValues .CREATE_AGENT .value
175- if span_type == "function" :
187+ if span_type == SPAN_TYPE_FUNCTION :
176188 return GenAI .GenAiOperationNameValues .EXECUTE_TOOL .value
177- if span_type == "response" :
189+ if span_type == SPAN_TYPE_RESPONSE :
178190 return GenAI .GenAiOperationNameValues .CHAT .value
179191 return span_type or "operation"
180192
@@ -375,29 +387,29 @@ def _attributes_from_generic(self, span_data: Any) -> dict[str, Any]:
375387
376388 def _attributes_for_span (self , span_data : Any ) -> dict [str , Any ]:
377389 span_type = getattr (span_data , "type" , None )
378- if span_type == "generation" :
390+ if span_type == SPAN_TYPE_GENERATION :
379391 return self ._attributes_from_generation (span_data )
380- if span_type == "response" :
392+ if span_type == SPAN_TYPE_RESPONSE :
381393 return self ._attributes_from_response (span_data )
382- if span_type == "agent" :
394+ if span_type == SPAN_TYPE_AGENT :
383395 operation = getattr (span_data , "operation" , None )
384396 if isinstance (operation , str ) and operation .strip ().lower () in {
385397 "create" ,
386398 "create_agent" ,
387399 }:
388400 return self ._attributes_from_agent_creation (span_data )
389401 return self ._attributes_from_agent (span_data )
390- if span_type == "agent_creation" :
402+ if span_type == SPAN_TYPE_AGENT_CREATION :
391403 return self ._attributes_from_agent_creation (span_data )
392- if span_type == "function" :
404+ if span_type == SPAN_TYPE_FUNCTION :
393405 return self ._attributes_from_function (span_data )
394406 if span_type in {
395- "guardrail" ,
396- "handoff" ,
397- "speech_group" ,
398- "speech" ,
399- "transcription" ,
400- "mcp_tools" ,
407+ SPAN_TYPE_GUARDRAIL ,
408+ SPAN_TYPE_HANDOFF ,
409+ SPAN_TYPE_SPEECH_GROUP ,
410+ SPAN_TYPE_SPEECH ,
411+ SPAN_TYPE_TRANSCRIPTION ,
412+ SPAN_TYPE_MCP_TOOLS ,
401413 }:
402414 return self ._attributes_from_generic (span_data )
403415 return self ._base_attributes ()
0 commit comments