Skip to content

Add mode configuration option#114

Draft
martosaur wants to merge 2 commits into
PostHog:mainfrom
martosaur:am-improve-error-for-disabled-default-supervisor
Draft

Add mode configuration option#114
martosaur wants to merge 2 commits into
PostHog:mainfrom
martosaur:am-improve-error-for-disabled-default-supervisor

Conversation

@martosaur
Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Should address #81 (see comment)

Changes:

  1. Improve error for cases when user set enable: false in configuration but still tried to use default PostHog instance.
  2. Introduce new configuration options mode :: :normal | :drop_events | :test. normal mode is, well, normal. test mode is basically current test_mode: true (and thus test_mode option is deprecated). drop_events simply drops all events instead of sending them to PostHog.

💚 How did you test it?

Unit tests

📝 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 sampo add to generate a changeset file

@martosaur martosaur requested review from a team and rafaeelaudibert as code owners May 11, 2026 04:31
@marandaneto
Copy link
Copy Markdown
Member

@martosaur thanks for the PR but thats a breaking change and we cannot simply remove test_mode
You can simply start the SDK with enable: false when it's in testing mode
Another approach is to implement the before_send callback as the other SDKs do, so you can simply implement a callback that drops the event if it's in staging/dev mode

but still tried to use default PostHog instance.

we can fix this in this PR only and follow up with another PR for a different approach but lets not address both things here that also have a breaking change

@martosaur martosaur force-pushed the am-improve-error-for-disabled-default-supervisor branch from 5d7b1cc to e74c07f Compare May 11, 2026 15:37
@martosaur
Copy link
Copy Markdown
Contributor Author

Hi @marandaneto , nice to meet you! Thanks for taking a look.

thats a breaking change and we cannot simply remove test_mode

That's a good call out! To be clar, the option is not removed, just merely deprecated. We still accept it and if passed, it will work as before. That should be backwards compatible change. I've pushed a test to better highlight this.

You can simply start the SDK with enable: false when it's in testing mode

enable: false works a little differently: it allows users to disable "managed" PostHog supervision tree to instead run it under their own application. This configuration option can't be used as a way to "turn off" posthog in dev. That's exactly the situation this comment is describing.

Another approach is to implement the before_send callback as the other SDKs do, so you can simply implement a callback that drops the event if it's in staging/dev mode

I'm confused, I don't see this callback anywhere?

@marandaneto
Copy link
Copy Markdown
Member

@martosaur https://posthog.com/docs/libraries/python#disabling-requests-during-tests

SDKs should not throw if disabled is enabled or malconfigured, but instead log and be noop, this is gonna be fixed here eg #107
Another option is the before send eg https://posthog.com/docs/libraries/js/usage#amending-or-sampling-events
so you can do eg

config.before_send = { event
  if (DEV)
    return null
}

So I think this PR should not yet add another public API to address the very same issue.

@marandaneto marandaneto marked this pull request as draft May 11, 2026 19:24
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