Skip to content

Sentry: trace requests only, MCP calls at a lower rate; KG writes each edge once per pass - #794

Merged
keysersoft merged 1 commit into
mainfrom
perf/sentry-sampling-kg-batching
Sep 29, 2026
Merged

keysersoft merged 1 commit into
mainfrom
perf/sentry-sampling-kg-batching

Conversation

@keysersoft

Copy link
Copy Markdown
Contributor

At 5 % the cloud backend sent about 700,000 spans a day to Sentry, far past a plan's quota. By volume:

  • database spans of the knowledge-graph ingest, attached to the MCP call that scheduled it: a SELECT and an UPDATE on kg_edges for every shared value, even when many values link the same two nodes;
  • root spans with no request behind them (pg-pool.connect, prisma:client:*, bare SQL), each sampled as a transaction of its own.

Changes

  • common/sentry-sampler.ts: only HTTP requests are traced. MCP routes use SENTRY_MCP_TRACES_SAMPLE_RATE, default a fifth of SENTRY_TRACES_SAMPLE_RATE. /health is never traced. Incoming sampling decisions are not inherited, because MCP clients send their own sampled traceparent.
  • KgObservationalService.ingestOrganization runs under Sentry.suppressTracing. Errors are still reported.
  • correlate() counts bumps per distinct edge and writes each edge once. The end state is the same as the sequential writes: observations, confidence, the last matchKey set, and status (a rejected or manual edge keeps its own). The references confirmation runs once per node pair.

Tests

  • New sentry-sampler.spec.ts.
  • New KG test: four values linking the same nodes give one read and one write per edge, observations +4, and the same confidence as four sequential bumps.
  • Backend suite passes locally, except the HANA suite, which needs the hdb driver that isn't installed here.
  • Typecheck and lint are clean.

…tes each edge once per pass

- tracesSampler: HTTP requests at SENTRY_TRACES_SAMPLE_RATE, MCP routes at
  SENTRY_MCP_TRACES_SAMPLE_RATE (default a fifth), health probes and root
  spans with no request (background Prisma/pg work) never. Incoming trace
  decisions are not inherited: MCP clients send their own sampled traceparent.
- The observational KG ingest runs with tracing suppressed: scheduled from an
  MCP call, its queries were spans of that call's trace.
- correlate() counts bumps per edge and writes each distinct edge once, with
  the same end state (observations, confidence, matchKey, status), instead of
  a read and an update per shared value.
@keysersoft
keysersoft merged commit 052e186 into main Sep 29, 2026
14 checks passed
@keysersoft
keysersoft deleted the perf/sentry-sampling-kg-batching branch September 29, 2026 07:35
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant