Skip to main content
Spring AI is a framework for building AI applications in Java. Braintrust traces chat calls made to OpenAI and Anthropic through Spring AI.

Tracing

To trace Spring AI with Braintrust’s Java SDK, use auto-instrumentation or manual instrumentation. Auto-instrumentation is the recommended path for most users.
The Braintrust Java agent instruments Spring AI chat models at JVM startup, so no changes to your application code are required.

Setup

Install the Braintrust Java SDK alongside the Spring AI module for each provider you use, then configure your API keys.
Braintrust instruments Spring AI 1.0.0 to 2.0.0 and requires Java 17 or later. Calls made with an unsupported Spring AI version still run, but produce no spans.
1

Install packages

2

Set environment variables

.env

Trace your application

To trace Spring AI calls without modifying your application code, attach the braintrust-java-agent at JVM startup. The agent intercepts every Spring AI chat model build and applies Braintrust instrumentation automatically.
1

Add the agent dependency

The agent is a separate artifact from the SDK. Add it as its own dependency configuration:
2

Run your app

Spring AI chat model builds in your application code are now intercepted automatically. No call to BraintrustSpringAI.wrap() is required. For Spring Boot, use ./gradlew bootRun instead.

What Braintrust traces

Braintrust traces each Spring AI chat model call that routes to a supported provider backend. Spring AI 2.x delegates HTTP to the official OpenAI and Anthropic Java SDKs, so spans carry the same fields as those integrations.Braintrust captures:
  • Chat model call spans for OpenAiChatModel (OpenAI backend) and AnthropicChatModel (Anthropic backend), with the request messages, model, and parameters.
  • Response content for each call.
  • Token usage metrics, including prompt and completion tokens.

Tracing resources