AI / LangChain4j interview questions
How does LangChain4j integrate with observability tools like OpenTelemetry?
LangChain4j 0.31+ introduced native OpenTelemetry instrumentation for tracing LLM calls. When the langchain4j-open-telemetry module is on the classpath alongside an OTel SDK, LangChain4j automatically creates spans for each LLM call, embedding attributes from the OpenTelemetry Semantic Conventions for Generative AI Systems (draft spec).
Each span captures:
gen_ai.system— The LLM provider (e.g.,openai)gen_ai.request.model— The model name usedgen_ai.request.max_tokens— Max tokens configuredgen_ai.usage.input_tokens— Actual input tokens consumedgen_ai.usage.output_tokens— Actual output tokens generatedgen_ai.request.temperature— Temperature setting
For Spring Boot, adding the OTel Spring Boot starter alongside the LangChain4j OTel module is sufficient for automatic instrumentation:
<dependency> <groupId>dev.langchain4j</groupId> <artifactId>langchain4j-open-telemetry</artifactId> </dependency> <dependency> <groupId>io.opentelemetry.instrumentation</groupId> <artifactId>opentelemetry-spring-boot-starter</artifactId> </dependency>
With these in place, every LLM call appears as a span in your Jaeger, Zipkin, Grafana Tempo, or any OTLP-compatible backend — showing latency distribution across providers and models, token usage trends, and which AI services are called in which order within a user request. This is critical for diagnosing slow AI paths in production without guessing.
More Related questions...