Repository navigation
feat(examples): Qwen (Model Studio) recipe on traceai-openai (TH-8314) - #235
Merged
Merged
Conversation
Add python/examples/qwen: trace Qwen Chat Completions on Alibaba Cloud Model Studio's OpenAI-compatible mode, made with the official openai SDK, by using the existing traceai-openai instrumentor. No Qwen package, no DashScope SDK. - src/app.py: worked example uses the legacy international host https://dashscope-intl.aliyuncs.com/compatible-mode/v1 (D10), labelled as legacy; DASHSCOPE_BASE_URL takes the console workspace host. check_base_url() refuses a literal {WorkspaceId} placeholder and aliyuncs.com URLs not ending in /compatible-mode/v1; never rewrites. DASHSCOPE_API_KEY only on the client. - README region table (Beijing, Virginia, Singapore, Tokyo + migration note), cross-region 401 invalid_api_key, Qwen-Audio / DashScope protocol / Responses not covered. - tests: loopback contract on the shared harness Receiver: request URL and bearer key at the documented host (MockTransport), one LLM span, model, usage (omitted when absent), provider label openai (D2), project resource and FI headers, no vendor key in any exported field, streaming with and without include_usage, cross-region 401 error span, FI_HIDE_INPUTS/OUTPUTS with control, app subprocess under a socket guard, refused URLs exit 2. - Pins current traceai-openai behaviour: streamed and failed calls have no model attribute; a final usage chunk (include_usage) is recorded. approved: Nikhil 2026-10-03 blanket Refs: TH-8314
…key check)
From pr-reviewer t_74f98c63 (CHANGES_REQUESTED, R1 P2 blocking):
- R1 (P2): README says the cross-region 401 comes from Model Studio and is
a region mismatch, not a Future AGI authentication failure (PRD AC-03 /
J2); pinned by the README contract test.
- R2: README names gen_ai.request.model and notes the requested model stays
in gen_ai.request.parameters on streamed and failed spans (unless
FI_HIDE_LLM_INVOCATION_PARAMETERS); stream and error tests pin it.
- R3: check_base_url compares the host lower-cased without a trailing dot
and decodes the placeholder check until stable, so trailing-dot hosts and
double-encoded {WorkspaceId} are refused; URLs are still never rewritten.
The three new cases failed before this change.
- R4: main() exits 2 naming DASHSCOPE_API_KEY before tracing when the key
is missing (failed before this change).
- R5: README gives the exact published-package command (only the recipe
src and the harness on PYTHONPATH).
- Spec nits: Qwen-Audio users are pointed to the DashScope protocol; the
README says the legacy hosts are still accepted.
approved: Nikhil 2026-10-03 blanket
Refs: TH-8314
mock_client rewrote every chat completion model to the request id, so the suite could not show that the span stores the response model. The new case keeps the synthetic response id, pins the chat.completion usage shape, and checks the OTLP export. Existing cases still echo. No live Model Studio call. RED: response.model was qwen-plus. GREEN: the new case passes on the installed traceAI-openai 0.1.10 wheel. approved: Nikhil 2026-10-03 blanket Refs: TH-8314
Contributor
Author
|
Test pin only, not a merge. Head 83beecd stops mock_client from rewriting the response model in one case and asserts the span stores the synthetic response id. App behavior is unchanged. The existing video is at aa900d8 and is not exact-head for this commit. No live Model Studio call. Review requested from NVJKKartik; this comment is not an approval. |
…der/model fix The recipe pinned traceai-openai 0.1.10 behaviour: gen_ai.provider.name is always "openai" and streamed/failed spans carry no gen_ai.request.model. #249 labels known vendor hosts and records the requested model, so these pins would break whichever PR merged second. Accept both behaviours (and the related Responses/embedding output changes where this recipe checks them), and say in the README which version does what. Passes against published traceAI-openai 0.1.10 and against #249. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
setup_tracing() passed project_name or "qwen-openai-recipe" to register(), so the default was always truthy and FI_PROJECT_NAME was never read: `python src/app.py` always exported to qwen-openai-recipe. The Anannas recipe reads FI_PROJECT_NAME with its name as the default; do the same here. An explicit setup_tracing() argument still wins, and an unset or empty FI_PROJECT_NAME keeps qwen-openai-recipe (never register()'s generic default). - README: FI_PROJECT_NAME in the Configure table and the Run section; the Code snippet reads it the same way as src/app.py. - Tests: setup_tracing() default / empty / env / explicit cases; the guarded app.py subprocess runs with FI_PROJECT_NAME unset and set; the README contract checks the new row and snippet. Passes against repository source, published traceAI-openai 0.1.10 and #249. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
Harden base URL validation, document regional endpoints and streaming usage, cover provider errors, and add source/floor/published recipe CI cells. Co-Authored-By: Claude Code <noreply@anthropic.com>
Document the Hong Kong shared-host exception and enumerate source versus published labels. Require exact per-host provider assertions on chat, streams and errors, with workspace and proxy controls. Prefer the Virginia workspace endpoint where official shared-host docs disagree. Co-Authored-By: Claude Code <noreply@anthropic.com>
Retain both Perplexity and Qwen in the shared recipe test matrix. Co-Authored-By: Claude Code <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a Qwen recipe for Alibaba Cloud Model Studio's OpenAI-compatible Chat Completions API at
python/examples/qwen/(TH-8314, parent TH-8103). It uses the officialopenaiSDK and the existingtraceai-openaiinstrumentor; there is no Qwen-specific package or native DashScope SDK dependency.FI_PROJECT_NAMEselects the Observe project, falling back toqwen-openai-recipe; Future AGI credentials stay with the tracer andDASHSCOPE_API_KEYstays with the OpenAI client.DASHSCOPE_BASE_URLoverride for the account's region/workspace. Documents Beijing, Singapore, Virginia, Hong Kong, Tokyo, and Frankfurt workspace endpoints and the shared DashScope hosts.qwen-plusin the Run block and links the official model catalog. The CLI supports chat and streaming withstream_options={"include_usage": True}and consumes the final usage chunk even whenchoicesis empty./compatible-mode/v1or/compatible-mode/v1/, without prefixes, endpoint suffixes, queries, or fragments. Allowed URLs are returned unchanged; custom proxies and loopback paths remain supported.traceAI-openai==0.1.10and current source. The host-by-host table distinguishes the mapped Beijing/Singapore/Virginia shared hosts and workspace hosts (dashscope) from the Hong Kong shared-host exception (openai); published 0.1.10 labels all of themopenai.Contract coverage and CI configuration
The recipe contracts use
httpx.MockTransport, a loopback OpenAI-shaped server, and the shared OTLP receiver. Subprocess socket/DNS guards block external provider access. Cases cover regional request routing and bearer authentication, chat, streamed usage, request-versus-response model IDs, 400/401/404/429/500 errors, key separation, privacy controls, project-name precedence, URL validation, and CLI subprocesses. Provider assertions require exact per-host values for chat, streaming, and errors, including Hong Kong shared/workspace endpoints and proxy/look-alike controls. Source versus published expectations are determined from the imported package path and pinned version rather than accepting either provider label. Temporary directories use the platform default for Linux/macOS portability; error-status assertions accommodate current fi-core's exception-prefix normalization.Adds Qwen to
.github/workflows/openai-compatible-recipe-tests.ymlwith the same three Python 3.11 cells as the sibling recipes:traceAI-openai==0.1.10+fi-instrumentation-otel==1.1.0devis merged into this branch normally. No shared instrumentor behavior is changed by this recipe.Scope
Synchronous Chat Completions and streaming through the OpenAI-compatible API. Native DashScope, Responses API, realtime audio, tools, structured outputs, workspace provisioning, billing-plan selection, and pricing-table changes are outside this recipe.
Official references
🤖 Generated with Claude Code