fix(cohere): replace deprecated SpanAttributes with GenAIAttributes#3751
fix(cohere): replace deprecated SpanAttributes with GenAIAttributes#3751pranay0703 wants to merge 3 commits intotraceloop:mainfrom
Conversation
Fixes AttributeError caused by removal of LLM_SYSTEM, LLM_USAGE_COMPLETION_TOKENS, etc. in opentelemetry-semantic-conventions-ai v0.4.14 by using standard GenAIAttributes.
|
Generated with ❤️ by ellipsis.dev |
📝 WalkthroughWalkthroughThis pull request systematically updates the Cohere instrumentation package to use the new GenAIAttributes semantic convention constants instead of the legacy SpanAttributes constants. The refactoring affects attribute naming for system identification, request models, prompts, completions, and token usage tracking across implementation and test files, with no changes to control flow or functionality. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/opentelemetry-instrumentation-cohere/tests/test_chat.py (1)
339-371: De-duplicate repeated tool-call assertions in this block.This section reasserts the same tool-call keys multiple times, which adds noise without increasing signal.
♻️ Suggested cleanup
- assert ( - span1.attributes.get(f"{GenAIAttributes.GEN_AI_COMPLETION}.0.tool_calls.1.name") - == res1.message.tool_calls[1].function.name - ) - assert ( - span1.attributes.get(f"{GenAIAttributes.GEN_AI_COMPLETION}.0.tool_calls.1.arguments") - == res1.message.tool_calls[1].function.arguments - ) - - assert ( - span1.attributes.get(f"{GenAIAttributes.GEN_AI_COMPLETION}.0.tool_calls.0.id") - == res1.message.tool_calls[0].id - ) - assert ( - span1.attributes.get(f"{GenAIAttributes.GEN_AI_COMPLETION}.0.tool_calls.0.name") - == res1.message.tool_calls[0].function.name - ) - assert ( - span1.attributes.get(f"{GenAIAttributes.GEN_AI_COMPLETION}.0.tool_calls.0.arguments") - == res1.message.tool_calls[0].function.arguments - ) - assert ( - span1.attributes.get(f"{GenAIAttributes.GEN_AI_COMPLETION}.0.tool_calls.1.id") - == res1.message.tool_calls[1].id - ) - assert ( - span1.attributes.get(f"{GenAIAttributes.GEN_AI_COMPLETION}.0.tool_calls.1.name") - == res1.message.tool_calls[1].function.name - ) - assert ( - span1.attributes.get(f"{GenAIAttributes.GEN_AI_COMPLETION}.0.tool_calls.1.arguments") - == res1.message.tool_calls[1].function.arguments - ) + # keep a single assertion set for each tool_call field🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/opentelemetry-instrumentation-cohere/tests/test_chat.py` around lines 339 - 371, The assertions for tool_calls are duplicated; remove the repeated blocks and keep a single set of assertions per tool call index—specifically update the assertions around span1, GenAIAttributes.GEN_AI_COMPLETION and res1.message.tool_calls so that for each index (e.g., 0 and 1) you assert .id, .function.name, and .function.arguments exactly once (using span1.attributes.get(f"{GenAIAttributes.GEN_AI_COMPLETION}.0.tool_calls.{i}.id") / .name / .arguments == res1.message.tool_calls[i].id / .function.name / .function.arguments), deleting the redundant repeated assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/opentelemetry-instrumentation-cohere/tests/test_chat.py`:
- Around line 339-371: The assertions for tool_calls are duplicated; remove the
repeated blocks and keep a single set of assertions per tool call
index—specifically update the assertions around span1,
GenAIAttributes.GEN_AI_COMPLETION and res1.message.tool_calls so that for each
index (e.g., 0 and 1) you assert .id, .function.name, and .function.arguments
exactly once (using
span1.attributes.get(f"{GenAIAttributes.GEN_AI_COMPLETION}.0.tool_calls.{i}.id")
/ .name / .arguments == res1.message.tool_calls[i].id / .function.name /
.function.arguments), deleting the redundant repeated assertions.
ℹ️ Review info
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled
You can enable these sources in your CodeRabbit configuration.
⛔ Files ignored due to path filters (1)
packages/opentelemetry-instrumentation-cohere/uv.lockis excluded by!**/*.lock
📒 Files selected for processing (5)
packages/opentelemetry-instrumentation-cohere/opentelemetry/instrumentation/cohere/__init__.pypackages/opentelemetry-instrumentation-cohere/opentelemetry/instrumentation/cohere/span_utils.pypackages/opentelemetry-instrumentation-cohere/tests/test_chat.pypackages/opentelemetry-instrumentation-cohere/tests/test_embed.pypackages/opentelemetry-instrumentation-cohere/tests/test_rerank.py
Fixes AttributeError caused by removal of LLM_SYSTEM, LLM_USAGE_COMPLETION_TOKENS, etc. in opentelemetry-semantic-conventions-ai v0.4.14 by using standard GenAIAttributes.
Thanks for submitting a PR! To make sure this gets merged quickly, make sure to check the following checkboxes.
feat(instrumentation): ...orfix(instrumentation): ....Summary by CodeRabbit
Release Notes