feat(analytics): restructure PostHog config under analytics.posthog + wire env vars#3641
feat(analytics): restructure PostHog config under analytics.posthog + wire env vars#3641PierreBrisorgueil merged 1 commit intomasterfrom
Conversation
… wire env vars Move config.posthog.* → config.analytics.posthog.*, rename apiKey → key, and wire DEVKIT_NODE_analytics_posthog_* env vars so Node prod ingestion actually reads POSTHOG_* values from the manifest. Aligns Node convention with Vue (config.analytics.posthog.key) per Wave 3 of PostHog Cloud migration. All consumers and test fixtures updated. Fixes: prod logs "WARN analytics PostHog not configured" caused by Wave 1 leaving env reads commented out in development.config.js.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (12)
WalkthroughThis PR refactors the PostHog analytics configuration structure throughout the codebase, moving it from a top-level ChangesPostHog Configuration Structure Refactoring
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3641 +/- ##
=======================================
Coverage 89.14% 89.14%
=======================================
Files 135 135
Lines 4641 4641
Branches 1433 1433
=======================================
Hits 4137 4137
Misses 392 392
Partials 112 112
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR migrates PostHog configuration from config.posthog.* to config.analytics.posthog.* (including apiKey → key) and wires the new config shape throughout the runtime services and test fixtures so analytics/error-tracking can be enabled via DEVKIT_NODE_analytics_posthog_* env vars.
Changes:
- Restructured config defaults to
analytics.posthogand added env var reads forenabled/key/host/appTag/errorTracking/autoCapture. - Updated analytics + error-tracking + Express wiring to read from
config.analytics.posthogand usekey. - Migrated Home readiness checks and updated unit/integration tests to the new config shape.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| config/defaults/development.config.js | Adds analytics.posthog defaults and reads DEVKIT_NODE_analytics_posthog_* env vars. |
| lib/services/analytics.js | Switches config reads to config.analytics.posthog and uses key for client init. |
| lib/services/errorTracker.js | Migrates error-tracker gating to config.analytics.posthog + key. |
| lib/services/express.js | Mounts auto-capture middleware based on config.analytics.posthog.autoCapture. |
| modules/home/services/home.service.js | Updates readiness checks to the new analytics.posthog.key path. |
| modules/home/tests/home.integration.tests.js | Updates readiness integration setup to set config.analytics.posthog.key. |
| modules/home/tests/home.service.unit.tests.js | Updates readiness unit test fixtures and assertions to analytics.posthog.key. |
| lib/services/tests/analytics.service.unit.tests.js | Migrates analytics service unit test fixtures to analytics.posthog.key. |
| lib/services/tests/analytics.service.resilience.unit.tests.js | Migrates resilience test fixture to analytics.posthog.key. |
| lib/services/tests/analytics.forRequest.unit.tests.js | Migrates request-aware helper tests to analytics.posthog.key. |
| lib/services/tests/analytics.capture.unit.tests.js | Migrates capture/init tests to analytics.posthog.key. |
| lib/services/tests/errorTracker.unit.tests.js | Migrates error-tracker tests to analytics.posthog.key. |
| // analytics — PostHog | ||
| const posthogConfigured = isSet(config.posthog?.apiKey); | ||
| const posthogConfigured = isSet(config.analytics?.posthog?.key); | ||
| checks.push({ |
| // errorTracking — PostHog | ||
| const errorTrackingEnabled = posthogConfigured && config.posthog?.errorTracking === true; | ||
| const errorTrackingEnabled = posthogConfigured && config.analytics?.posthog?.errorTracking === true; | ||
| checks.push({ | ||
| category: 'errorTracking', | ||
| status: errorTrackingEnabled ? 'ok' : 'warning', | ||
| message: errorTrackingEnabled ? 'PostHog $exception capture enabled' : 'PostHog Error Tracking not enabled (set posthog.errorTracking=true)', | ||
| message: errorTrackingEnabled ? 'PostHog $exception capture enabled' : 'PostHog Error Tracking not enabled (set analytics.posthog.errorTracking=true)', |
| @@ -19,8 +19,8 @@ import analyticsService from './analytics.js'; | |||
| * @returns {void} | |||
| */ | |||
| const captureException = (err, ctx = {}) => { | |||
| const posthogConfig = config?.posthog ?? {}; | |||
| if (posthogConfig.apiKey && posthogConfig.errorTracking === true) { | |||
| const posthogConfig = config?.analytics?.posthog ?? {}; | |||
| if (posthogConfig.key && posthogConfig.errorTracking === true) { | |||
| analyticsService.captureException(err, ctx); | |||
| const { enabled, apiKey, host, flushAt, flushInterval, appTag } = config.posthog ?? {}; | ||
| if (!enabled || !apiKey) return; | ||
| const { enabled, key, host, flushAt, flushInterval, appTag } = config.analytics?.posthog ?? {}; | ||
| if (!enabled || !key) return; |
| // auto-capture middleware is opt-in: only mounted when analytics.posthog.autoCapture === true. | ||
| try { | ||
| await AnalyticsService.init(); | ||
| if (config.posthog?.autoCapture === true) { | ||
| if (config.analytics?.posthog?.autoCapture === true) { | ||
| app.use(analyticsMiddleware); | ||
| } |
| expect(row.status).toBe('warning'); | ||
| }); | ||
|
|
||
| test('warning when posthog is not configured at all', async () => { |
Summary
config.posthog.{apiKey,host,appTag}commented out andenabled: false. The Trawl Node manifest setsPOSTHOG_*env vars but no code path read them, soconfig.posthog.apiKey === undefined→ service stayed no-op. Prod logs:WARN analytics PostHog not configured.config.posthog.*→config.analytics.posthog.*, renameapiKey→key, and wire all env reads toDEVKIT_NODE_analytics_posthog_{enabled,key,host,appTag,errorTracking,autoCapture}.config.analytics.posthog.keypath (cfpierreb-devkit/Vue+trawl_vue/.github/workflows/build.yml).Files changed
config/defaults/development.config.js— restructure block, uncomment env reads, dropsentry:remnantlib/services/analytics.js—config.posthog→config.analytics?.posthog,apiKey→keylib/services/errorTracker.js— same path migration +apiKey→keylib/services/express.js—config.posthog?.autoCapture→config.analytics?.posthog?.autoCapturemodules/home/services/home.service.js— readiness check:config.posthog?.apiKey→config.analytics?.posthog?.key{ posthog: { apiKey:... } }→{ analytics: { posthog: { key:... } } }Downstream impact
After merge:
trawl_nodepicks this up via/update-stack, then infra manifest renamesPOSTHOG_*→DEVKIT_NODE_analytics_posthog_*(Wave W3.3). No downstream project overridesconfig.posthogat config level — all get values via env vars.Test plan
npm run lint— ESLint: No issues foundnpm run test:unit— 1358 passed, 0 failed (all analytics/errorTracker/home tests green)npm run test:coverage— 1759 passed, 3 pre-existing failures (MongoDB$sortArrayversion constraint, unrelated)Summary by CodeRabbit