feat: add embedding tracer support for Bedrock, LiteLLM, OpenAI#631
feat: add embedding tracer support for Bedrock, LiteLLM, OpenAI#631viniciusdsmello wants to merge 17 commits intomainfrom
Conversation
Used by superpowers workflows to host isolated git worktrees during implementation, never meant to be tracked. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…EN-10480) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…480) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…N-10480) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…OPEN-10480) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…gression (OPEN-10480) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds the same file-level pragma already used by test_portkey_integration.py to suppress reportUnknown* and reportMissingParameterType — these come from openlayer.lib.integrations being in pyright's ignore list, which causes imports from there to be typed as Unknown. Per-line pyright ignores added on direct imports of botocore.response and openai, which are not present in the lint job's environment. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Code review findings addressed: - Move per-call imports of _openai_embedding_common to module-level (was in hot path of every embedding call). - Extract build_embedding_step_kwargs into _openai_embedding_common so that sync and async OpenAI handlers each become ~10 lines instead of ~50, and LiteLLM reuses the same kwargs assembly. - Drop LiteLLM's local _parse_embedding_response and _get_embedding_model_parameters; both now delegate to the shared helpers (LiteLLM-specific timeout/api_base/api_version/cost/metadata are layered on top of the common kwargs). - Type Bedrock _parse_embedding_output return as Tuple[Union[List[float], List[List[float]]], int, int] instead of bare tuple. Net: -34 lines across the 5 touched source files. Tests unchanged, all 77 embedding tests + 448 lib tests still green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Code reviewFound 4 issues. Issue #1 is a release-blocker — verified by running an embedding call against the PR branch (the trace was silently dropped, with the integration handler logging
openlayer-python/src/openlayer/lib/integrations/openai_tracer.py Lines 1644 to 1660 in 5c4765b openlayer-python/src/openlayer/lib/integrations/async_openai_tracer.py Lines 734 to 750 in 5c4765b
openlayer-python/src/openlayer/lib/integrations/litellm_tracer.py Lines 368 to 382 in 5c4765b Once #1 is fixed, the rest of the implementation produces a correct payload — verified locally with a one-off 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
Summary
Adds native embedding tracing support across the Python SDK so that embedding API calls (Titan via Bedrock,
litellm.embedding,OpenAI.embeddings.create) generate proper traces in Openlayer with correct model, tokens, dimensions, and output.StepType.EMBEDDING+add_embedding_step_to_tracehelper (src/openlayer/lib/tracing/)."embed"inmodelIdand routes to a dedicated handler with parsers for Titan v1/v2 and Cohere v3 (single + batch). Existing chat path is untouched and locked in by a backfilled regression test.litellm.embeddingalongside the existinglitellm.completionpatch. Reusesdetect_provider_from_response,extract_usage_from_response, andextract_litellm_metadata.client.embeddings.createfor both sync (trace_openai) and async (trace_async_openai) clients via a small shared helper module (_openai_embedding_common.py).Linear
OPEN-10480
Verification
ruff checkclean on all touched files.pyrightclean on all touched source files.Test plan
amazon.titan-embed-text-v2:0) — confirm trace appears with model name and prompt tokens populated.litellm.embedding(model="text-embedding-3-small", input="x").step_type=embeddingis rendered correctly (out of scope for this PR but required for end-to-end value).Out of scope
🤖 Generated with Claude Code