Repository navigation
feat(openai): Set gen_ai.response.finish_reasons on chat completion spans - #8028
manojmulammagari wants to merge 1 commit into
Conversation
chrikrah
left a comment
There was a problem hiding this comment.
@manojmulammagari the logic and tests hold at 9f0f067. The one open point is the attribute type, and that is a maintainer call. finish_reasons sits next to gen_ai.response.model, ungated, and response text stays behind data_collection.
$ cd <export of 9f0f067> && .venv/bin/python -m pytest tests/integrations/openai/ -q
697 passed, 926 warnings in 45.62s
# sentry_sdk/integrations/openai.py from 9f0f067^, your tests kept
75 failed, 622 passed, 926 warnings in 55.04s
FAILED tests/integrations/openai/test_openai.py::test_completions_token_usage_manual_output_counting_choices[True-True] - KeyError: 'gen_ai.response.finish_reasons'
# pytest 9.1.1, Python 3.14.7; not run: a live OpenAI call, ruff, the rest of the suite
The PR stores a raw list[str], as anthropic.py:682 already does. sentry-conventions types gen_ai.response.finish_reasons as "string", and open #7873 reports the list form as unsearchable under stream_gen_ai_spans=True.
@alexander-alderman-webb #5506 and #5507, the JSON-string fixes, closed unmerged. Is the list form the direction now, or should this wait for #7873?
|
Closing this because the |
Closes #8000
Part of #8004
Summary
choice.finish_reasonfrom OpenAI Chat Completion responses (non-streaming, sync streaming, and async streaming) and setsSPANDATA.GEN_AI_RESPONSE_FINISH_REASONS(gen_ai.response.finish_reasons) as alist[str]on bothSpanandStreamedSpan.finish_reasonisNoneand only sets the span attribute when at least one non-null finish reason is present.