[BOT ISSUE] OpenAI Responses API stream_raw() not instrumented
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 58/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- ruby
调研方向
从 lib/braintrust/contrib/openai/instrumentation/responses.rb 开始,并将其中的 create 和 stream 包装器与 lib/braintrust/contrib/openai/instrumentation/chat.rb:60-72 进行比较。然后检查 lib/braintrust/contrib/openai/patcher.rb 中的 ResponsesPatcher 和 Internal::Stream 处理;当 Responses stream_raw 生成包含指定输入、聚合输出、元数据和指标的 tracing 时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Summary
The official OpenAI Ruby gem provides client.responses.stream_raw() which returns an OpenAI::Internal::Stream of raw server-sent events. This method is not instrumented, meaning users who call stream_raw instead of stream on the Responses API get zero tracing.
This is inconsistent with the Chat Completions integration in this same SDK, which already instruments stream_raw alongside create and stream.
What is missing
OpenAI::Resources::Responses#stream_raw— not wrapped, no context is set on the returned stream object- Although
OpenAI::Internal::Streamis patched by theChatPatcher, theInternalStreammodule only traces whenctx[:stream_type] == :raw— a context value that only the Chatstream_rawwrapper sets. Responsesstream_rawcalls pass through completely untraced.
How the Chat integration handles this (for reference)
The Chat integration wraps stream_raw at lib/braintrust/contrib/openai/instrumentation/chat.rb:60-72, storing context on the stream object with stream_type: :raw. The ChatPatcher then patches OpenAI::Internal::Stream at lib/braintrust/contrib/openai/patcher.rb:58-63 to create spans on consumption.
A similar pattern would be needed for Responses:
- Wrap
Responses#stream_rawto store context (with a distinctstream_type) on the returned stream - Either extend the existing
InternalStreammodule to handle the responses stream type, or create a dedicated stream handler
What a span should capture
- Input: the response input (text, conversation items, etc.)
- Output: aggregated output items from
response.completedevent (same asResponseStream) - Metadata: model, instructions, tools, provider, endpoint, stream flag
- Metrics: input_tokens, output_tokens, time_to_first_token
Braintrust docs status
not_found — Braintrust tracing docs at https://www.braintrust.dev/docs/guides/traces and OpenAI integration docs do not specifically mention stream_raw for any provider.
Upstream sources
- Official OpenAI Ruby SDK: https://github.com/openai/openai-ruby —
OpenAI::Resources::Responsesdefinescreate,stream,stream_raw,retrieve,retrieve_streaming,delete,cancel, andcompact stream_rawreturnsOpenAI::Internal::Stream(yielding raw SSE events), distinct fromstreamwhich returnsOpenAI::Helpers::Streaming::ResponseStream
Local repo files inspected
lib/braintrust/contrib/openai/instrumentation/responses.rb— wraps onlycreate(line 35) andstream(line 59); nostream_rawmethodlib/braintrust/contrib/openai/patcher.rb—ResponsesPatcher(line 76) patchesResponseStreambut does not patchInternal::Streamfor responseslib/braintrust/contrib/openai/instrumentation/chat.rb:60-72— shows how Chat'sstream_rawis wrapped (the pattern to follow)lib/braintrust/contrib/openai/patcher.rb:58-63— showsInternal::Streampatching for Chat (withstream_type: :rawguard atchat.rb:242)
- 主要语言
- Ruby
- 星标
- 9
- 派生
- 11
- 平均合并
- 2 天 3 小时
- 30 天内合并 PR
- 5
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
braintrustdata/braintrust-sdk-ruby 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 76/100
-
难度 2/5 1-3 小时 新手友好度 72/100
-
ruby
难度 3/5 半天 新手友好度 62/100
-
ruby
难度 3/5 1-2 天 新手友好度 45/100
查看 braintrustdata/braintrust-sdk-ruby 的全部 Issue
相似的 Issue
-
难度 1/5 1-3 小时 新手友好度 66/100
betagouv/conseillers-entreprises#4770 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 85/100
seek4science/seek#2762 ·
维护者通常 5 天内回复
-
难度 2/5 1-3 小时 新手友好度 67/100
Freika/dawarich#3910 · 3 个 reaction ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
rubyevents/rubyevents#2277 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 92/100
维护者通常 2 天内回复