Skip to main content
OpenInference provides Java instrumentation packages for popular AI frameworks and libraries. All packages are built on OpenTelemetry and follow the OpenInference semantic conventions.

Available Instrumentations

FrameworkPackage NameVersionMaven Central
LangChain4jopeninference-instrumentation-langchain4j0.1.5View on Maven Central
Spring AIopeninference-instrumentation-springAI0.1.0View on Maven Central

Core Packages

In addition to framework-specific instrumentations, OpenInference provides core packages:
PackageDescriptionVersionMaven Central
openinference-semantic-conventionsJava constants for OpenInference semantic conventions0.1.1View on Maven Central
openinference-instrumentationBase instrumentation utilities and OITracer0.1.1View on Maven Central

Installation

Gradle

Add the desired instrumentation to your build.gradle:

Maven

Add the desired instrumentation to your pom.xml:

Requirements

General Requirements

  • Java Version: Java 11 or higher (Java 17+ for Spring AI)
  • OpenTelemetry: OpenTelemetry Java 1.49.0 or higher
  • Build Tools: Gradle 7.0+ or Maven 3.6+

Framework-Specific Requirements

LangChain4j

  • LangChain4j 1.0.0 or higher
  • Java 11+

Spring AI

  • Spring AI 1.0.0 or higher
  • Micrometer Observation 1.15.0 or higher
  • Java 17+

Quick Start Examples

LangChain4j

Spring AI

Features

All OpenInference Java instrumentations provide:
  • Automatic Trace Capture: LLM calls, parameters, and responses
  • Token Usage Tracking: Prompt, completion, and total token counts
  • Message Tracing: Input/output messages with roles (user, assistant, system, tool)
  • Tool Call Tracing: Function names, arguments, and results
  • Error Tracking: Exceptions and error messages
  • Configurable Privacy: Hide sensitive input/output data
  • OpenTelemetry Native: Works with any OTel-compatible backend
  • Context Propagation: Distributed tracing support

OpenTelemetry Setup

All instrumentations require OpenTelemetry to be initialized. Here’s a basic setup:

Viewing Traces

Arize Phoenix is an open-source observability platform designed for LLM applications:
  1. Start Phoenix:
  2. Configure your application to send traces to http://localhost:4317
  3. View traces at http://localhost:6006

Other OpenTelemetry Backends

OpenInference instrumentations work with any OpenTelemetry-compatible backend:
  • Jaeger: Distributed tracing platform
  • Zipkin: Distributed tracing system
  • Grafana Tempo: Scalable distributed tracing backend
  • Cloud Services: AWS X-Ray, Google Cloud Trace, Azure Monitor

Semantic Conventions

OpenInference Java packages follow the OpenInference semantic conventions, which define:
  • Span Kinds: LLM, Chain, Tool, Agent, Retriever, Embedding, Reranker, Guardrail, Evaluator
  • Attributes: Standardized attribute names for model info, tokens, messages, etc.
  • Message Format: Structured format for capturing LLM conversations
Learn more in the Semantic Conventions documentation.

Common Patterns

Configuration Privacy Controls

All instrumentations support hiding sensitive data:

Graceful Shutdown

Always flush spans before shutdown:

Custom Attributes

Add custom attributes to your resource:

Troubleshooting

Dependency Conflicts

If you encounter OpenTelemetry version conflicts:

Missing Traces

  1. Verify OpenTelemetry is initialized before instrumentation
  2. Check that OTLP endpoint is reachable
  3. Ensure forceFlush() is called before application exit
  4. Enable debug logging: -Dio.opentelemetry.javaagent.debug=true

Performance Considerations

  • Use BatchSpanProcessor instead of SimpleSpanProcessor in production
  • Configure appropriate batch sizes and delays
  • Consider sampling for high-volume applications

Examples and Resources

Example Applications

Complete working examples are available in the OpenInference repository:

Community and Support

Contributing

Contributions are welcome! See the Contributing Guide for details.

License

All OpenInference Java packages are released under the Apache License 2.0.