@@ -203,6 +203,14 @@ class OtelAttr(str, Enum):
203203 INPUT_MESSAGES = "gen_ai.input.messages"
204204 OUTPUT_MESSAGES = "gen_ai.output.messages"
205205 SYSTEM_INSTRUCTIONS = "gen_ai.system_instructions"
206+ # Attributes previously from opentelemetry-semantic-conventions-ai SpanAttributes,
207+ # removed in v0.4.14. Defined here for forward compatibility.
208+ SYSTEM = "gen_ai.system"
209+ REQUEST_MAX_TOKENS = "gen_ai.request.max_tokens"
210+ REQUEST_TEMPERATURE = "gen_ai.request.temperature"
211+ REQUEST_TOP_P = "gen_ai.request.top_p"
212+ REQUEST_MODEL = "gen_ai.request.model"
213+ RESPONSE_MODEL = "gen_ai.response.model"
206214
207215 # Workflow attributes
208216 WORKFLOW_ID = "workflow.id"
@@ -1167,7 +1175,7 @@ def get_response(
11671175 # in a different async context than creation — using use_span() would
11681176 # cause "Failed to detach context" errors from OpenTelemetry.
11691177 operation = attributes .get (OtelAttr .OPERATION , "operation" )
1170- span_name = attributes .get (SpanAttributes . LLM_REQUEST_MODEL , "unknown" )
1178+ span_name = attributes .get (OtelAttr . REQUEST_MODEL , "unknown" )
11711179 span = get_tracer ().start_span (f"{ operation } { span_name } " )
11721180 span .set_attributes (attributes )
11731181 if OBSERVABILITY_SETTINGS .SENSITIVE_DATA_ENABLED and messages :
@@ -1229,7 +1237,7 @@ async def _finalize_stream() -> None:
12291237 return wrapped_stream
12301238
12311239 async def _get_response () -> ChatResponse :
1232- with _get_span (attributes = attributes , span_name_attribute = SpanAttributes . LLM_REQUEST_MODEL ) as span :
1240+ with _get_span (attributes = attributes , span_name_attribute = OtelAttr . REQUEST_MODEL ) as span :
12331241 if OBSERVABILITY_SETTINGS .SENSITIVE_DATA_ENABLED and messages :
12341242 _capture_messages (
12351243 span = span ,
@@ -1539,16 +1547,16 @@ def _get_instructions_from_options(options: Any) -> str | None:
15391547OTEL_ATTR_MAP : dict [str | tuple [str , ...], tuple [str , Callable [[Any ], Any ] | None , bool , Any ]] = {
15401548 "choice_count" : (OtelAttr .CHOICE_COUNT , None , False , 1 ),
15411549 "operation_name" : (OtelAttr .OPERATION , None , False , None ),
1542- "system_name" : (SpanAttributes . LLM_SYSTEM , None , False , None ),
1550+ "system_name" : (OtelAttr . SYSTEM , None , False , None ),
15431551 "provider_name" : (OtelAttr .PROVIDER_NAME , None , False , None ),
15441552 "service_url" : (OtelAttr .ADDRESS , None , False , None ),
15451553 "conversation_id" : (OtelAttr .CONVERSATION_ID , None , True , None ),
15461554 "seed" : (OtelAttr .SEED , None , True , None ),
15471555 "frequency_penalty" : (OtelAttr .FREQUENCY_PENALTY , None , True , None ),
1548- "max_tokens" : (SpanAttributes . LLM_REQUEST_MAX_TOKENS , None , True , None ),
1556+ "max_tokens" : (OtelAttr . REQUEST_MAX_TOKENS , None , True , None ),
15491557 "stop" : (OtelAttr .STOP_SEQUENCES , None , True , None ),
1550- "temperature" : (SpanAttributes . LLM_REQUEST_TEMPERATURE , None , True , None ),
1551- "top_p" : (SpanAttributes . LLM_REQUEST_TOP_P , None , True , None ),
1558+ "temperature" : (OtelAttr . REQUEST_TEMPERATURE , None , True , None ),
1559+ "top_p" : (OtelAttr . REQUEST_TOP_P , None , True , None ),
15521560 "presence_penalty" : (OtelAttr .PRESENCE_PENALTY , None , True , None ),
15531561 "top_k" : (OtelAttr .TOP_K , None , True , None ),
15541562 "encoding_formats" : (
@@ -1561,7 +1569,7 @@ def _get_instructions_from_options(options: Any) -> str | None:
15611569 "agent_name" : (OtelAttr .AGENT_NAME , None , False , None ),
15621570 "agent_description" : (OtelAttr .AGENT_DESCRIPTION , None , False , None ),
15631571 # Multiple source keys - checks model_id in options, then model in kwargs, then model_id in kwargs
1564- ("model_id" , "model" ): (SpanAttributes . LLM_REQUEST_MODEL , None , True , None ),
1572+ ("model_id" , "model" ): (OtelAttr . REQUEST_MODEL , None , True , None ),
15651573 # Tools with validation - returns None if no valid tools
15661574 "tools" : (
15671575 OtelAttr .TOOL_DEFINITIONS ,
@@ -1718,7 +1726,7 @@ def _get_response_attributes(
17181726 if finish_reason :
17191727 attributes [OtelAttr .FINISH_REASONS ] = json .dumps ([finish_reason ])
17201728 if model_id := getattr (response , "model_id" , None ):
1721- attributes [SpanAttributes . LLM_RESPONSE_MODEL ] = model_id
1729+ attributes [OtelAttr . RESPONSE_MODEL ] = model_id
17221730 if capture_usage and (usage := response .usage_details ):
17231731 if usage .get ("input_token_count" ):
17241732 attributes [OtelAttr .INPUT_TOKENS ] = usage ["input_token_count" ]
@@ -1730,8 +1738,8 @@ def _get_response_attributes(
17301738GEN_AI_METRIC_ATTRIBUTES = (
17311739 OtelAttr .OPERATION ,
17321740 OtelAttr .PROVIDER_NAME ,
1733- SpanAttributes . LLM_REQUEST_MODEL ,
1734- SpanAttributes . LLM_RESPONSE_MODEL ,
1741+ OtelAttr . REQUEST_MODEL ,
1742+ OtelAttr . RESPONSE_MODEL ,
17351743 OtelAttr .ADDRESS ,
17361744 OtelAttr .PORT ,
17371745)
@@ -1749,10 +1757,10 @@ def _capture_response(
17491757 attrs : dict [str , Any ] = {k : v for k , v in attributes .items () if k in GEN_AI_METRIC_ATTRIBUTES }
17501758 if token_usage_histogram and (input_tokens := attributes .get (OtelAttr .INPUT_TOKENS )):
17511759 token_usage_histogram .record (
1752- input_tokens , attributes = {** attrs , SpanAttributes . LLM_TOKEN_TYPE : OtelAttr .T_TYPE_INPUT }
1760+ input_tokens , attributes = {** attrs , OtelAttr . T_TYPE : OtelAttr .T_TYPE_INPUT }
17531761 )
17541762 if token_usage_histogram and (output_tokens := attributes .get (OtelAttr .OUTPUT_TOKENS )):
1755- token_usage_histogram .record (output_tokens , {** attrs , SpanAttributes . LLM_TOKEN_TYPE : OtelAttr .T_TYPE_OUTPUT })
1763+ token_usage_histogram .record (output_tokens , {** attrs , OtelAttr . T_TYPE : OtelAttr .T_TYPE_OUTPUT })
17561764 if operation_duration_histogram and duration is not None :
17571765 if OtelAttr .ERROR_TYPE in attributes :
17581766 attrs [OtelAttr .ERROR_TYPE ] = attributes [OtelAttr .ERROR_TYPE ]
0 commit comments