Skip to content

fix(tracing): trace only supported LLM calls and pass the rest through - #38

Open
Yash1hi wants to merge 2 commits into
mainfrom
fix/wrap-non-chat-create
Open

Yash1hi wants to merge 2 commits into
mainfrom
fix/wrap-non-chat-create

Conversation

@Yash1hi

@Yash1hi Yash1hi commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Summary

wrap() intercepted every method named create on a wrapped client and parsed the result as a Chat Completion or Message. So calls like client.responses.create(...) and client.embeddings.create(...) raised AttributeError (for example 'Response' object has no attribute 'choices'). Now only the supported calls are traced, and every other method passes through untouched:

  • OpenAI: chat.completions.create and beta.chat.completions.create
  • Anthropic: messages.create and beta.messages.create

Streaming and non-streaming calls are both traced, sync and async. Async detection also unwraps SDK decorators: they hid the coroutine function, so some async calls were treated as sync.

Changes

  • src/scorecard_ai/lib/_wrap_llms_otel.py: route only the supported attribute paths to the tracing wrapper; everything else returns the client's own attribute; use inspect.unwrap when detecting async methods.
  • src/scorecard_ai/lib/wrap_llms.py: the docstring lists the traced methods.
  • tests/lib/test_wrap_llms.py: 98 offline cases covering pass-through (Responses, embeddings, raw and streaming response wrappers), tracing for each supported method, sync and async, streaming and not.

Tracing the Responses API could be a follow-up.

Testing

  • .venv/bin/python -m pytest -q tests/lib/test_wrap_llms.py: 98 passed (the regression cases fail on main).
  • ruff check, ruff format --check, and pyright on the touched files: passed.

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.

1 participant