Skip to content

fix(vertexai): repair TypeScript generation and stream tracing - #519

Open
nik13 wants to merge 8 commits into
devfrom
fix/vertexai-typescript-real-sdk
Open

nik13 wants to merge 8 commits into
devfrom
fix/vertexai-typescript-real-sdk

Conversation

@nik13

@nik13 nik13 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Repairs the existing @traceai/fi-instrumentation-vertexai adapter for the legacy @google-cloud/vertexai SDK. This is not the modern @google/genai adapter in #493, nor the Python changes in #248 / #312.

  • Refresh FITracer after constructor privacy configuration and provider changes; the usual setTracerProvider() setup no longer silently retains a stale tracer.
  • Instrument both stable and preview generation/chat APIs. Capture the actual chat model at both SDK bounds, multi-turn history, function content, all candidates, generation settings and zero-valued usage.
  • Complete streaming spans from the SDK-owned aggregate response promise. Preserve the returned result, aggregate promise, iterator and chat history; no extra reads, buffering, polling or duplicate spans. Aggregate-only use, early iterator exit and parse failures all terminate their spans.
  • Replace the process-wide patch gate with owned per-module wrappers. Manual disable restores methods; independent SDK copies, frozen namespace objects and CJS/ESM aliases work without double wrapping. Active requests can finish after disable.
  • Keep bounded content in standard gen_ai.input.messages / gen_ai.output.messages fields, including function data, so granular FI privacy controls apply. Do not export duplicated raw bodies, media bytes/URIs or provider error messages/stacks. Telemetry failures preserve SDK success/error behavior.
  • Remove the unreachable TextEmbeddingModel hook: the supported SDK does not export that class. Document the actual legacy SDK scope and upstream migration route instead of claiming embedding support.
  • Align the peer range with the existing 1.x module filter and the Node engine declaration with FI core's existing OpenTelemetry dependency requirements. Add the package to the ordered workspace build and a six-combination packed-consumer CI workflow. Existing release-please wiring already covers this package; no version or changelog bump.

Reproduction and verification

Baseline: current dev at 5ae2b9b4a3678af52abc01d90e4fe2fe1d4c2099. The normal setup failed to export spans. After explicitly re-enabling only to isolate further baseline defects, eight separate regressions also failed at each SDK bound: generation metadata, chat model/history, aggregate-only streams, preview tracing, manual disable, candidate/tool capture, raw-media capture and zero token counts.

Final validation used synthetic Google/FI credentials and an OS sandbox denying outbound networking except localhost. Google SDK authentication/request construction and response/SSE parsing are real; provider HTTP responses are synthetic fixtures. OTLP is actually exported over HTTP to a local receiver and decoded. This is not a claim of live Google or Future AGI service testing.

  • 31 packed-consumer tests × 6 combinations = 186 passes, no skips: SDK 1.0.0 and current npm latest 1.12.0, each on Node 18.19.0, 22.15.0, and 26.8.1. Consumers install the built tarball with published FI dependencies, not workspace core.
  • Covers parents, stable/preview calls, chat history and function results, repeated streaming parts and aggregate usage, early iteration exit, empty/malformed SSE, in-flight disable, provider changes, suppression, all six content-hiding controls, environment privacy, bounded capture, automatic loading and namespace aliases.
  • Exact README application executed with synthetic authentication and real loopback OTLP; asserts the exported span. CommonJS exports, native ESM imports and public TypeScript declarations checked at both SDK bounds.
  • 8 ownership/fail-open unit tests passed. Self-review caught and fixed namespace-alias duplication, missing list-truncation markers and loss of the latest message when bounded history receives a tools prefix; regression tests demonstrated each failure first.
  • Full pnpm run build:ordered, frozen workspace installation, release_plan.py --check (129 packages), and git diff --check passed. Frozen installation retains existing unrelated arrow2csv bin-link warnings; the command succeeds and the lockfile is unchanged.

Compatibility and release notes

This is a compatibility repair for an upstream-deprecated SDK, not a new recommended SDK for applications. The README points developers toward Google's migration guide, without claiming that the separate modern traceAI adapter is published.

Content is now emitted only in standard message attributes rather than additional raw/input/output copies. The Node engine correction reflects the requirements already imposed by the existing FI core dependency; no newly imposed runtime requirement or breaking API is intended.

The customer docs draft is held until this repair is released, because the currently published adapter does not contain these fixes. No docs-main PR, registry publication, workflow dispatch or merge is part of this PR. The GitHub workflow runs the same compatibility matrix on PR changes.

E2E coverage

Not applicable to the product application's E2E map. This SDK package has committed real-SDK, packed-consumer, exact-README and loopback-OTLP tests instead.

🤖 Generated with Claude Code

nik13 and others added 8 commits November 1, 2026 21:53
Cover real stable/preview SDKs, preserve aggregate stream lifecycle, repair provider/privacy initialization and owned teardown, and verify packed consumers at both SDK bounds.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Normalize string chat parts, prioritize current input turns, retain message envelopes under capture limits, and merge privacy-masked FI context attributes. Add failing-first real-SDK coverage for all four review findings.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
Cover positive, zero and absent counters across stable/preview unary and streaming responses at both supported SDK bounds.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>

This branch has not been deployed

No deployments
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