Skip to content

feat(debug): Make data reliable when debuging - #316

Open
jrosendahl-opt wants to merge 3 commits into
masterfrom
feat/debug-flag-overrides
Open

feat(debug): Make data reliable when debuging#316
jrosendahl-opt wants to merge 3 commits into
masterfrom
feat/debug-flag-overrides

Conversation

@jrosendahl-opt

@jrosendahl-opt jrosendahl-opt commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Summary

When you are debuging a page the sampling and a/b infrastructure get in the way. This change makes it so when you are in debug mode you are also in the production group and there is no analytics sampling.

  • Analytics sampling: shouldSample() now returns true immediately when optableDebug is set, regardless of the configured samplingRate
  • AB test group: optableDebug forces the production/treatment group, same as optableControlGroup=0 — explicit optableControlGroup=1 still takes priority
  • Bot detection: SkipTargetingForBots() returns false immediately when optableDebug is set, so targeting always runs even in bot-like environments (e.g. headless browsers during development)

Activated via ?optableDebug URL param or sessionStorage.setItem("optableDebug", "1") in the browser console, using the existing flags system.

Test plan

  • optableDebug in sessionStorage causes shouldSample() to return true even with samplingRate: 0
  • optableDebug forces production group assignment even when random bucket would land in control
  • optableControlGroup=1 overrides optableDebug (explicit control override still works)
  • SkipTargetingForBots() returns false when optableDebug is set
  • All existing tests pass (npx jest)

🤖 Generated with Claude Code

@jrosendahl-opt
jrosendahl-opt requested review from a team as code owners August 14, 2026 15:29
@jrosendahl-opt
jrosendahl-opt requested a review from Yoshiji August 14, 2026 15:29
@jrosendahl-opt jrosendahl-opt changed the title feat(debug): optableDebug flag forces sampling=1, production group, and bypasses bot detection feat(debug): Make data reliable when debuging Aug 14, 2026
Comment thread lib/addons/prebid/analytics.ts Outdated
* @returns true if the event should be sampled and analytics calls may proceed.
*/
shouldSample(): boolean {
if (getFlags().optableDebug) return true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Personally, I'd bind this to optableControlGroup instead of optableDebug.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This PR has both controlGroup and the sample rate tied to debug with the assumption that when you are debugging you don't want activity hidden by sampling.

Most of the time the first question is did x happen. If id does not happen because of some sampling issue, debugging becomes non-intuitive until you realize sampling is the issue, and then you have to figure out how to turn sampling off.

Is there a use case where logging + sampling + control + turning off bot detection this would present a problem?

If so we could use a different parameter than optableDebug.

@jplaroche jplaroche left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

left a comment

jrosendahl-opt and others added 2 commits September 8, 2026 15:51
…nd bypasses bot detection

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… flag

optableDebug is documented for publishers as a logging switch, so overloading
it silently changed sampling, A/B assignment and bot detection for anyone
already setting it. The overrides move to their own flag, read through
flagEnabled so an explicit "=0" turns them off.

Three further problems the overrides introduced:

- The witness payload reported the configured samplingRate while sampling was
  forced on, so the processor extrapolated a debug session as a full sample: a
  0.1 rate scaled one debug auction to ten. It now reports the effective rate
  and tags the event with optableDebugOverrides so debug traffic can be
  excluded from aggregates.
- OPTABLE_TARGETING_DONE outlives the flag, so a session that had already been
  bot-detected kept short-circuiting RTD even with the override on. The
  override now clears the key.
- A flag-forced A/B variant was written to localStorage, pinning the browser to
  that group long after the flag was gone. Forced variants are no longer
  persisted, which also fixes the pre-existing optableControlGroup case.
@mosherBT
mosherBT force-pushed the feat/debug-flag-overrides branch from b6a8e7e to 23d77a9 Compare September 8, 2026 19:59
- flags.md gained the optableDebugOverrides row. That registry is the documented
  source of truth, and the key had only been described in a FLAG_KEYS comment,
  which is now trimmed to the one thing visible from the key list: why a second
  debug flag exists at all.
- setupAB persists inside the priority-3 branch that assigns the variant, so the
  "never persist a forced variant" rule no longer rides on a boolean whose
  meaning depends on sitting between two priority blocks. A new resolution step
  can no longer silently inherit it.
- SkipTargetingForBots reuses the try/catch it already had instead of adding a
  second one ahead of it.
- effectiveSamplingRate() collapses into one local in the payload builder, its
  only caller, so the reported rate and the debug tag are read once and cannot
  disagree for a single event. Its tests now assert the payload fields rather
  than the helper, covering the contract that actually matters.
- botDetection.md documents the SkipTargetingForBots contract change, and the
  per-feature docs link to flags.md instead of restating the =0 semantics.
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.

3 participants