feat(sentry): usage-tier sync-session transaction, sync metrics wiring, bg/fg breadcrumbs#199
Open
gmaclennan wants to merge 2 commits into
Open
feat(sentry): usage-tier sync-session transaction, sync metrics wiring, bg/fg breadcrumbs#199gmaclennan wants to merge 2 commits into
gmaclennan wants to merge 2 commits into
Conversation
…g, bg/fg breadcrumbs Derive sync sessions from the data.isSyncEnabled edges of each project's $sync sync-state events: a comapeo.sync.session transaction (usage-tier, sampled via a name-matched tracesSampler so it records while the base trace rate is 0) with discover/replicate child spans, carrying only bucketed peer count, bucketed bytes, and outcome. The same lifecycle wires the previously call-site-less metrics.syncSession emitter (duration at diagnostic tier, peers/bytes buckets usage-gated). RN side adds comapeo.app.background/foreground breadcrumbs from AppState changes, usage-gated. Closes #80.
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.
Closes #80.
Sync-session transaction + metrics
@comapeo/coreexposes two usable sync lifecycle signals: each project's$syncemitssync-state(withdata.isSyncEnabledand a per-peer map of remainingwant/wantedblock counts), andMapeoManageremitslocal-peers. There is no project-opened event and no per-phase events, so the newbackend/lib/sync-observer.jswrapsmanager.getProject(the only project-open hook) and derives a session from thedata.isSyncEnablededges: false→true starts it, true→false (manual stop or autostop-after-synced) ends it. Outcome iscompletedwhen the last peer-bearing state had nothing left to send or receive in either namespace group, elsestopped.The
comapeo.sync.sessiontransaction is usage-tier: it is only created whenapplicationUsageDatais on, and a name-matched branch in a newtracesSampler(backendSentry.init) samples it at 1 so it records while the base trace rate is 0; all other spans keep the previous parent-based / native-resolved-rate behaviour. Its attributes are restricted tooutcome,peers_bucket,bytes_bucket— no peer identities, no project IDs (asserted in tests against the serialized envelope).Two honest limitations, from what the core API actually exposes:
sync.discover(session start until the first peer appears; skipped when peers are already connected) andsync.replicate. A handshake phase is not derivable — the noise/protomux handshake is internal to core and surfaces no event.bytes_bucketreportsunknown(on both the transaction and the counter) until core exposes bytes. The §9.2 table row notes this.The same session end wires the previously call-site-less
metrics.syncSessionemitter:comapeo.sync.session.duration_msstays diagnostic-tier, the peers/bytes bucket counters stay usage-gated inside the helper.peersBucketgains a0bucket for sessions where no peer ever connected.RN bg/fg breadcrumbs
src/sentry.tsattaches anAppStatechange listener at module load (same pattern as the existing state listeners): transitions tobackground/activeaddcomapeo.app.background/comapeo.app.foregroundbreadcrumbs so an error reads as "fired N seconds after backgrounding" from crumb timestamps. Gated onsentryReadyplus a snapshot-at-launchapplicationUsageDataread; iOS transientinactiveand repeated same-direction events are ignored. No dependency change —@sentry/react-nativeremains a peer dependency.Docs
§9.2 tier table: removed the "not yet wired (#80)" markers from the three sync rows only (the shutdown/ipc/telemetry rows belong to #190) and documented the bucket sets /
unknownbytes limitation.Tests
Backend (
sync-observer.test.mjs, real SDK + OTel wiring likesentry.test.mjs): usage on ⇒ transaction envelope reaches the sink with only the allowed attributes and the derived child spans; usage off ⇒ no envelope, duration metric still records, bucket counters absent; stopped outcome; zero-peer bucket; watcher seeded mid-session. RN (sentry.test.js): crumbs added when usage tier on, deduped, absent when tier off or Sentry never initialised.npm run lint,npm run build,npm run test(72) andnpm run backend:test(78) all pass. Not verified on-device; the backend tests drive the real Sentry SDK end to end.