Repository navigation
feat(convex): allow optional POSTHOG_PROJECT_TOKEN and add disabled option - #5859
Conversation
Coherence📄 0 spec file errors · ⛔ 0 broken rules · 🚪 0 unchecked inputs · 🐛 0 bugs that came back What is Coherence?Coherence compares the code with its spec files ( This check read 44 parts of the code and 7 rules. Tip Nothing to fix. |
SDK performance: posthog-nodeBenchmarks completed. No changes flagged for review. Flags require at least a 5% change in the median and all six pairs agreeing on direction. This is a noise filter, not proof of a performance change or a CI gate. View all results
Values are medians of paired measurements. Not flagged does not mean unchanged. Unavailable means a measurement could not be provided, not zero. Estimated allocation measurements retain their instrumentation uncertainty. RSS measures the whole process, not just SDK allocations; observed peaks are sampled checkpoints. Paired ranges in the diagnostics describe variability, not confidence intervals. Each shard uses its own runner; compare Before PR against With PR within a row, not across shards. Compared 102 metric rows; 102 rows shown in all results. Omitted or shortened data remain in |
|
✅ Security review complete — No findings above the confidence threshold, in 4 min. Add the |
|
additional context / justification here #5611 (comment) |
turnipdabeets
left a comment
There was a problem hiding this comment.
Looks good to me. Keeping fail-fast in the app's own defineApp({ env }) while the component fails open fits the capture spec's missing-token requirement, and the setup guide already declares v.string() there, so existing apps keep the deploy-time check. Since this reverses the v2 "required at deploy" call from #3662, it'd be good to get a thumbs-up from Richard or Manoel before merging. Could we also add the tokenless dev/preview setup and the disabled option to the posthog.com Convex guide, which #5611 asks for too?
PR overviewNo security issues were found in this pull request. Reviews
|
richardsolomou
left a comment
There was a problem hiding this comment.
looks good, happy with flipping the #3662 call here. apps that want it to fail at deploy still get that from v.string() in their own defineApp({ env }), and the setup guide already does that, so prod setups dont rly lose anything
|
PostHog/posthog.com#22828 for the docs |
Problem
@posthog/convexdeclaredPOSTHOG_PROJECT_TOKENas required (v.string()) in the component'sconvex.config.ts. When an installing app declaresPOSTHOG_PROJECT_TOKEN: v.optional(v.string())in its owndefineApp({ env })so dev or preview deployments can run without sending events to production, Convex refuses to deploy because an optional app env var cannot be bound to a required component env var.Closes #5611.
Changes
POSTHOG_PROJECT_TOKENon the component (packages/convex/src/component/convex.config.ts,_generated/server.ts): ChangedPOSTHOG_PROJECT_TOKENfromv.string()tov.optional(v.string()). Existing apps that declarePOSTHOG_PROJECT_TOKEN: v.string()in their owndefineApp({ env })continue to work and keep deploy-time enforcement; apps that want tokenless dev/preview deployments can declarev.optional(v.string())or omit the binding.POSTHOG_PROJECT_TOKENis unset or blank (packages/convex/src/component/lib.ts):readConfig()warns once per isolate (re-arming if a token is later configured and then cleared) rather than spamming on every dropped call.localEvaluationEnabled()now requires a non-emptyPOSTHOG_PROJECT_TOKEN, soensureRefreshLoopandrefreshLoopschedule no ticks even ifPOSTHOG_PERSONAL_API_KEYis set.getFlagDefinitionsreturns{ disabled: true, data: null, ... }whenPOSTHOG_PROJECT_TOKENis unset (suppressing any stale cached definitions), andPostHog.loadEvaluator()degrades toundefined/{}instead of throwing"local feature flag evaluation is not configured".disabled?: booleanconstructor option onPostHog(packages/convex/src/client/index.ts): Matchesposthog-node/posthog-pythonand lets callers short-circuit all capture, exception, flag, andreloadFeatureFlagscalls before scheduling or invoking Convex component functions or runningidentify/beforeSendcallbacks (for example,disabled: !process.env.POSTHOG_PROJECT_TOKEN).disabled: trueshort-circuiting. Added a minor changeset for@posthog/convex.Release info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
@dustinbyrne.@posthog/convexwithposthog-node/posthog-pythondisabled-client semantics instead of using a magic sentinel string forPOSTHOG_PROJECT_TOKEN. MakingPOSTHOG_PROJECT_TOKENoptional on the component lets each app choose whether its owndefineApp({ env })enforces fail-at-deploy (v.string()) or permits tokenless dev/preview deployments (v.optional(v.string())), whilenew PostHog(components.posthog, { disabled })provides an optional fast-path to avoid scheduling no-op component actions.oxfmt --check,pnpm lint,pnpm check-types,pnpm build,pnpm test:unit, andpnpm test:integrationinpackages/convex(11 test files, 232 tests passing, 0 type/lint errors). No live Convex cloud deployment test was run.