fix(otel): coerce unknown finish_reason / response_id to None instead of stringifying

This commit is contained in:
Lucas Gomide
2026-05-28 14:12:19 -03:00
parent 14de68f79d
commit 90ce6855cf
2 changed files with 7 additions and 6 deletions

View File

@@ -1596,7 +1596,7 @@ class LLM(BaseLLM):
messages=params.get("messages"),
usage=usage_dict,
finish_reason=finish_reason,
response_id=response_id_last or response_id,
response_id=response_id_last,
)
return full_response
@@ -1622,7 +1622,7 @@ class LLM(BaseLLM):
messages=params.get("messages"),
usage=self._usage_to_dict(usage_info),
finish_reason=finish_reason,
response_id=response_id_last or response_id,
response_id=response_id_last,
)
return full_response
raise

View File

@@ -1385,7 +1385,9 @@ class GeminiCompletion(BaseLLM):
``.name`` attribute (e.g. ``"STOP"``, ``"MAX_TOKENS"``); we forward
it raw and let downstream telemetry map to the OTel GenAI enum.
"""
response_id = getattr(response, "response_id", None)
raw_response_id = getattr(response, "response_id", None)
response_id = raw_response_id if isinstance(raw_response_id, str) else None
finish_reason: str | None = None
candidates = getattr(response, "candidates", None)
if candidates:
@@ -1394,9 +1396,8 @@ class GeminiCompletion(BaseLLM):
except (IndexError, TypeError, KeyError):
candidate_finish = None
if candidate_finish is not None:
finish_reason = getattr(candidate_finish, "name", None) or str(
candidate_finish
)
name = getattr(candidate_finish, "name", None)
finish_reason = name if isinstance(name, str) else None
return finish_reason, response_id
@staticmethod