Skip to main content
This example demonstrates how to use OpenInference instrumentation with LangChain4j for building LLM applications in Java.

Prerequisites

  • Java 11+
  • Gradle or Maven
  • OpenAI API key
  • Phoenix running (or another OTLP-compatible collector)

Installation

1

Add dependencies to build.gradle

2

Set environment variables

Complete Example

Key Features

Model Listener Pattern

LangChain4j uses a listener pattern for instrumentation:

Tool/Function Calling

Define tools using annotations:

Resource Attributes

Use resource attributes to organize traces:

Graceful Shutdown

Always flush and shutdown the tracer provider:

Running with Gradle

Next Steps