Skip to main content
LangChain4j is the Java/Kotlin port of LangChain — a framework for composing LLM calls, tools, retrieval, and agents on the JVM. Arize AX captures every LangChain4j chat-model call via the com.arize:openinference-instrumentation-langchain4j artifact, attached as a model listener.

Prerequisites

  • Java 17+ (Java 11 also works, but the latest LangChain4j and OpenTelemetry releases test against 17+)
  • An Arize AX account (sign up)
  • An OPENAI_API_KEY from the OpenAI Platform

Launch Arize

  1. Sign in to your Arize AX account.
  2. From Space Settings, copy your Space ID and API Key. You will set them as ARIZE_SPACE_ID and ARIZE_API_KEY below.

Install

Add the dependencies to build.gradle:

Configure credentials

Setup tracing

Java doesn’t separate setup from runtime the way Python or TypeScript do — both happen in the same main method. Put the OpenTelemetry SDK initialization at the top, then use it for the rest of the program:

Run LangChain4j

Expected output

Verify in Arize

  1. Open your Arize AX space and select project langchain4j-tracing-example.
  2. You should see a new trace within ~30–60 seconds (Arize’s Java OTLP ingest is slightly slower than the Python path) containing a generate LLM span with the prompt, response, model name (gpt-5.5), and token-usage attributes attached.
  3. If no traces appear, see Troubleshooting.

Check from the skill, CLI, or SDK

Confirm spans are actually reaching your Arize AX project. Use whichever fits your workflow — the skill and CLI work for any framework; the SDK check is shown for each language.
Install the Arize Skills plugin and let your coding agent check for you:
Then prompt your agent:
Use the arize-trace skill to export and analyze recent traces from my project. Confirm spans are arriving, and summarize any errors or latency issues.

Troubleshooting

  • No traces in Arize. Confirm ARIZE_SPACE_ID and ARIZE_API_KEY are set in the same shell that runs gradle run. The OTLP exporter logs at FINE level — to surface delivery errors, add java.util.logging.Logger.getLogger("io.opentelemetry").setLevel(Level.FINE) before initialization, or wire a SLF4J implementation. To confirm spans are being produced locally before troubleshooting export, add SimpleSpanProcessor.create(LoggingSpanExporter.create()) as an extra processor — it prints every span to stderr.
  • No spans, but LangChain4jInstrumentor.instrument() ran. The instrumentor is not auto-global. Each ChatModel (or EmbeddingModel, StreamingChatModel, etc.) must explicitly attach the listener: .listeners(List.of(instrumentor.createModelListener())). Models built without it produce no spans.
  • 401 from OpenAI. Verify OPENAI_API_KEY is set and has access to gpt-5.5. Swap modelName("gpt-5.5") for a model your key can call.
  • request timed out. GPT-5 reasoning can exceed LangChain4j’s default 60s timeout. Bump it: OpenAiChatModel.builder()...timeout(Duration.ofMinutes(3))....
  • Spans dropped at JVM exit. BatchSpanProcessor exports asynchronously. Always tracerProvider.forceFlush().join(...) and tracerProvider.shutdown().join(...) before main returns.
  • SLF4J(W): No SLF4J providers were found. Harmless — the OpenAI HTTP client looks for an SLF4J implementation. Add implementation 'org.slf4j:slf4j-simple:2.0.9' to build.gradle to silence it (and get HTTP request logs).

Resources

LangChain4j Documentation

OpenInference LangChain4j Instrumentor (Maven Central)

OpenInference LangChain4j Source

LangChain4j Example (with tools + multi-turn)