Skip to content

fix(watsonx): record list prompts with GenAIAttributes.GEN_AI_PROMPT - #4709

Open
Ygormorais wants to merge 2 commits into
traceloop:mainfrom
Ygormorais:fix/watsonx-list-prompt-attribute
Open

Ygormorais wants to merge 2 commits into
traceloop:mainfrom
Ygormorais:fix/watsonx-list-prompt-attribute

Conversation

@Ygormorais

@Ygormorais Ygormorais commented Nov 14, 2026 •

Copy link
Copy Markdown
  • 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. (Bug fix only: the reproduction output and unit tests are below.)
  • PR name follows conventional commits format: feat(instrumentation): ... or fix(instrumentation): ....
  • (If applicable) I have updated the documentation accordingly. (Not applicable.)

What

_set_input_attributes in the watsonx instrumentation uses SpanAttributes.GEN_AI_PROMPT when the prompt is a list:

f"{SpanAttributes.GEN_AI_PROMPT}.{index}.user"

opentelemetry.semconv_ai.SpanAttributes has no GEN_AI_PROMPT member (not in the published 0.5.1, not in the in-repo version), so this raises AttributeError. _handle_input is wrapped in @dont_throw, so the error is swallowed. The result:

  • list prompts (model.generate(prompt=["a", "b"])) are silently missing from the span
  • _emit_input_events is never reached for these calls, because it runs after the failing line

This PR uses GenAIAttributes.GEN_AI_PROMPT (already imported in the module, and the documented replacement for SpanAttributes.LLM_PROMPTS in semconv-ai's MIGRATION.md) for the list branch, and for the string branch too, which used LLM_PROMPTS. The attribute key stays gen_ai.prompt, so the string-prompt output is unchanged.

I checked the latest main and the 150 most recent PR heads: none changes this line.

Reproduction (before the fix)

string error=None  prompt attrs={'gen_ai.prompt.0.user': 'hello'}
list   error=AttributeError: type object 'SpanAttributes' has no attribute 'GEN_AI_PROMPT'  prompt attrs={}

Tests

Added tests/traces/test_input_attributes.py (no cassettes, no network): string prompt, list prompt passed as kwarg, list prompt passed positionally.

  • without the fix: 2 failed, 1 passed
  • with the fix: full watsonx suite passes (11 passed); ruff check . clean

🤖 Generated with Claude Code

https://claude.ai/code/session_019vQj79oorBrk3jGJ9eumPM

Summary by CodeRabbit

  • Improvements
    • Prompt telemetry now uses standardized GenAI attribute names for scalar and list inputs.
    • List prompts continue to retain indexed user attributes, including when provided positionally.

Ygormorais and others added 2 commits November 14, 2026 00:00
SpanAttributes.GEN_AI_PROMPT does not exist in opentelemetry.semconv_ai, so list prompts raised AttributeError, which @dont_throw swallowed: list prompts were silently dropped from the span and input events were not emitted. Use GenAIAttributes.GEN_AI_PROMPT (already imported; the documented replacement for LLM_PROMPTS) for the list and string branches. The attribute key is unchanged (gen_ai.prompt).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019vQj79oorBrk3jGJ9eumPM
Unit tests without cassettes or network: string prompt, list prompt as kwarg and list prompt passed positionally. The two list tests fail before the fix with AttributeError swallowed by @dont_throw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019vQj79oorBrk3jGJ9eumPM
@CLAassistant

CLAassistant commented Nov 14, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Watsonx prompt attributes now use the GenAI prompt namespace for scalar and list inputs. Tests cover trimmed string prompts, list prompts, and positional list prompts.

Changes: Watsonx prompt attributes

Layer / File(s) Summary
Prompt keys and tests
packages/opentelemetry-instrumentation-watsonx/opentelemetry/instrumentation/watsonx/__init__.py, packages/opentelemetry-instrumentation-watsonx/tests/traces/test_input_attributes.py
Scalar and list prompts use indexed gen_ai.prompt user attributes. Tests cover trimmed scalar prompts and keyword and positional lists.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: huang-cn

Merge Risk: Minimal · up to 67447

This fixes list prompts being silently dropped from watsonx spans, and the change is small and covered by new tests. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the fix (list prompts recorded with GenAIAttributes.GEN_AI_PROMPT in the watsonx instrumentation). The raw summary confirms the change swaps the prompt attribute namespace for scalar a…
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.
Full details: Title check

Explanation

The title names the fix (list prompts recorded with GenAIAttributes.GEN_AI_PROMPT in the watsonx instrumentation). The raw summary confirms the change swaps the prompt attribute namespace for scalar and list inputs, and the objectives describe replacing the nonexistent SpanAttributes.GEN_AI_PROMPT member. The title matches the main change, so it passes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 25668b20-98d4-41c3-9de3-b44b5a5ab8a2
Commits

Reviewing files that changed from the base of the PR and between e3d651a and 6744714.

Files selected for processing: 2

  • packages/opentelemetry-instrumentation-watsonx/opentelemetry/instrumentation/watsonx/__init__.py
  • packages/opentelemetry-instrumentation-watsonx/tests/traces/test_input_attributes.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

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