fix: no-op when disabled or uninitialized#162
Merged
Conversation
Prompt To Fix All With AIFix 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 |
turnipdabeets
approved these changes
Jun 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 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.initwas called.Changes:
identify,group_identify,alias, andcapture_exceptionbefore payload validation.PostHog.init.💚 How did you test it?
bundle exec rspec spec/posthog/client_spec.rb spec/posthog/rails/railtie_spec.rb📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file