Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[BOT ISSUE] OpenAI Responses API stream_raw() not instrumented

未关闭
#138 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
58/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
ruby
领域
observability

调研方向

从 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::Stream is patched by the ChatPatcher, the InternalStream module only traces when ctx[:stream_type] == :raw — a context value that only the Chat stream_raw wrapper sets. Responses stream_raw calls 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:

  1. Wrap Responses#stream_raw to store context (with a distinct stream_type) on the returned stream
  2. Either extend the existing InternalStream module 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.completed event (same as ResponseStream)
  • 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::Responses defines create, stream, stream_raw, retrieve, retrieve_streaming, delete, cancel, and compact
  • stream_raw returns OpenAI::Internal::Stream (yielding raw SSE events), distinct from stream which returns OpenAI::Helpers::Streaming::ResponseStream

Local repo files inspected

  • lib/braintrust/contrib/openai/instrumentation/responses.rb — wraps only create (line 35) and stream (line 59); no stream_raw method
  • lib/braintrust/contrib/openai/patcher.rb — ResponsesPatcher (line 76) patches ResponseStream but does not patch Internal::Stream for responses
  • lib/braintrust/contrib/openai/instrumentation/chat.rb:60-72 — shows how Chat's stream_raw is wrapped (the pattern to follow)
  • lib/braintrust/contrib/openai/patcher.rb:58-63 — shows Internal::Stream patching for Chat (with stream_type: :raw guard at chat.rb:242)
主要语言
Ruby
星标
9
派生
11
平均合并
2 天 3 小时
30 天内合并 PR
5

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

braintrustdata/braintrust-sdk-ruby 的其他 Issue

查看 braintrustdata/braintrust-sdk-ruby 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。