Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/Dev-Prod Environment Separation-ralph.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ You are running in an autonomous, unattended loop. On every single execution, yo
### Phase 1: Environment Tagging (Sentry + PostHog)

- [x] 1.1 — Add `NEXT_PUBLIC_SENTRY_ENVIRONMENT` to env schema + all Sentry init files
- [ ] 1.2 — Add PostHog environment super property
- [x] 1.2 — Add PostHog environment super property
- [ ] 1-CP — **Checkpoint**: full suite green
- [ ] 1-PUSH — **Push**: `/push` to PR

Expand Down
3 changes: 3 additions & 0 deletions src/lib/posthog/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export function getPostHogClient() {
person_profiles: "identified_only",
capture_pageview: false, // We capture manually in the provider
});
posthog.register({
environment: process.env.NODE_ENV === "production" ? "production" : "development",
});
Comment on lines +18 to +20

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

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.

}

return posthog;
Expand Down
Loading