Skip to content

[BOT ISSUE] Spring AI instrumentation limited to OpenAI and Anthropic chat models; no embedding model support #71

Description

@braintrust-bot

Summary

The Spring AI instrumentation module (springai_1_0_0) only wraps OpenAiChatModel.Builder and AnthropicChatModel.Builder. All other Spring AI chat model providers — including Google Vertex AI Gemini, Mistral, AWS Bedrock, and Azure OpenAI — are silently passed through with no instrumentation. Additionally, Spring AI's EmbeddingModel interface is not instrumented for any provider.

Unlike the analogous LangChain4j gap (#60), unsupported Spring AI providers generally cannot fall through to this repo's direct SDK auto-instrumentation modules. Spring AI providers use their own HTTP transport layers (Spring RestClient, Google Cloud libraries, Azure SDK, AWS SDK) rather than the upstream provider SDKs that the auto-instrumentation modules target (com.openai:openai-java, com.anthropic:anthropic-java, com.google.genai).

What is missing

1. Chat model providers beyond OpenAI and Anthropic

BraintrustSpringAI.wrap() (lines 17–39) checks the builder class name against two hardcoded strings:

private static final String OPENAI_BUILDER_CLASS =
        "org.springframework.ai.openai.OpenAiChatModel$Builder";
private static final String ANTHROPIC_BUILDER_CLASS =
        "org.springframework.ai.anthropic.AnthropicChatModel$Builder";

Unrecognized builders are returned unmodified with a log.info() message. No BraintrustObservationHandler is registered, so no spans are created.

The most impactful missing providers:

Spring AI module Provider Auto-instrumentation fallback?
spring-ai-vertex-ai-gemini Google Vertex AI Gemini No — uses google-cloud-vertexai, not com.google.genai
spring-ai-azure-openai Azure OpenAI No — uses com.azure:azure-ai-openai, not com.openai:openai-java
spring-ai-bedrock AWS Bedrock No — uses software.amazon.awssdk:bedrockruntime
spring-ai-mistral-ai Mistral AI No — uses Spring RestClient directly

The auto-instrumentation modules (SpringAIOpenAIInstrumentationModule, SpringAIAnthropicInstrumentationModule) similarly only register ByteBuddy advice for the two known builder classes.

2. Embedding model instrumentation

BraintrustObservationHandler implements ObservationHandler<ChatModelObservationContext> only. Spring AI also fires observations for embedding calls via EmbeddingModelObservationContext, but no handler is registered for these. This means all Spring AI embedding calls — including OpenAI and Anthropic embeddings through Spring AI — produce no Braintrust spans.

Spring AI's EmbeddingModel interface is implemented by OpenAiEmbeddingModel, VertexAiEmbeddingModel, BedrockEmbeddingModel, and others.

Braintrust docs status

Upstream sources

Local files inspected

  • braintrust-sdk/instrumentation/springai_1_0_0/src/main/java/dev/braintrust/instrumentation/springai/v1_0_0/BraintrustSpringAI.java — lines 17–39 (hardcoded builder class checks; unrecognized builders passed through)
  • braintrust-sdk/instrumentation/springai_1_0_0/src/main/java/dev/braintrust/instrumentation/springai/v1_0_0/BraintrustObservationHandler.java — implements ObservationHandler<ChatModelObservationContext> only; no EmbeddingModelObservationContext handler
  • braintrust-sdk/instrumentation/springai_1_0_0/src/main/java/dev/braintrust/instrumentation/springai/v1_0_0/OpenAIBuilderWrapper.java — OpenAI-specific tagging
  • braintrust-sdk/instrumentation/springai_1_0_0/src/main/java/dev/braintrust/instrumentation/springai/v1_0_0/AnthropicBuilderWrapper.java — Anthropic-specific tagging
  • braintrust-sdk/instrumentation/springai_1_0_0/src/main/java/dev/braintrust/instrumentation/springai/v1_0_0/auto/SpringAIOpenAIInstrumentationModule.java — only targets OpenAiChatModel$Builder.build()
  • braintrust-sdk/instrumentation/springai_1_0_0/src/main/java/dev/braintrust/instrumentation/springai/v1_0_0/auto/SpringAIAnthropicInstrumentationModule.java — only targets AnthropicChatModel$Builder.build()
  • braintrust-sdk/instrumentation/springai_1_0_0/src/test/java/dev/braintrust/instrumentation/springai/v1_0_0/BraintrustSpringAITest.java — parameterized tests only cover OpenAI and Anthropic; no embedding tests exist

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions