> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openlayer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Spring AI

> Learn how to export Spring AI traces to Openlayer

<img width="700" style={{ borderRadius: "0.5rem" }} src="https://mintcdn.com/openlayer-44/zlWrng2mbxttdDP9/images/integrations/spring_ai_hero.png?fit=max&auto=format&n=zlWrng2mbxttdDP9&q=85&s=5e0fcc4e4f01c5b178973be81dd5d70d" alt="Spring AI hero" data-path="images/integrations/spring_ai_hero.png" />

[Spring AI](https://docs.spring.io/spring-ai/reference/) is a
Spring-based framework that helps you build AI applications. It comes with built-in OpenTelemetry
instrumentation, making it easy to export trace data.

This guide shows how to export Spring AI traces to Openlayer for observability
and evaluation.

## Configuration

The integration works by sending trace data to Openlayer's [OpenTelemetry endpoint](/integrations/opentelemetry).

<Tip>
  The full code used in this guide is available
  [here](https://colab.research.google.com/github/openlayer-ai/openlayer-python/blob/main/examples/tracing/semantic-kernel/semantic_kernel.ipynb).
</Tip>

To set it up, you need to:

<Steps>
  <Step title="Add dependencies">
    Make sure your project includes the following dependencies:

    * Spring Boot Actuator
    * Micrometer tracing with OpenTelemetry support
    * OTLP exporter

    For Maven projects, add the required dependencies to your pom.xml. (Gradle users can use the equivalent coordinates.)

    ```xml theme={null}
    <dependencyManagement>
      <dependencies>
          <dependency>
              <groupId>io.opentelemetry.instrumentation</groupId>
              <artifactId>opentelemetry-instrumentation-bom</artifactId>
              <version>2.13.2</version>
              <type>pom</type>
              <scope>import</scope>
          </dependency>
      </dependencies>

    </dependencyManagement>

    <dependencies>
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter</artifactId>
      </dependency>
      <dependency>
          <groupId>org.springframework.ai</groupId>
          <artifactId>spring-ai-openai-spring-boot-starter</artifactId>
          <version>1.0.0-M6</version>
      </dependency>
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
      </dependency>
      <dependency>
          <groupId>io.opentelemetry.instrumentation</groupId>
          <artifactId>opentelemetry-spring-boot-starter</artifactId>
      </dependency>
      <!-- Spring Boot actuator -->
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-actuator</artifactId>
      </dependency>
      <!-- Micrometer Observation-OpenTelemetry bridge -->
      <dependency>
          <groupId>io.micrometer</groupId>
          <artifactId>micrometer-tracing-bridge-otel</artifactId>
      </dependency>
      <!-- OpenTelemetry OTLP exporter -->
      <dependency>
          <groupId>io.opentelemetry</groupId>
          <artifactId>opentelemetry-exporter-otlp</artifactId>
      </dependency>
    </dependencies>
    ```
  </Step>

  <Step title="Configure Tracing in `application.yml`">
    With the dependencies in place, Spring Boot will auto-configure OpenTelemetry tracing.

    You just need to:

    * Set the OTLP endpoint (pointing to Openlayer)
    * Enable tracing for Spring AI

    Example configuration:

    ```yaml theme={null}
    spring:
      application:
        name: my-llm-app
      ai:
        chat:
          observations:
            include-prompt: true # Include prompt content in tracing (disabled by default for privacy)
            include-completion: true # Include completion content in tracing (disabled by default)
    management:
      tracing:
        sampling:
          probability: 1.0 # Sample 100% of requests for full tracing (adjust in production as needed)
      observations:
        annotations:
          enabled: true # Enable @Observed (if you use observation annotations in code)
    ```
  </Step>

  <Step title="Point to Openlayer's OpenTelemetry endpoint">
    Finally, point your application to Openlayer's OpenTelemetry endpoint via
    the following environment variables:

    ```bash theme={null}
    OTEL_EXPORTER_OTLP_ENDPOINT="https://api.openlayer.com/v1/otel"
    OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer YOUR_OPENLAYER_API_KEY_HERE, x-bt-parent=pipeline_id:YOUR_PIPELINE_ID_HERE"
    ```
  </Step>

  <Step title="Run LLMs and workflows as usual">
    Once instrumentation is set up, you can run your Spring application and LLM calls as usual.
    Trace data will be automatically captured and exported to Openlayer, where
    you can begin testing and analyzing it.
  </Step>
</Steps>
