Skip to content

feat(together): add finish_reason attribute to spans#4136

Open
raghavenderreddygrudhanti wants to merge 2 commits into
traceloop:mainfrom
raghavenderreddygrudhanti:feat/together-add-finish-reason
Open

feat(together): add finish_reason attribute to spans#4136
raghavenderreddygrudhanti wants to merge 2 commits into
traceloop:mainfrom
raghavenderreddygrudhanti:feat/together-add-finish-reason

Conversation

@raghavenderreddygrudhanti
Copy link
Copy Markdown

@raghavenderreddygrudhanti raghavenderreddygrudhanti commented May 13, 2026

What

Adds gen_ai.response.finish_reason attribute to Together AI spans.

Why

Other instrumentations (OpenAI, Anthropic, Groq) already capture this attribute. It's useful for monitoring stop reasons (eos, length, stop) and alerting on unexpected truncations.

Changes

  • Added finish_reason extraction in span_utils.py
  • Added test assertion in test_chat.py

Summary by CodeRabbit

  • Bug Fixes

    • Telemetry now records the AI response completion reason in observability spans (captures finish reason or null).
  • Tests

    • Added/updated tests to validate response completion reason attributes in instrumentation tests.
  • Documentation

    • Improved docstrings for span-attribute helper functions to clarify their behavior.

Review Change Stack

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 01b047bd-813e-4b0f-babd-dfd520a35bda

📥 Commits

Reviewing files that changed from the base of the PR and between 7f4ea5a and 278dcf3.

📒 Files selected for processing (1)
  • packages/opentelemetry-instrumentation-together/opentelemetry/instrumentation/together/span_utils.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/opentelemetry-instrumentation-together/opentelemetry/instrumentation/together/span_utils.py

📝 Walkthrough

Walkthrough

The PR captures the model response finish reason into the span as gen_ai.response.finish_reason (from the first response choice) and adds a test assertion that it equals "eos".

Changes

Response finish reason tracking

Layer / File(s) Summary
Set response finish reason span attribute
packages/opentelemetry-instrumentation-together/opentelemetry/instrumentation/together/span_utils.py
Docstrings added for span helpers; set_model_completion_attributes sets SpanAttributes.GEN_AI_RESPONSE_FINISH_REASON from response.choices[0].finish_reason when choices exist, otherwise None.
Validate finish reason in tests
packages/opentelemetry-instrumentation-together/tests/test_chat.py
Test assertion added to verify together_span.attributes["gen_ai.response.finish_reason"] == "eos".

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I sniff the span, a tiny clue,
A finish reason peeks right through,
From choice one’s whisper, "eos" in tow,
I hop and trace the telemetry glow.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(together): add finish_reason attribute to spans' directly and clearly summarizes the main change: adding the finish_reason attribute to Together AI spans.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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
Author

@raghavenderreddygrudhanti raghavenderreddygrudhanti left a comment

Choose a reason for hiding this comment

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

Looks good overall. The GEN_AI_RESPONSE_FINISH_REASON attribute is being set safely with a fallback when response.choices is unavailable. I reviewed the implementation and validation layer.

Reviewed in CodeRabbit Review Stack

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.

3 participants