feat: add PostHog environment super property - #97
JakubAnderwald wants to merge 1 commit into
Conversation
Register an 'environment' super property on PostHog init so all events are tagged with 'production' or 'development'. This enables filtering analytics by environment in the PostHog dashboard. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThe pull request registers PostHog with an environment super property during client initialization, setting the value based on NODE_ENV, and updates a progress tracker documentation to mark Phase 1.2 as completed. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/lib/posthog/client.ts`:
- Around line 18-20: The code calls posthog.register and reads
process.env.NODE_ENV directly; replace that raw process.env access with the
validated value exported from your env schema (the module that declares NODE_ENV
via zod, e.g., the exported `env` from src/env.ts). Import the env object (or
the specific exported variable that represents NODE_ENV) and use that (for
example `env.NODE_ENV === "production" ? "production" : "development"`) inside
posthog.register so the value is schema-validated rather than reading
process.env directly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 4e0abbd8-73fb-4c10-937b-0f8d39b75f9c
📒 Files selected for processing (2)
docs/Dev-Prod Environment Separation-ralph.mdsrc/lib/posthog/client.ts
| posthog.register({ | ||
| environment: process.env.NODE_ENV === "production" ? "production" : "development", | ||
| }); |
There was a problem hiding this comment.
Replace raw process.env usage with validated env access.
Line 19 reads process.env.NODE_ENV directly inside src/, which violates the repository env-handling rule and bypasses schema-based configuration.
Proposed fix
posthog.register({
- environment: process.env.NODE_ENV === "production" ? "production" : "development",
+ environment: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT ?? "development",
});As per coding guidelines: src/**/*.{ts,tsx,js,jsx}: "Declare all environment variables in src/env.ts using zod schemas. Never use process.env directly in code."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/lib/posthog/client.ts` around lines 18 - 20, The code calls
posthog.register and reads process.env.NODE_ENV directly; replace that raw
process.env access with the validated value exported from your env schema (the
module that declares NODE_ENV via zod, e.g., the exported `env` from
src/env.ts). Import the env object (or the specific exported variable that
represents NODE_ENV) and use that (for example `env.NODE_ENV === "production" ?
"production" : "development"`) inside posthog.register so the value is
schema-validated rather than reading process.env directly.
Summary
environmentsuper property (production/development) on PostHog initTest plan
🤖 Generated with Claude Code
Summary by CodeRabbit
Documentation
New Features