Skip to content

Batch telemetry through a getbb.app Worker and count threads and messages - #8402

Merged
SawyerHood merged 2 commits into
mainfrom
posthog-reduce-events
Nov 30, 2026
Merged

SawyerHood merged 2 commits into
mainfrom
posthog-reduce-events

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

Cuts bb's PostHog volume and puts a Worker of ours between bb and PostHog, so the analytics backend can change without an app release.

Why

About 3.7M events a week, most of them user_message_sent (2.4M) and thread_created (746k), many from automations, plugins and duplicate first messages. Releases before 0.50.1 also created person profiles, so later events were billed as identified. Projected bill for this period: about $1,425.

What changes

bb server (apps/server/src/services/system/telemetry.ts, telemetry-outbox.ts)

  • Threads and messages are counted per day, provider and initiator, and sent as one usage_counts event each (period: "day", period_start, threads_created, messages_sent). Automated threads and messages are still counted.
  • Other events are queued and sent in batches about once a minute and at shutdown to BB_TELEMETRY_URL (default https://getbb.app/api/telemetry/v1/batch), in bb's own format.
  • Unsent telemetry lives in telemetry-outbox.json (not bb.db). A batch is resent with the same event ids until the Worker accepts it; opting out sends what was recorded, then deletes the file.
  • New install id file telemetry-id-v2, so old person profiles stop upgrading events to identified billing.
  • BB_TELEMETRY_URL replaces BB_POSTHOG_API_KEY; the PostHog key is no longer in the app.

Worker (apps/telemetry, route getbb.app/api/telemetry/*)

  • Validates batches (snake_case names only, so no $ properties from clients; flat values; size and age limits), rate-limits per install.
  • Adds country, region and city from Cloudflare as PostHog's $geoip_* properties and does not forward the IP (/batch/?ip=0, $geoip_disable), with $process_person_profile: false.
  • Backend is a config var (posthog or discard); staging discards.
  • deploy-telemetry.yml tests and deploys it on push to main.

App: new_thread_submit is only sent for failed submits.

Docs and the privacy page are updated.

Rollout

  1. Merge: deploys the Worker (no released version calls it yet).
  2. Send a test batch; check location, no IP, and that a resent uuid is deduplicated.
  3. Release. Old versions keep sending the old events until they update; daily totals during the transition are old events + usage_counts sums.

Tests

Server tests (97 files, 1,195 tests), Worker tests, server-archive, config and composer tests pass; typecheck clean. 5 bb-app launcher tests in test/index.test.ts time out locally on main too.

…ages

The bb server no longer sends one PostHog event per message and per thread.
Threads and messages are counted per day, provider and initiator and sent as
usage_counts events; other events are queued. Batches go about once a minute
and at shutdown to BB_TELEMETRY_URL (getbb.app/api/telemetry/v1/batch) in
bb's own format, kept in telemetry-outbox.json until accepted.

The new apps/telemetry Worker validates batches, adds coarse location from
Cloudflare without forwarding the IP, and forwards them to PostHog without
person profiles. The PostHog key moves out of the app, so the backend can
change without a release. A new install id file (telemetry-id-v2) stops old
person profiles from upgrading events to identified billing.

new_thread_submit is only sent for failed submits.
@blacksmith-sh

This comment has been minimized.

@SawyerHood
SawyerHood merged commit c138072 into main Nov 30, 2026
96 of 97 checks passed
@SawyerHood
SawyerHood deleted the posthog-reduce-events branch November 30, 2026 19:06
scowalt pushed a commit to scowalt/bb that referenced this pull request Dec 1, 2026
…ages (get-bb#8402)

Cuts bb's PostHog volume and puts a Worker of ours between bb and
PostHog, so the analytics backend can change without an app release.

## Why
About 3.7M events a week, most of them `user_message_sent` (2.4M) and
`thread_created` (746k), many from automations, plugins and duplicate
first messages. Releases before 0.50.1 also created person profiles, so
later events were billed as identified. Projected bill for this period:
about $1,425.

## What changes
**bb server** (`apps/server/src/services/system/telemetry.ts`,
`telemetry-outbox.ts`)
- Threads and messages are counted per day, provider and initiator, and
sent as one `usage_counts` event each (`period: "day"`, `period_start`,
`threads_created`, `messages_sent`). Automated threads and messages are
still counted.
- Other events are queued and sent in batches about once a minute and at
shutdown to `BB_TELEMETRY_URL` (default
`https://getbb.app/api/telemetry/v1/batch`), in bb's own format.
- Unsent telemetry lives in `telemetry-outbox.json` (not `bb.db`). A
batch is resent with the same event ids until the Worker accepts it;
opting out sends what was recorded, then deletes the file.
- New install id file `telemetry-id-v2`, so old person profiles stop
upgrading events to identified billing.
- `BB_TELEMETRY_URL` replaces `BB_POSTHOG_API_KEY`; the PostHog key is
no longer in the app.

**Worker** (`apps/telemetry`, route `getbb.app/api/telemetry/*`)
- Validates batches (snake_case names only, so no `$` properties from
clients; flat values; size and age limits), rate-limits per install.
- Adds country, region and city from Cloudflare as PostHog's `$geoip_*`
properties and does not forward the IP (`/batch/?ip=0`,
`$geoip_disable`), with `$process_person_profile: false`.
- Backend is a config var (`posthog` or `discard`); staging discards.
- `deploy-telemetry.yml` tests and deploys it on push to `main`.

**App**: `new_thread_submit` is only sent for failed submits.

Docs and the privacy page are updated.

## Rollout
1. Merge: deploys the Worker (no released version calls it yet).
2. Send a test batch; check location, no IP, and that a resent uuid is
deduplicated.
3. Release. Old versions keep sending the old events until they update;
daily totals during the transition are old events + `usage_counts` sums.

## Tests
Server tests (97 files, 1,195 tests), Worker tests, server-archive,
config and composer tests pass; typecheck clean. 5 `bb-app` launcher
tests in `test/index.test.ts` time out locally on `main` too.
@SawyerHood SawyerHood mentioned this pull request Dec 2, 2026
SawyerHood added a commit that referenced this pull request Dec 2, 2026
## Human comments

## What was wrong

`main` has 331 commits since `desktop-v0.50.1` with no release notes,
and `bb-app` and `@bb/desktop` are still at 0.50.1.

## What changed

- `packages/bb-app/package.json`, `apps/desktop/package.json`: 0.50.1 →
0.51.0 (`node scripts/bump-version.mjs --minor`). The release adds 14
database migrations (0159–0172), raises `HOST_DAEMON_PROTOCOL_VERSION`
from 268 to 286, moves `@get-bb/plugin-sdk` from 0.6.157 to 0.6.216,
replaces the Cursor agent with Grok Build, and turns six early-adopter
experiments on for everyone (#8068).
- `CHANGELOG.md`: the 0.51.0 section, covering `desktop-v0.50.1` through
#8507 (`4d7a9af609`). Same sections as 0.50.0: Reliability, Performance,
Usability, Experiments, Now on for everyone, Agents, Bug fixes, Plugins,
Security, Thanks (21 outside contributors). The telemetry rework (#8402)
is left out on purpose.
- `changelog-metadata.ts`: the 0.51.0 `RELEASE_META` entry (December 2,
2026, "Warm worktrees, multi-folder projects, and new agents").

## How you verified

- `node .github/workflows/check-version-lockstep.mjs`: `bb-app=0.51.0
@bb/desktop=0.51.0`.
- `pnpm exec turbo run typecheck test --filter=@bb/app
--filter=@bb/config --filter=@bb/server --filter=bb-app`: 17/17 tasks
(`@bb/app` 709 files, 7574 passed, 20 skipped).
- `pnpm exec turbo run smoke:tarball --filter=bb-app --force`: passed in
51 s.
- oxfmt on `CHANGELOG.md` and `changelog-metadata.ts`, and `git diff
--check`: clean.

> AGENT GENERATED
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.

1 participant