Skip to content

fix(litellm): record seed, stop sequences and penalty request attributes - #4607

Open
shantam77 wants to merge 1 commit into
traceloop:mainfrom
shantam77:fix/litellm-request-attributes
Open

shantam77 wants to merge 1 commit into
traceloop:mainfrom
shantam77:fix/litellm-request-attributes

Conversation

@shantam77

@shantam77 shantam77 commented Oct 11, 2026 •

Copy link
Copy Markdown

Fixes #4598

Problem

_set_request_attributes in the litellm instrumentation only recorded model, temperature, top_p and max_tokens. seed, stop, frequency_penalty and presence_penalty were passed through to the provider but never ended up on the span, even though the GenAI semconv defines attributes for all of them.

Fix

Set gen_ai.request.seed, gen_ai.request.stop_sequences, gen_ai.request.frequency_penalty and gen_ai.request.presence_penalty from kwargs. litellm accepts stop as either a string or a list, while semconv defines stop_sequences as a string array, so a plain string is wrapped in a list before it's recorded. An empty string is still skipped, same as before.

Testing

Added a parametrized test in test_completion.py covering stop passed as a list and as a string. Full package suite passes locally (32 passed, 1 skipped) and ruff check is clean.

Ran the repro from the issue against this branch:

Before (from the issue):

gen_ai.request.model = openai/gpt-4o-mini
gen_ai.request.temperature = 0.3
gen_ai.request.top_p = 0.9
gen_ai.request.max_tokens = 50

After:

{'gen_ai.request.model': 'openai/gpt-4o-mini', 'gen_ai.request.temperature': 0.3, 'gen_ai.request.top_p': 0.9, 'gen_ai.request.max_tokens': 50, 'gen_ai.request.seed': 7, 'gen_ai.request.stop_sequences': ('END',), 'gen_ai.request.frequency_penalty': 0.1, 'gen_ai.request.presence_penalty': 0.2}
  • 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. (span attributes from the repro above)
  • PR name follows conventional commits format: feat(instrumentation): ... or fix(instrumentation): ....

I used Claude Code (Opus 5.5) to help navigate the codebase and review the change; I wrote and tested the fix myself.

Summary by CodeRabbit

  • Enhancements
    • Request tracing now includes the seed, stop sequences, frequency penalty, and presence penalty. A single stop string is recorded in the same format as a one-item stop list.

@CLAassistant

CLAassistant commented Oct 11, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fc901f92-3694-4bcc-a19c-23af1126243c

📥 Commits

Reviewing files that changed from the base of the PR and between 17d0c5a and b586d62.


📒 Files selected for processing (2)
  • packages/opentelemetry-instrumentation-litellm/opentelemetry/instrumentation/litellm/__init__.py
  • packages/opentelemetry-instrumentation-litellm/tests/test_completion.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.



📝 Walkthrough

Walkthrough

The LiteLLM instrumentation now records request seed, stop sequences, frequency penalty, and presence penalty as span attributes. A test checks these attributes and verifies that a string stop value is recorded as a one-item tuple.

Changes

LiteLLM request attributes

Layer / File(s) Summary
Record and test request attributes
packages/opentelemetry-instrumentation-litellm/opentelemetry/instrumentation/litellm/__init__.py, packages/opentelemetry-instrumentation-litellm/tests/test_completion.py
The instrumentation records seed, stop sequences, frequency penalty, and presence penalty. The test covers string and list inputs for stop and checks the recorded attribute values.

Priority: ⬇️ Low

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

Change: Bug fix · Severity of issue fixed: Low


Merge Risk | ⚪ Minimal · up to b586d

Merge Risk: ⚪ Minimal · up to b586d

No material user-facing or operational failure is established in this change. The added attributes and stop-value normalization are covered by the supplied tests, so the change presents minimal merge risk.

Security Architecture Review

Security architecture risk: 🔵 Low · up to b586d

The change adds request metadata to traces without changing provider arguments or privileges. Stop strings are recorded even when prompt capture is disabled; their privacy impact depends on how applications construct them and who can access the traces. No security-control violation was established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The incremental exposure is caller-supplied request values entering the application's tracing pipeline. Stop strings extend the free-form data available to trace consumers. The inspected library path does not establish external attacker reachability, cross-tenant trace access, exporter destinations, or the sensitivity of those strings.

Trust Boundaries and Controls

  • observed — TRACELOOP_TRACE_CONTENT is documented as controlling prompt, completion, and embedding capture. Prompt attribute recording checks that predicate, but request-attribute recording does not. Existing model, temperature, top-p, and max-token metadata already used this ungated path; stop sequences are newly added. The documentation does not explicitly classify stop sequences as protected content.

Hardening Proposals

  • proposed — Explicitly classify stop sequences in the telemetry privacy contract. If applications may derive them from sensitive data, consider content-controlled recording or redaction; otherwise document that content suppression leaves request-control metadata enabled.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: recording LiteLLM request attributes for seed, stop sequences, and penalty values.
Linked Issues check Passed Issue #4598 requires LiteLLM spans to record seed, stop sequences, frequency penalty, and presence penalty. The PR adds all four attributes in _set_request_attributes. It converts a non-empty string…
Out of Scope Changes check Passed The PR changes only LiteLLM request-attribute recording and its completion tests. The implementation and tests directly support issue #4598. No unrelated behavior or package scope is evident.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@shantam77

Copy link
Copy Markdown
Author

Hi team , could anyone review my PR

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.

🐛 Bug Report: LiteLLM instrumentation does not record seed, stop, frequency_penalty, presence_penalty

2 participants