CAMEL-24556: Add LangChain4jAgentObservabilityTest - #25909
Conversation
Add producer-level GenAI observability tests for langchain4j-agent, mirroring langchain4j-chat and langchain4j-embeddings coverage. Verifies generate_content spans with gen_ai.* attributes and token usage when enabled, and no telemetry when camel.aiObservability.enabled=false. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Automated review (Bugbot + Grok) completed:
AI-generated on behalf of atiaomar1978-hub |
Assert total token count, finish reason, and absent response model header on the enabled path; verify route body still works when observability is disabled. Co-authored-by: Cursor <cursoragent@cursor.com>
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 9 tested, 27 compile-only — current: 9 all testedMaveniverse Scalpel detected 36 affected modules (current approach: 9).
|
gnodet
left a comment
There was a problem hiding this comment.
🤖 AI-generated review on behalf of Guillaume Nodet
LGTM — clean, well-structured observability test. ✅
This closely follows the established pattern from LangChain4jChatObservabilityTest and LangChain4jEmbeddingsObservabilityTest. All assertions are correct against the actual GenAiAttributes constants, GenAiOperationName enum values, GenAiModelResolver behavior, and the agent producer's header-setting logic. The shouldNotEmitGenAiSpanWhenDisabled test is a valuable addition that the sister tests lack.
Two minor observations (not blocking):
-
Consider asserting
RESPONSE_MODELabsence in span tags (line ~137): The test correctly assertsHeaders.RESPONSE_MODELis null on the exchange header, since the agent producer passesnullforresponseModelinGenAiUsage.of(). For completeness, you could also verifytags.get(GenAiAttributes.RESPONSE_MODEL)is null — documenting the span-level behavior alongside the header-level one. -
Pre-existing pattern debt —
RecordingTracer/RecordingSpanduplication: The same inner classes are now copy-pasted across four test classes (GenAiObservabilitySpanTest,LangChain4jChatObservabilityTest,LangChain4jEmbeddingsObservabilityTest, and this one). As observability tests grow, extracting these into a shared test-support class would reduce maintenance burden. Not introduced by this PR — just noting for future consideration.
Nice work filling the observability gap for the agent component!
Summary
Adds producer-level GenAI observability test coverage for
langchain4j-agent, completing the gap identified during review of #25337 (Phase 1).LangChain4jAgentObservabilityTest— verifiesgenerate_contentspan emission withgen_ai.operation.name,gen_ai.system,gen_ai.request.model, token usage tags, and result headers when observability is enabledshouldNotEmitGenAiSpanWhenDisabled— verifies no telemetry whencamel.aiObservability.enabled=falsecamel-ai-observability,camel-telemetry, andcamel-test-junit6tocamel-langchain4j-agent/pom.xml(same pattern ascamel-langchain4j-chat)JIRA
https://issues.apache.org/jira/browse/CAMEL-24556
Testing
./mvnw test -pl components/camel-ai/camel-langchain4j-agent -Dtest=LangChain4jAgentObservabilityTestBoth tests pass.
AI-generated on behalf of atiaomar1978-hub