Skip to content

fix: no-op when disabled or uninitialized#162

Merged
marandaneto merged 2 commits into
mainfrom
fix/noop-when-disabled
Jun 1, 2026
Merged

fix: no-op when disabled or uninitialized#162
marandaneto merged 2 commits into
mainfrom
fix/noop-when-disabled

Conversation

@marandaneto
Copy link
Copy Markdown
Member

💡 Motivation and Context

The SDK should not raise into the host application when it is disabled or the Rails facade is used before explicit initialization. Disabled clients previously still validated some event payloads before hitting the no-op worker, and Rails delegated calls raised until PostHog.init was called.

Changes:

  • Return no-op defaults from disabled identify, group_identify, alias, and capture_exception before payload validation.
  • Lazily install a disabled no-op client for the Rails facade when delegated methods are called before PostHog.init.
  • Add regression coverage for disabled client payloads and uninitialized Rails facade calls.

💚 How did you test it?

  • bundle exec rspec spec/posthog/client_spec.rb spec/posthog/rails/railtie_spec.rb

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file

@marandaneto marandaneto marked this pull request as ready for review June 1, 2026 06:11
@marandaneto marandaneto requested a review from a team as a code owner June 1, 2026 06:11
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Jun 1, 2026

Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
spec/posthog/client_spec.rb:59-70
**Test should be parameterised**
Each method is asserted twice (once for no-raise, once for return value), and the four methods are expressed as four separate copy-pasted blocks. The team's stated preference is parameterised tests. A table-driven form — e.g. `[[:identify, [{}]], [:group_identify, [{}]], ...].each do |method, args|` — would express the same invariant once and make it trivial to add new methods without drift.

### Issue 2 of 2
posthog-rails/lib/posthog/rails/railtie.rb:75-79
**Lazy init still emits a confusing error log**
`PostHog::Client.new(api_key: nil)` always logs `logger.error('api_key is missing or empty after trimming whitespace…')`. Any application that calls a PostHog method before `PostHog.init` — the exact scenario this PR is meant to handle gracefully — will see an error-level log entry pointing at a missing API key, even though no key has ever been configured. The `before_init` path is entirely intentional here, so the log noise is misleading rather than helpful. Consider either suppressing the error for this lazy-fallback construction path, or logging at a lower level (e.g. `:debug`) when the client is being created as a pre-init no-op placeholder.

Reviews (1): Last reviewed commit: "fix: no-op when disabled or uninitialize..." | Re-trigger Greptile

Comment thread spec/posthog/client_spec.rb
Comment thread posthog-rails/lib/posthog/rails/railtie.rb
@marandaneto marandaneto merged commit 80e2c13 into main Jun 1, 2026
15 checks passed
@marandaneto marandaneto deleted the fix/noop-when-disabled branch June 1, 2026 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants