Skip to content

feat(examples): Qwen (Model Studio) recipe on traceai-openai (TH-8314) - #235

Merged
nik13 merged 10 commits into
devfrom
feat/th-8314-qwen
Oct 28, 2026
Merged

nik13 merged 10 commits into
devfrom
feat/th-8314-qwen

Conversation

@nik13

@nik13 nik13 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

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 official openai SDK and the existing traceai-openai instrumentor; there is no Qwen-specific package or native DashScope SDK dependency.

  • Registers tracing before client creation. FI_PROJECT_NAME selects the Observe project, falling back to qwen-openai-recipe; Future AGI credentials stay with the tracer and DASHSCOPE_API_KEY stays with the OpenAI client.
  • Uses the documented Singapore shared endpoint by default, with an explicit DASHSCOPE_BASE_URL override for the account's region/workspace. Documents Beijing, Singapore, Virginia, Hong Kong, Tokyo, and Frankfurt workspace endpoints and the shared DashScope hosts.
  • Uses qwen-plus in the Run block and links the official model catalog. The CLI supports chat and streaming with stream_options={"include_usage": True} and consumes the final usage chunk even when choices is empty.
  • Rejects unresolved workspace placeholders, malformed URLs, URL credentials, whitespace/control characters, invalid host spellings, and malformed ports before tracing. Alibaba hosts require HTTPS and exactly /compatible-mode/v1 or /compatible-mode/v1/, without prefixes, endpoint suffixes, queries, or fragments. Allowed URLs are returned unchanged; custom proxies and loopback paths remain supported.
  • Documents provider errors, privacy controls, and the provider/model attribute differences between published traceAI-openai==0.1.10 and 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 them openai.
  • Recommends Virginia's workspace-dedicated endpoint and notes the discrepancy between Alibaba's shared-host listings on its Base URL and regional endpoint pages.

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.yml with the same three Python 3.11 cells as the sibling recipes:

OpenAI SDK traceAI packages
3.24.0 Repository source
1.69.0 Repository source (SDK floor)
3.24.0 Published traceAI-openai==0.1.10 + fi-instrumentation-otel==1.1.0

dev is 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

nik13 added 3 commits October 5, 2026 18:18
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
@nik13
nik13 requested a review from NVJKKartik October 10, 2026 08:42
@nik13

nik13 commented Oct 10, 2026

Copy link
Copy Markdown
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.

nik13 and others added 7 commits October 11, 2026 21:32
…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>
@nik13
nik13 merged commit dc977c6 into dev Oct 28, 2026
32 checks passed
@nik13
nik13 deleted the feat/th-8314-qwen branch October 28, 2026 09:21
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