feat(langchain) GenAI semconv compliance#3822
feat(langchain) GenAI semconv compliance#3822max-deygin-traceloop wants to merge 6 commits intomax/tlp-1925-python-sdk-otel-semantic-conventionfrom
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
740ee81 to
6401889
Compare
072b0ac to
1400d4e
Compare
35fa2f9 to
63b8553
Compare
|
|
||
| # Record token usage metrics | ||
| vendor = span.attributes.get(GenAIAttributes.GEN_AI_SYSTEM, "Langchain") | ||
| vendor = span.attributes.get(GenAIAttributes.GEN_AI_SYSTEM, "langchain") |
There was a problem hiding this comment.
@max-deygin-traceloop @OzBenSimhonTraceloop we need to set also GEN_AI_PROVIDER_NAME
here:
https://github.com/traceloop/openllmetry/pull/3808/changes#r2959993030
…→ GEN_AI_ - Replace SpanAttributes.LLM_REQUEST_FUNCTIONS with GenAIAttributes.GEN_AI_TOOL_DEFINITIONS - Replace SpanAttributes.LLM_REQUEST_TYPE with GenAIAttributes.GEN_AI_OPERATION_NAME - Replace SpanAttributes.LLM_USAGE_TOTAL_TOKENS with SpanAttributes.GEN_AI_USAGE_TOTAL_TOKENS - Update test_llms.py, test_tool_calls.py, test_langgraph.py accordingly - Add test_semconv_compliance.py Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…nitions to JSON array Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Replace flat gen_ai.prompt.{i}.* attributes with GEN_AI_INPUT_MESSAGES JSON array
- Replace flat gen_ai.completion.{i}.* attributes with GEN_AI_OUTPUT_MESSAGES JSON array
- Convert _set_chat_tool_calls (flat span attrs) to _build_tool_calls_list (returns list)
- Fix vendor_detection: "Anthropic" → "anthropic" to match OTel semconv lowercase
- Update all affected tests to parse GEN_AI_INPUT/OUTPUT_MESSAGES JSON arrays
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…emove debug print - vendor_detection.py: use canonical GenAISystem string values for all vendors (AWS → aws.bedrock, HuggingFace → hugging_face, Google → google, Azure → az.ai.openai, Cohere → cohere, Ollama → ollama, Together → together_ai, Replicate → replicate, Fireworks → fireworks, Groq → groq, MistralAI → mistral_ai) - span_utils.py: remove debug print() from production exception handler - tests: update GEN_AI_SYSTEM assertions to match new lowercase values Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ck, add vendor unit tests - vendor_detection.py: Google/Vertex AI → "gcp.gen_ai" (matches GenAISystem.GOOGLE) - vendor_detection.py: both fallback returns "Langchain" → "langchain" (matches GenAISystem.LANGCHAIN) - callback_handler.py: two GEN_AI_SYSTEM default fallbacks "Langchain" → "langchain" - span_utils.py: GEN_AI_SYSTEM default fallback "Langchain" → "langchain" - tests: add parameterized test_vendor_detection.py covering all 13 vendors + default fallback Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
63b8553 to
aadef1d
Compare
Migrate LangChain instrumentation to OTel GenAI semconv
Aligns the LangChain instrumentation with the upstream OpenTelemetry GenAI semantic
conventions.
Changes:
SpanAttributes.LLM_*constants with upstreamGenAIAttributes.GEN_AI_*equivalentsgen_ai.prompt.{i}.*/gen_ai.completion.{i}.*attributes togen_ai.input.messages/gen_ai.output.messagesJSON arrays (set_llm_request,set_chat_request,set_chat_response)gen_ai.tool.definitions.{i}.*attributes togen_ai.tool.definitionsJSON array
_set_chat_tool_calls(flat span attrs) with_build_tool_calls_list(returns list for embedding in JSON)
gen_ai.operation.namebug incallback_handler.py"Anthropic"→"anthropic"to match OTel semconvgen_ai.input.messages/gen_ai.output.messagesJSON arrays