Skip to content

[bot] Add instrumentation wrapper for async-openai client #44

@braintrust-bot

Description

@braintrust-bot

Summary

The Braintrust Rust SDK has no wrapper for async-openai, the dominant Rust client for the OpenAI API. Every other Braintrust SDK provides an OpenAI client wrapper (wrapOpenAI in TypeScript, wrap_openai in Python, traceopenai.NewMiddleware in Go, BraintrustOpenAI.wrapOpenAI in Java, BraintrustOpenAI.WrapOpenAI in .NET, Braintrust.instrument!(:openai) in Ruby), but the Rust SDK has no equivalent.

What is missing

A wrap_openai-style function that takes an async-openai Client and returns a traced version that automatically creates spans for:

  • Chat completionsclient.chat().create() and client.chat().create_stream()
  • Responses APIclient.responses().create() and streaming variant
  • Embeddingsclient.embeddings().create()

The wrapper should capture inputs, outputs, model name, token usage, latency, and tool calls in Braintrust spans, matching the behavior of the OpenAI wrappers in other Braintrust SDKs.

The SDK already has building blocks that could support this:

  • extract_openai_usage() in src/extractors.rs parses OpenAI usage fields
  • wrap_stream_with_span() in src/stream.rs attaches spans to async streams
  • SpanBuilder / SpanHandle in src/span.rs for manual span creation

But there is no integration that wires these together around async-openai client calls.

Library significance

Braintrust docs status

supported (in other languages) — Braintrust documents OpenAI client wrapping for TypeScript, Python, Ruby, Go, Java, and .NET on the Trace LLM calls page and the OpenAI integration page. Rust is not listed as a supported language for OpenAI wrapping.

Upstream sources

Local files inspected

  • src/extractors.rsextract_openai_usage() parses OpenAI usage fields but is not wired to any client wrapper
  • src/stream.rswrap_stream_with_span() exists but is a generic stream helper, not an async-openai integration
  • src/span.rs — span creation infrastructure exists
  • src/lib.rs — public API exports; no async-openai references
  • Cargo.toml — no async-openai dependency
  • Full codebase search for "async-openai", "async_openai", "openai::Client" — zero results

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions