Skip to content

fix(cohere): replace deprecated SpanAttributes with GenAIAttributes#3751

Open
pranay0703 wants to merge 3 commits intotraceloop:mainfrom
pranay0703:main
Open

fix(cohere): replace deprecated SpanAttributes with GenAIAttributes#3751
pranay0703 wants to merge 3 commits intotraceloop:mainfrom
pranay0703:main

Conversation

@pranay0703
Copy link
Copy Markdown

@pranay0703 pranay0703 commented Mar 2, 2026

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.

  • I have added tests that cover my changes.
  • If adding a new instrumentation or changing an existing one, I've added screenshots from some observability platform showing the change.
  • PR name follows conventional commits format: feat(instrumentation): ... or fix(instrumentation): ....
  • (If applicable) I have updated the documentation accordingly.

Summary by CodeRabbit

Release Notes

  • Chores
    • Updated Cohere instrumentation to align with the latest OpenTelemetry semantic conventions for telemetry attributes. Span attribute naming now follows current AI/LLM observability standards for improved consistency across observability tools.

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.
@ellipsis-dev
Copy link
Copy Markdown
Contributor

ellipsis-dev Bot commented Mar 2, 2026

⚠️ This PR is too big for Ellipsis, but support for larger PRs is coming soon. If you want us to prioritize this feature, let us know at help@ellipsis.dev


Generated with ❤️ by ellipsis.dev

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 2, 2026

📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Summary
Core Instrumentation
packages/opentelemetry-instrumentation-cohere/opentelemetry/instrumentation/cohere/__init__.py, packages/opentelemetry-instrumentation-cohere/opentelemetry/instrumentation/cohere/span_utils.py
Updated span attribute constants from SpanAttributes (LLM_SYSTEM, LLM_USAGE_COMPLETION_TOKENS, LLM_USAGE_PROMPT_TOKENS) to GenAIAttributes equivalents (GEN_AI_SYSTEM, GEN_AI_USAGE_OUTPUT_TOKENS, GEN_AI_USAGE_INPUT_TOKENS) across Cohere request/response handling.
Test Suite
packages/opentelemetry-instrumentation-cohere/tests/test_chat.py, packages/opentelemetry-instrumentation-cohere/tests/test_embed.py, packages/opentelemetry-instrumentation-cohere/tests/test_rerank.py
Replaced SpanAttributes constant references with GenAIAttributes equivalents in test assertions across chat, embed, and rerank test scenarios, including system, request model, prompt/completion, role, content, and token usage attributes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Hopping through the code with glee,
Old attributes now set semantically free,
From LLM to GenAI they gracefully dance,
A refactoring that gives the conventions a chance!
More harmony in the instrumentation we weave, 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.26% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: replacing deprecated SpanAttributes with GenAIAttributes across the Cohere instrumentation package.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 7a572e8 and 5289338.

⛔ Files ignored due to path filters (1)
  • packages/opentelemetry-instrumentation-cohere/uv.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • packages/opentelemetry-instrumentation-cohere/opentelemetry/instrumentation/cohere/__init__.py
  • packages/opentelemetry-instrumentation-cohere/opentelemetry/instrumentation/cohere/span_utils.py
  • packages/opentelemetry-instrumentation-cohere/tests/test_chat.py
  • packages/opentelemetry-instrumentation-cohere/tests/test_embed.py
  • packages/opentelemetry-instrumentation-cohere/tests/test_rerank.py

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 4, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants