Skip to content

fix: align instrumentation tests with current APIs and close LiteLLM/FastAPI gaps#326

Open
AkhileshNair2201 wants to merge 15 commits into
mainfrom
feat/sdk-caching
Open

fix: align instrumentation tests with current APIs and close LiteLLM/FastAPI gaps#326
AkhileshNair2201 wants to merge 15 commits into
mainfrom
feat/sdk-caching

Conversation

@AkhileshNair2201

Copy link
Copy Markdown
Contributor

Summary

This PR brings the unit test suite back in sync with the current instrumentation and SDK APIs, and fixes two small production gaps that the updated tests exposed.

Tests had drifted after recent renames and API changes (instrumentor class names, wrapt-based wrapping, span attribute conventions, Config/Tracer kwargs, default span attributes). Several suites were failing or asserting obsolete contracts. This change updates those expectations so failures again mean a real behavior break, not a stale mock.

What changed

Production

  • FastAPI build_request_url — when the ASGI scope has no server, fall back to the path instead of leaving url undefined.
  • LiteLLM _uninstrument — also unwrap responses / aresponses, matching what _instrument wraps, so uninstrument fully restores the original methods.

Tests

  • OpenAI / LiteLLM — assert exact wrap/unwrap counts; restore OpenAI chat wrapper coverage; assert LiteLLM prompt/completion attributes that the code actually sets.
  • Google GenAI — target NetraGoogleGenAiInstrumentor; drop tests for helpers that no longer exist.
  • Netra init — expect DEFAULT_INSTRUMENTS and newer Config fields (cache_ttl_seconds, metrics knobs, etc.).
  • Span wrapper / tracer — expect netra.span.type and mock Filtering/Trial exporters used by current Tracer setup.
  • FastAPI / input scanner — match method-only default span names and the llm_guard import path used at runtime.

Why

Without this, CI and local pytest either fail on outdated assertions or pass with weak checks (e.g. call_count >= 1) that would miss partial instrumentation regressions. Aligning tests to the live contracts makes the suite a reliable gate for future instrumentation changes.

Test plan

  • pytest tests/test_openai_instrumentation.py tests/test_litellm_instrumentation.py tests/test_google_genai_instrumentation.py -q
  • pytest tests/test_fastapi_instrumentation.py tests/test_netra_init.py tests/test_span_wrapper.py tests/test_tracer.py tests/test_input_scanner.py -q
  • Full pytest green locally

AkhileshNair2201 and others added 6 commits July 10, 2026 13:01
Co-authored-by: Cursor <cursoragent@cursor.com>
Restore the 0.1.95 changelog entry, bump to 0.1.96, skip cache writes
for non-positive TTL, and add shutdown and edge-case tests.

Co-authored-by: Cursor <cursoragent@cursor.com>
…FastAPI gaps

Co-authored-by: Cursor <cursoragent@cursor.com>
AkhileshNair2201 and others added 5 commits July 10, 2026 13:06
* feat: add opt-in TTL caching for get_prompt

Co-authored-by: Cursor <cursoragent@cursor.com>

* update doc

* remove 0.1.95 changelog

* fix: address PR review feedback for get_prompt caching

Restore the 0.1.95 changelog entry, bump to 0.1.96, skip cache writes
for non-positive TTL, and add shutdown and edge-case tests.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix

* fix: align instrumentation tests with current APIs and close LiteLLM/FastAPI gaps

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
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