Repository navigation
feat: add next.js and nuxt server span context - #5315
pauldambra merged 10 commits into
Conversation
There was a problem hiding this comment.
PostHog Review · Standard · reviewed 7f93d89: 1 Should fix.
This is the only automatic review while this pull request is a draft. Comment @posthog review to review new changes sooner. Otherwise, a review of the new changes runs when you mark it ready for review.
Coherence0 spec problems · 0 failing chokepoints · 2 spec gaps · 0 guard failures 44 components, 7 bullets (5 invariants, 2 requirements), 0 problems Chokepoints: none declared. Spec gaps: 2 entrances with outside or unknown trust and no traced control, and 10 more held by the adoption baseline
Close one with |
Node SDK compliance v2Commit: 7dc2d42 Capture v0 — acceptance✅ 28 passed / ❌ 3 non-passing / Drill-down: run artifacts → ❌ server_snapshot_payload_false — failed_assertionExpected native data result Code: Failed step: acceptance/public/evaluate-flags.feature:868 the public snapshot outcomes should have these semantics: ❌ server_snapshot_payload_zero — failed_assertionExpected native data result Code: Failed step: acceptance/public/evaluate-flags.feature:868 the public snapshot outcomes should have these semantics: ❌ server_snapshot_payload_null — failed_assertionExpected native data result Code: Failed step: acceptance/public/evaluate-flags.feature:868 the public snapshot outcomes should have these semantics: Harness exit: 1; report validation exit: 1. Capture v1 — acceptance✅ 28 passed / ❌ 3 non-passing / Drill-down: run artifacts → ❌ server_snapshot_payload_false — failed_assertionExpected native data result Code: Failed step: acceptance/public/evaluate-flags.feature:868 the public snapshot outcomes should have these semantics: ❌ server_snapshot_payload_zero — failed_assertionExpected native data result Code: Failed step: acceptance/public/evaluate-flags.feature:868 the public snapshot outcomes should have these semantics: ❌ server_snapshot_payload_null — failed_assertionExpected native data result Code: Failed step: acceptance/public/evaluate-flags.feature:868 the public snapshot outcomes should have these semantics: Harness exit: 1; report validation exit: 1. Capture v0 — migration✅ 55 passed / ❌ 1 non-passing / Drill-down: run artifacts → ❌ migration/yaml-parity-v1/remote-flags-v1.feature::Omitted GeoIP settings default to enabled in flag requests — failed_assertionFlags field differs Code: Failed step: migration/yaml-parity-v1/remote-flags-v1.feature:134 the first flags request field "geoip_disable" should equal JSON false Operation: Field: Expected: false Actual value: true Harness exit: 1; report validation exit: 1. Capture v1 — migration✅ 120 passed / ❌ 1 non-passing / Drill-down: run artifacts → ❌ migration/yaml-parity-v1/remote-flags-v1.feature::Omitted GeoIP settings default to enabled in flag requests — failed_assertionFlags field differs Code: Failed step: migration/yaml-parity-v1/remote-flags-v1.feature:134 the first flags request field "geoip_disable" should equal JSON false Operation: Field: Expected: false Actual value: true Harness exit: 1; report validation exit: 1. |
7f93d89 to
e63e115
Compare
e63e115 to
032965a
Compare
|
Note 🤖 Automated comment by QA Swarm — not written by a human Verdict: ✅ APPROVE (round 1 @ 032965a)Restacked on the Node privacy fix in #5314. Nuxt tests now use enabled clients that drop events, so the span checks run against the new privacy gate. Checks
Known limit: when a sampler drops an intermediate span, the bridge cannot prove ancestry, so that case stays unenriched. Automated by QA Swarm. Human review is required. This comment does not approve a merge or release. |
|
found same issues as the bot |
032965a to
1da8a47
Compare
There was a problem hiding this comment.
PostHog Review · Standard · reviewed 1da8a47: 1 Must fix.
This is review round 3 on this pull request. When findings keep coming back in the same code, the approach is usually the problem. Before the next fix, check whether a different design would remove the whole class of findings.
1da8a47 to
8bb9fe4
Compare
There was a problem hiding this comment.
PostHog Review · Standard · reviewed 8bb9fe4: 1 Should fix.
This is review round 4 on this pull request. When findings keep coming back in the same code, the approach is usually the problem. Before the next fix, check whether a different design would remove the whole class of findings.
marandaneto
left a comment
There was a problem hiding this comment.
bot still has open comments but approving to unblock, my findings were addressed
Error tracking smokeCommit: 7/8 passed (0 skipped, 0 uncovered)
|
Generated-By: PostHog Desktop Task-Id: 5681be44-4986-48db-b140-1bda88f75f96
Generated-By: PostHog Desktop Task-Id: 5681be44-4986-48db-b140-1bda88f75f96
Generated-By: PostHog Desktop Task-Id: 5681be44-4986-48db-b140-1bda88f75f96
Generated-By: PostHog Desktop Task-Id: 5681be44-4986-48db-b140-1bda88f75f96
Generated-By: PostHog Desktop Task-Id: 5681be44-4986-48db-b140-1bda88f75f96
Generated-By: PostHog Desktop Task-Id: bfd18848-e498-4352-a58a-b9ba85de4198
withPostHogContext passed a proxy that put the request identity back on every call, so posthog.withContext inside the callback was ignored. The callback already runs inside the request scope, so pass the client. Generated-By: PostHog Desktop Task-Id: e73c8b25-9501-4f04-9fd8-e82415e1f9f9
With requestContext on, the request scope now keeps properties from an outer application context. The error hook now prefers the active application identity over the saved header identity. Generated-By: PostHog Desktop Task-Id: e73c8b25-9501-4f04-9fd8-e82415e1f9f9
Match posthog-node: withPostHogContext and the Nitro request wrapper no longer end the context when the handler returns or throws. Work the handler starts keeps the request IDs. Generated-By: PostHog Desktop Task-Id: e73c8b25-9501-4f04-9fd8-e82415e1f9f9
Next.js 15 bundles instrumentation and App Router handlers in separate webpack layers, each loading its own copy of clientCache.node.ts. That gave each layer its own client for the same key, so the OTel span processor (reading one client's context) and withPostHogContext (writing another's) could disagree about the current request. Cache clients on globalThis, keyed by Symbol.for, so every layer shares one. Generated-By: PostHog Desktop Task-Id: e73c8b25-9501-4f04-9fd8-e82415e1f9f9
9201663 to
7dc2d42
Compare
[Robot] Prepared with PostHog Desktop on behalf of @pauldambra.
Problem
Next.js and Nuxt developers need to connect backend work to browser sessions. Their existing server clients do not keep request IDs active around application spans.
Changes
@posthog/next/otel.createPostHogSpanContext(config)reuses the existing configuration, identity resolver, consent handling, and cached client.createContextSpanProcessor()andwithPostHogContext(work)for App Router handlers, actions, and wrapped server component work.serverConfig.requestContext, defaultfalse, and Node-onlygetPostHogServerClient()from@posthog/nuxt/server.undefinedbefore startup and after close.The processor follows only parent span objects it observed. A sampled-out intermediate hides earlier server ancestors, which remain unchanged.
Next.js support is Node App Router work. Pages Router arguments, browser/Edge tracing, later React child rendering, and work after the wrapped callback are outside it. Nuxt covers Nitro 2's H3 handler and Nitro 3's fetch handler. Handler completion can precede the end of a streamed response body.
Builds on #5314. Tracks sdk-specs#128. Release after the shared Node bridge, with the exact minimum dependency set through the release process.
Validation:
Release info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes
pnpm changesetto generate a changeset fileAdded the equivalent minor changeset directly.
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Models: GPT-6 (Codex) implemented the framework integrations. GPT-6 Astra reviewed SDK APIs and implemented the incoming Nuxt span regression fix. Used PostHog Desktop, local Node tools, synthetic framework apps, and GitHub CLI. The final change uses one shared processor and keeps the stack at two layers. Human review is required.
Created with PostHog Desktop