Skip to content

[codex] Trace first-party relay clients#2995

Open
juliusmarminge wants to merge 4 commits into
mainfrom
codex/hosted-web-tracing-poc
Open

[codex] Trace first-party relay clients#2995
juliusmarminge wants to merge 4 commits into
mainfrom
codex/hosted-web-tracing-poc

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Jun 7, 2026

Copy link
Copy Markdown
Member

Problem

Relay requests made by hosted web, desktop, and the headless CLI were not exported to the product-owned relay tracing dataset. Mobile had an OTLP tracer, but it was installed as a broad runtime tracer rather than being scoped to relay operations. Installing another global tracer on web or server would also capture unrelated user server/provider work that belongs to the user's own observability configuration.

Approach

This PoC adds a dedicated RelayClientTracer reference in @t3tools/client-runtime. Relay operations explicitly switch to that tracer while executing, so ordinary application, provider, and server spans continue to use the existing user-controlled tracer.

The shared managed relay client now traces all relay API operations through that boundary. Mobile and web provide platform-specific OTLP layers to the shared reference. The server and headless CLI provide the same scoped tracer and wrap their raw relay link/unlink requests. Desktop is covered by the web renderer build, with a distinct client resource attribute.

Infrastructure and release configuration

Alchemy creates a dataset-scoped ingest-only token for first-party relay clients and exposes its endpoint, dataset, and token in stack output. The relay deploy command can read persisted production stack output with --read-state without planning or applying infrastructure.

The release workflow reads that output and injects canonical T3CODE_RELAY_CLIENT_OTLP_TRACES_* values into desktop, CLI, and hosted web builds. loadRepoEnv projects those values to concise Vite aliases for browser builds. The CLI bundle embeds build-time fallbacks while still allowing runtime overrides.

Validation

  • vp check
  • vp run typecheck
  • vp run lint:mobile
  • 31 focused tests covering tracer isolation, OTLP export, server/public config resolution, Alchemy output decoding, env projection, and managed relay behavior

vp check reports the existing nine react(no-unstable-nested-components) warnings and no errors.

Note

Add OTLP tracing for first-party relay clients across web, mobile, server, and CLI

  • Introduces RelayClientTracer and withRelayClientTracing in packages/shared/src/relayTracing.ts as the shared mechanism for switching the active tracer to a per-surface OTLP exporter for relay operations.
  • Provisions a new Axiom ingest token for relay client spans in infra/relay/src/observability.ts and propagates the URL, dataset, and token through the deploy pipeline and into .env/GitHub outputs via three new T3CODE_RELAY_CLIENT_OTLP_TRACES_* variables.
  • Wraps managed relay client methods, the t3MintCredential server route, the CLI unlink handler, and managed WebSocket URL resolution with withRelayClientTracing, creating and continuing W3C trace context across these boundaries.
  • Adds connectManagedCloudEnvironment root span and relayTraceHeaders propagation so trace context flows from the initial cloud connection through credential renewal and WebSocket reconnects.
  • Adds a --read-state flag to the relay deploy CLI that fetches deployed stack outputs without planning or applying changes, used by the release workflow to inject tracing config into downstream build and deploy jobs.
  • Risk: addManagedRelayEnvironment now requires a relayTraceHeaders argument; callers not yet passing this will need updating.
📊 Macroscope summarized 03c78cc. 7 files reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted

🗂️ Filtered Issues

No issues evaluated.


Note

Medium Risk
Touches release CI, public ingest tokens, and distributed trace propagation on managed cloud connect paths; misconfiguration could leak tokens in build env or break trace continuity without affecting core auth.

Overview
Adds scoped OTLP tracing for first-party relay clients so web, mobile, server, and CLI emit relay-operation spans to a product-owned dataset without replacing the global tracer.

A new shared RelayClientTracer and withRelayClientTracing route only explicit relay work through a dedicated Axiom OTLP layer; makeRelayClientTracingLayer wires platform-specific resources (mobile, web runtime, headless CLI, server broker). Managed relay HTTP calls, cloud CLI unlink, server relay broker requests, and web managed-environment connect/reconnect paths are wrapped accordingly; traceRelayBrokerHandler continues incoming traceparent on t3MintCredential.

Config & release: resolveRelayClientTracingConfig (HTTPS-only) plus build-time T3CODE_RELAY_CLIENT_OTLP_TRACES_* embeds; loadRepoEnv projects to VITE_RELAY_OTLP_TRACES_*. Relay infra adds a client ingest token and stack outputs; deploy gains --read-state and GitHub outputs. Release workflow reads prod relay state and injects tracing env into desktop, CLI, and Vercel web builds. Web CloudManagedConnection carries relayTraceHeaders for trace propagation across DPoP/WebSocket setup.

Reviewed by Cursor Bugbot for commit 03c78cc. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f16e4d51-ab6f-4d22-8306-b0f6f35a4894

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/hosted-web-tracing-poc

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Jun 7, 2026
@github-actions

github-actions Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

🚀 Expo continuous deployment is ready!

  • Project → t3-code
  • Platforms → android, ios
  • Scheme → t3code-preview
  🤖 Android 🍎 iOS
Fingerprint f9033cdeb2089379d2da4fc425aba1c94bc5feb7 58a0e3786e25e8165e9c158dc7b1ba699ce30e0d
Build Details Build Permalink
DetailsDistribution: INTERNAL
Build profile: preview:dev
Runtime version: f9033cdeb2089379d2da4fc425aba1c94bc5feb7
App version: 0.1.0
Git commit: 16947a0c5efe1d12e46c8a8b2455e330c0da25d3
Build Permalink
DetailsDistribution: INTERNAL
Build profile: preview:dev
Runtime version: 58a0e3786e25e8165e9c158dc7b1ba699ce30e0d
App version: 0.1.0
Git commit: 16947a0c5efe1d12e46c8a8b2455e330c0da25d3
Update Details Update Permalink
DetailsBranch: pr-2995
Runtime version: f9033cdeb2089379d2da4fc425aba1c94bc5feb7
Git commit: 16947a0c5efe1d12e46c8a8b2455e330c0da25d3
Update Permalink
DetailsBranch: pr-2995
Runtime version: 58a0e3786e25e8165e9c158dc7b1ba699ce30e0d
Git commit: 16947a0c5efe1d12e46c8a8b2455e330c0da25d3
Update QR

Base automatically changed from codex/connection-infra-otel-base to main June 8, 2026 03:21
juliusmarminge and others added 2 commits June 7, 2026 20:22
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>
@juliusmarminge juliusmarminge force-pushed the codex/hosted-web-tracing-poc branch from 34a5a25 to a1779f7 Compare June 8, 2026 03:22
@juliusmarminge juliusmarminge marked this pull request as ready for review June 8, 2026 03:25
@macroscopeapp

macroscopeapp Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs human review

This PR introduces distributed tracing infrastructure across multiple applications and deployment pipelines. The scope includes new cloud resource provisioning, CI/CD modifications, and runtime integration in mobile, web, and server apps - warranting human review for the coordination and completeness of the feature.

You can customize Macroscope's approvability policy. Learn more.

juliusmarminge and others added 2 commits June 7, 2026 20:33
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>
@github-actions github-actions Bot added size:XL 500-999 changed lines (additions + deletions). and removed size:L 100-499 changed lines (additions + deletions). labels Jun 8, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Renewal drops relay trace headers
    • Added relayTraceHeaders: renewed.relayTraceHeaders to the options passed to ensureSavedEnvironmentConnection after credential renewal, ensuring the connect trace from renewManagedRelayCredential is propagated to the new websocket setup.

Create PR

Or push these changes by commenting:

@cursor push f4367e9265
Preview (f4367e9265)
diff --git a/apps/web/src/environments/runtime/service.ts b/apps/web/src/environments/runtime/service.ts
--- a/apps/web/src/environments/runtime/service.ts
+++ b/apps/web/src/environments/runtime/service.ts
@@ -1601,6 +1601,7 @@
                   scopes: scopeHint,
                   serverConfig: options?.serverConfig ?? null,
                   allowManagedRenewal: false,
+                  relayTraceHeaders: renewed.relayTraceHeaders,
                 });
               }
             }

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 03c78cc. Configure here.

activeRecord.environmentId,
activeCredential,
relayTraceHeaders,
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renewal drops relay trace headers

Low Severity

When a managed saved environment’s initial connection fails auth and credentials are renewed, the follow-up ensureSavedEnvironmentConnection call omits renewed.relayTraceHeaders, so the first websocket ticket request no longer continues the connect trace that renewManagedRelayCredential just produced.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 03c78cc. Configure here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Low

return await ensureSavedEnvironmentConnection(renewed.record, {

When renewManagedRelayCredential succeeds in the auth error handling block (lines 1595-1604), the recursive call to ensureSavedEnvironmentConnection omits renewed.relayTraceHeaders. This causes the newly created client to use null instead of the fresh trace headers from the renewal, losing the tracing context for the connection attempt.

🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @apps/web/src/environments/runtime/service.ts around line 1599:

When `renewManagedRelayCredential` succeeds in the auth error handling block (lines 1595-1604), the recursive call to `ensureSavedEnvironmentConnection` omits `renewed.relayTraceHeaders`. This causes the newly created client to use `null` instead of the fresh trace headers from the renewal, losing the tracing context for the connection attempt.

Evidence trail:
apps/web/src/environments/runtime/service.ts lines 1595-1604 (recursive call omitting relayTraceHeaders); lines 1358-1402 (renewManagedRelayCredential returning relayTraceHeaders); line 1521 (default to null when not provided); line 1527 (relayTraceHeaders passed to createSavedEnvironmentClient); lines 1201-1204 (relayTraceHeaders used when resolving WebSocket URL); line 1957 (other caller that does pass relayTraceHeaders); lines 1218-1220 (renewal inside client resolver that properly passes renewed.relayTraceHeaders).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL 500-999 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant