Skip to content

Make server-side posthog-node capture serverless-safe#228

Merged
gewenyu99 merged 3 commits into
mainfrom
fix/serverless-capture-flush
Jul 11, 2026
Merged

Make server-side posthog-node capture serverless-safe#228
gewenyu99 merged 3 commits into
mainfrom
fix/serverless-capture-flush

Conversation

@gewenyu99

Copy link
Copy Markdown
Collaborator

Reframes the commandments so per-request handlers in web frameworks (Next.js/Nuxt/SvelteKit/Astro, serverless, edge) are treated as short-lived and must await flush()/shutdown(), and fixes the server example handlers to await the send before returning — the drift that let the wizard generate capture code that silently drops events on serverless.

gewenyu99 and others added 2 commits July 10, 2026 19:33
The javascript_node block told the agent not to set flush config in
"long-running servers", which caught web frameworks whose per-request
handlers are actually short-lived on serverless/edge — so generated
capture code returned before the async send ran and dropped events.
Reframe per-request handlers as short-lived and require an awaited
flush()/shutdown(), and add the same rule to the nextjs, astro-ssr,
astro-hybrid, and sveltekit blocks.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The singleton examples captured and returned without awaiting the send;
that works on a long-lived dev server but drops events on serverless/edge
where the function freezes on return. Add await posthog.flush() before
each handler returns, and give nuxt-4 the flushAt/flushInterval config the
other examples already have.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@gewenyu99
gewenyu99 requested a review from a team as a code owner July 10, 2026 23:33
@github-actions

Copy link
Copy Markdown

🧙 Wizard CI

Run the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands:

Test all apps:

  • /wizard-ci all

Test all apps in a directory:

  • /wizard-ci basic-integration
  • /wizard-ci mcp-analytics
  • /wizard-ci revenue

Test an individual app:

  • /wizard-ci basic-integration/android
  • /wizard-ci basic-integration/angular
  • /wizard-ci basic-integration/astro
Show more apps
  • /wizard-ci basic-integration/django
  • /wizard-ci basic-integration/fastapi
  • /wizard-ci basic-integration/flask
  • /wizard-ci basic-integration/javascript-node
  • /wizard-ci basic-integration/javascript-web
  • /wizard-ci basic-integration/laravel
  • /wizard-ci basic-integration/next-js
  • /wizard-ci basic-integration/nuxt
  • /wizard-ci basic-integration/python
  • /wizard-ci basic-integration/rails
  • /wizard-ci basic-integration/react-native
  • /wizard-ci basic-integration/react-router
  • /wizard-ci basic-integration/sveltekit
  • /wizard-ci basic-integration/swift
  • /wizard-ci basic-integration/tanstack-router
  • /wizard-ci basic-integration/tanstack-start
  • /wizard-ci basic-integration/vue
  • /wizard-ci mcp-analytics/custom-dispatcher
  • /wizard-ci mcp-analytics/typescript-sdk
  • /wizard-ci revenue/stripe

Results will be posted here when complete.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@gewenyu99
gewenyu99 merged commit 6c9632d into main Jul 11, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants