Observability for Spring AI (Java) with Opik
Observability for Spring AI (Java) with Opik
Observability for Spring AI (Java) with Opik
Spring AI is a framework designed to simplify the integration of AI and machine learning capabilities into Spring applications. It provides a familiar Spring-based programming model for working with AI models, vector stores, and AI-powered features, making it easier to build intelligent applications within the Spring ecosystem.
Spring AI’s primary advantage is its seamless integration with the Spring framework, allowing developers to leverage Spring’s dependency injection, configuration management, and testing capabilities while building AI-powered applications.
To use the Spring AI integration with Opik, you will need to have Spring AI and the required OpenTelemetry packages installed. The easiest way to start is to use the OPIK SpringAI starter project.
Before running the demo application, ensure you have the following installed:
Ensure you have Java 21 or higher installed.
The application requires the following environment variables to be set:
Configure your environment variables based on your Opik deployment:
If you are using Opik Cloud, you will need to set the following environment variables:
To log the traces to a specific project, you can add the
projectName parameter to the OTEL_EXPORTER_OTLP_HEADERS
environment variable:
You can also update the Comet-Workspace parameter to a different
value if you would like to log the data to a different workspace.
Set up OpenTelemetry instrumentation for Spring AI in your application.yaml:
Your Spring AI code will now automatically send traces to Opik:
After cloning the OPIK SpringAI starter repository, you can run the demo application using one of the following methods:
The application will start on http://localhost:8085
After that you can send a request to the application endpoints to interact with the chatbot:
Or POST request to the /api/chat/ask-enhanced endpoint with TAGS and METADATA in the body:
After running the demo application, you can view the traces in Opik by navigating to the Traces tab in the Projects page.

If you have any questions or suggestions for improving the Spring AI integration, please open an issue on our GitHub repository.