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_KEYfrom the OpenAI Platform
Launch Arize
- Sign in to your Arize AX account.
- From Space Settings, copy your Space ID and API Key. You will set them as
ARIZE_SPACE_IDandARIZE_API_KEYbelow.
Install
Add the dependencies tobuild.gradle:
Configure credentials
Setup tracing
Java doesn’t separate setup from runtime the way Python or TypeScript do — both happen in the samemain 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
- Open your Arize AX space and select project
langchain4j-tracing-example. - You should see a new trace within ~30–60 seconds (Arize’s Java OTLP ingest is slightly slower than the Python path) containing a
generateLLM span with the prompt, response, model name (gpt-5), and token-usage attributes attached. - If no traces appear, see Troubleshooting.
Troubleshooting
- No traces in Arize. Confirm
ARIZE_SPACE_IDandARIZE_API_KEYare set in the same shell that runsgradle run. The OTLP exporter logs atFINElevel — to surface delivery errors, addjava.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, addSimpleSpanProcessor.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. EachChatModel(orEmbeddingModel,StreamingChatModel, etc.) must explicitly attach the listener:.listeners(List.of(instrumentor.createModelListener())). Models built without it produce no spans. 401from OpenAI. VerifyOPENAI_API_KEYis set and has access togpt-5. SwapmodelName("gpt-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.
BatchSpanProcessorexports asynchronously. AlwaystracerProvider.forceFlush().join(...)andtracerProvider.shutdown().join(...)beforemainreturns. SLF4J(W): No SLF4J providers were found.Harmless — the OpenAI HTTP client looks for an SLF4J implementation. Addimplementation 'org.slf4j:slf4j-simple:2.0.9'tobuild.gradleto silence it (and get HTTP request logs).