Skip to content

[bot] RubyLLM provider-side batch completions (RubyLLM.batch) not instrumented #193

Description

@braintrust-bot

Summary

The ruby_llm gem provides RubyLLM.batch(chats) / RubyLLM::Batch.submit(chats) for submitting multiple chat completions as a provider-side batch job (e.g., OpenAI Batch API). This API is not instrumented by this SDK. The current RubyLLM integration only instruments RubyLLM::Chat#complete — individual synchronous completions. Batch submission is a distinct generative execution path that bypasses Chat#complete entirely and produces no spans today.

What is missing

RubyLLM.batch(chats) / RubyLLM::Batch.submit(chats) — submits an array of staged Chat objects to the provider as a batch job. Returns a RubyLLM::Batch object. The underlying provider API (e.g., OpenAI /v1/batches) queues the completions for asynchronous generation, typically completing within hours at reduced cost.

Key execution surface:

  • Batch.submit(chats) — the batch creation call: sends all queued chat requests to the provider. This is where a span should be created.
  • batch.messages — retrieves completed results (polling/retrieval; CRUD, out of scope).

What a span should capture

  • Input: number of chats submitted, model(s), provider
  • Metadata: batch id (returned by provider), provider, endpoint (e.g., /v1/batches), status on creation
  • Output: batch ID and initial status
  • Metrics: request_counts (total requests submitted), latency of the submit call

The span should be created at submit time, not at result retrieval time, since that is when the generative execution is initiated.

Why Chat#complete instrumentation does not cover this

Batch.submit calls the provider's batch API directly — it does not call Chat#complete for each chat. Staged chats have their requests serialized and sent as a single batch request. The existing ChatPatcher (which wraps Chat#complete) fires zero times during batch submission.

Braintrust docs status

not_found — The Braintrust RubyLLM integration docs at https://www.braintrust.dev/docs/integrations/sdk-integrations/ruby-llm document only chat completions, tool calls, token usage, and streaming. Batch processing is not mentioned.

Upstream sources

Local repo files inspected

  • lib/braintrust/contrib/ruby_llm/patcher.rb — defines only ChatPatcher (wraps Chat#complete); no BatchPatcher
  • lib/braintrust/contrib/ruby_llm/instrumentation/chat.rb — wraps Chat#complete and Chat#execute_tool only; Batch.submit takes a completely separate code path
  • lib/braintrust/contrib/ruby_llm/integration.rb — registers [ChatPatcher] only
  • Grep for batch, Batch, BatchPatcher, submit across lib/braintrust/contrib/ruby_llm/ returns zero matches

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Fields

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions