Skip to content

fix: add flattened OpenInference LLM attributes for annotations and replay#207

Merged
rapids-bot[bot] merged 2 commits into
NVIDIA:mainfrom
mnajafian-nv:fix/openclaw-openinference-llm-attrs
Jun 3, 2026
Merged

fix: add flattened OpenInference LLM attributes for annotations and replay#207
rapids-bot[bot] merged 2 commits into
NVIDIA:mainfrom
mnajafian-nv:fix/openclaw-openinference-llm-attrs

Conversation

@mnajafian-nv
Copy link
Copy Markdown
Contributor

@mnajafian-nv mnajafian-nv commented Jun 3, 2026

Overview

This PR adds flattened OpenInference LLM message and tool-call attributes from typed codec annotations, with a narrowly scoped fallback for OpenClaw replay request/response payloads.

  • I confirm this contribution is my own work, or I have the right to submit it under this project's license.
  • I searched existing issues and open pull requests, and this does not duplicate existing work.

Details

  • Emits flattened llm.input_messages.* and llm.output_messages.* attributes from typed annotated LLM requests and responses.
  • Emits llm.tools.*.tool.json_schema, llm.invocation_parameters, and llm.finish_reason when typed codec annotations provide them.
  • Adds an OpenClaw-specific replay fallback for request messages, system prompts, response content, and tool calls when annotations are unavailable.
  • Gates replay fallback to OpenClaw replay payload markers so generic unannotated payloads do not receive replay-only flattened attributes.
  • Excludes request headers and other non-observable transport metadata from exported OpenInference LLM attributes.
  • Updates OpenInference docs to distinguish annotation-backed attributes from OpenClaw replay-backed attributes.

Where should the reviewer start?

Start with crates/core/src/observability/openinference.rs, then review the focused coverage in crates/core/tests/unit/observability/openinference_tests.rs.

Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)

  • Relates to OpenClaw observability consistency work.

Validation

  • cargo fmt --all --check
  • cargo test -p nemo-relay openinference -- --nocapture
  • cargo test -p nemo-relay
  • cargo clippy -p nemo-relay --all-targets -- -D warnings
  • npm test --workspace=nemo-relay-openclaw

Additional local validation

  • Ran a real OpenClaw + NeMo Relay + Phoenix smoke.
  • Verified local ATIF and ATOF outputs and Phoenix trace ingestion for the OpenClaw replay path covered by this change.

Summary by CodeRabbit

  • New Features

    • Expanded LLM observability: emits flattened request/response message attributes, system prompts, tool schemas/calls, finish reasons, and invocation parameters, including for supported replay payloads.
  • Tests

    • Added unit and end-to-end tests covering annotated and replayed LLM payloads, attribute emission, and strengthened redaction/omission checks.
  • Documentation

    • Clarified OpenInference docs on when and how LLM attributes, usage counters, and tool metadata are exported.

…w replay

Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
@mnajafian-nv mnajafian-nv added this to the 0.4 milestone Jun 3, 2026
@mnajafian-nv mnajafian-nv self-assigned this Jun 3, 2026
@mnajafian-nv mnajafian-nv requested a review from a team as a code owner June 3, 2026 16:10
@mnajafian-nv mnajafian-nv added the Improvement improvement to existing functionality label Jun 3, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

Walkthrough

Refactors OpenInference LLM span attribute generation into helpers that emit flattened llm.* attributes (messages, system prompt, tool schema/calls, invocation parameters, finish reason) from codec-annotated payloads or parsed OpenClaw replay JSON; adds tests and docs.

Changes

OpenInference LLM Attribute Extraction Refactoring

Layer / File(s) Summary
Refactored entry points and codec imports
crates/core/src/observability/openinference.rs
Consolidated codec request/response type imports; start_attributes and end_attributes now compute an is_llm flag once and delegate LLM attribute population to helper functions.
Request attribute extraction: annotated and replay paths
crates/core/src/observability/openinference.rs
Core request logic: push_llm_request_attributes chooses between structured event.annotated_request() and replay payload extraction; annotated builder emits system prompt, invocation parameters, and message role/content; replay utilities detect and parse OpenClaw payloads from raw JSON.
Response attribute and tool call emission
crates/core/src/observability/openinference.rs
Response-side attribute generation: extraction of role/content/tool-calls from replay payloads, derivation of tool call names/arguments from multiple JSON shapes, emission under llm.output_messages.*.tool_calls.* keys, and mapping of FinishReason variants to strings.
Test infrastructure and assertion helpers
crates/core/tests/unit/observability/openinference_tests.rs
Reusable assertion helpers (assert_attr, assert_attr_contains, assert_no_attr_contains) and fixture constructors for empty and sample annotated request/response payloads.
Test coverage for LLM attribute emission
crates/core/tests/unit/observability/openinference_tests.rs
Updated redaction test; new unit tests validating OpenClaw replay attribute flattening and that unannotated output excludes message fields; comprehensive end-to-end test for annotated payloads covering system prompts, message details, tool schemas, tool calls, and finish reasons.
OpenInference documentation updates
docs/observability-plugin/openinference.mdx
Expanded documentation explaining how provider usage information, LLM messages, system prompts, and tool calls are emitted as flattened OpenInference attributes from codec annotations and replay payloads, with conditional emission of tool schema/finish reason/invocation parameters and exclusion of transport metadata.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • NVIDIA/NeMo-Relay#206: Both PRs update OpenInference LLM attribute emission in end_attributes, with this PR refactoring request/response attribute helpers and the retrieved PR extending cost-surfacing and usage-derived fields.
  • NVIDIA/NeMo-Relay#203: Both PRs modify OpenInference span attribute generation; this PR refactors LLM request/response attribute population with replay/annotated payload parsing, while the other extends usage and output value extraction for OpenAI/Anthropic cached token fields.

Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 1 warning)

Check name Status Explanation Resolution
Title check ❌ Error Title exceeds 72-character limit at 74 characters and uses 'fix' type appropriately, but violates length constraint. Reduce title to ≤72 characters. Consider: 'fix: flatten OpenInference LLM attributes for annotations and replay' (68 chars) or similar revision.
Docstring Coverage ⚠️ Warning Docstring coverage is 17.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed PR description is comprehensive, includes all required template sections with detailed implementation details, test coverage, and validation steps.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@github-actions github-actions Bot added size:L PR is large Bug issue describes bug; PR fixes bug lang:rust PR changes/introduces Rust code and removed Improvement improvement to existing functionality labels Jun 3, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

willkill07
willkill07 previously approved these changes Jun 3, 2026
Copy link
Copy Markdown
Member

@willkill07 willkill07 left a comment

Choose a reason for hiding this comment

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

Minor docs feedback

Comment thread docs/observability-plugin/openinference.mdx Outdated
Comment thread docs/observability-plugin/openinference.mdx Outdated
Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
@mnajafian-nv mnajafian-nv changed the title fix: add flattened OpenInference LLM attributes for annotations and OpenClaw replay fix: add flattened OpenInference LLM attributes for annotations and replay Jun 3, 2026
@willkill07
Copy link
Copy Markdown
Member

/merge

1 similar comment
@mnajafian-nv
Copy link
Copy Markdown
Contributor Author

/merge

@rapids-bot rapids-bot Bot merged commit 5db6ec9 into NVIDIA:main Jun 3, 2026
72 checks passed
@mnajafian-nv mnajafian-nv deleted the fix/openclaw-openinference-llm-attrs branch June 3, 2026 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug issue describes bug; PR fixes bug lang:rust PR changes/introduces Rust code size:L PR is large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants