Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[bot] OpenAI ResponseStream `text` method bypasses instrumentation

オープン 初心者向け
#155 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
ruby

調査の方向性

lib/braintrust/contrib/openai/instrumentation/responses.rb:118-183 から始めます。ここでは現在、ResponseStream が各 each をラップしています。lib/braintrust/contrib/openai/instrumentation/chat.rb:140-225 の対応するテキスト処理と比較してください。lib/braintrust/contrib/openai/patcher.rb:113-119 を確認してパッチ対象のクラスを特定し、その後、text を介して ResponseStream を消費すると、each を使用した場合でも二重に tracing されずに tracing が生成されることを検証してください。

索引モデルが issue の本文から書いたものです。

説明

Summary

The OpenAI ResponseStream instrumentation only wraps the each method, but the upstream OpenAI::Helpers::Streaming::ResponseStream class also exposes a text convenience method that bypasses each and returns text deltas directly. Users who consume the Responses API stream via stream.text.each { |t| ... } get zero tracing.

This is inconsistent within the same SDK: the Chat Completions integration wraps both each and text on ChatCompletionStream, but the Responses integration only wraps each on ResponseStream.

What is missing

ResponseStream#text is not wrapped. The upstream SDK's text method returns a fused chain yielding ResponseTextDeltaEvent content that reads from the underlying HTTP stream directly, bypassing the prepended each method on the ResponseStream object.

How the Chat integration handles this (for reference)

The Chat integration wraps both methods on ChatCompletionStream at lib/braintrust/contrib/openai/instrumentation/chat.rb:152-169:

module ChatCompletionStream
  module InstanceMethods
    def each(&block)        # line 152 — wrapped ✓
      ...
    end

    def text                # line 159 — wrapped ✓
      ...
      Enumerator.new do |y|
        trace_consumption(ctx) do
          original_enum.each { |t| y << t }
        end
      end
    end
  end
end

The same pattern should be applied to ResponseStream. The ctx[:consumed] guard already prevents double-tracing when both text and each are wrapped on the same object.

Upstream ResponseStream methods

The upstream class (OpenAI::Helpers::Streaming::ResponseStream) exposes:

  • each — wrapped ✓
  • text — NOT wrapped ✗ — bypasses each, reads from internal stream directly
  • until_done — covered (calls each internally)
  • get_final_response — covered (consumes stream via each)
  • get_output_text — covered (delegates to get_final_response)

Only text needs a wrapper because it is the only consumption method that bypasses each.

Braintrust docs status

not_found — Braintrust docs do not mention text as a stream consumption method or differentiate between stream consumption patterns.

Upstream sources

Local repo files inspected

  • lib/braintrust/contrib/openai/instrumentation/responses.rb:118-183 — ResponseStream module only wraps each (line 128)
  • lib/braintrust/contrib/openai/instrumentation/chat.rb:140-225 — ChatCompletionStream module wraps both each (line 152) and text (line 159)
  • lib/braintrust/contrib/openai/patcher.rb:113-119 — ResponsesPatcher.patch_response_stream patches ResponseStream class
主要言語
Ruby
スター
9
フォーク
11
平均マージ
3日 43分
マージ済み PR(30日)
9

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

braintrustdata/braintrust-sdk-ruby のほかの issue

braintrustdata/braintrust-sdk-ruby の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。