Skip to content

feat(telemetry): add typed Sentry telemetry model and bootstrap#324

Merged
provencher merged 1 commit into
cameroncooke/sentry-01-build-plumbingfrom
cameroncooke/sentry-02-telemetry-foundation
Jul 2, 2026
Merged

feat(telemetry): add typed Sentry telemetry model and bootstrap#324
provencher merged 1 commit into
cameroncooke/sentry-01-build-plumbingfrom
cameroncooke/sentry-02-telemetry-foundation

Conversation

@cameroncooke

@cameroncooke cameroncooke commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds the data-minimization core: a closed typed telemetry model and the bootstrap that initializes Sentry and exposes the emit primitives. This is the privacy boundary expressed in code.

Stack: 2/10 · depends on PR 1 · Refs GH-183

What this changes

  • SentryTelemetryModel.swift — closed enums (Category, Action, Transaction, Metric, SpanOperation, Attribute, plus ModelFamily/ProviderKind/ToolName/TokenBudgetBucket…). No Attribute case accepts an arbitrary String.
  • SentryTelemetryBootstrap.swift — the only file that imports Sentry (gated). start() + addBreadcrumb/increment/gauge/distributionMilliseconds/trace/span primitives.

Business rules (the privacy boundary)

  • No user content can be expressed. Attributes are closed enums, bools, counts, and buckets only.
  • Counts are clamped: negative → dropped, capped at 999_999, so an internal count can't become a precise fingerprint.
  • Unknown/custom tool names degrade to domain only (ToolName(rawValue:) returns nil).
  • Raw model/provider names never escape — bucketed into ModelFamily/ProviderKind; token sizes bucketed into TokenBudgetBucket.
  • start() config is conservative: sendDefaultPii = false; session replay, MetricKit, structured logs, auto network/file-IO/CoreData/auto-perf tracing all off; maxBreadcrumbs = 50, maxCacheItems = 30; only crashes, uncaught NSExceptions, and app-hangs auto-captured. tracesSampleRate 1 (debug) / 0.3 (prod).
  • A literal Attribute.allowedKeys set + the single telemetryData(from:) funnel guarantee every emit path (breadcrumb/span/metric) is allow-listed identically.

Key decisions

  • The model is an extension of the SentryTelemetryBootstrap enum, so the two files are one type and must ship together (this is why the PR is ~740 LOC and indivisible).
  • Attributes are @autoclosure so a disabled build never even constructs the array (zero overhead).
  • trace/span helpers tag is_error and finish spans; #else passthroughs make them transparent when telemetry is compiled out.

Note on size

~740 LOC, over the 500 target, but irreducible: splitting would either break the single-type relationship or change the final bytes.

Test plan

  • Compiles in both modes (flag on/off). ✅ verified.
  • (Contract unit tests were intentionally removed by the author and are not part of this stack.)

@cameroncooke cameroncooke force-pushed the cameroncooke/sentry-02-telemetry-foundation branch from 90179cb to c6ba672 Compare June 29, 2026 21:40
@cameroncooke cameroncooke force-pushed the cameroncooke/sentry-01-build-plumbing branch from d17e5a0 to 531da8a Compare June 29, 2026 21:40
@cameroncooke cameroncooke marked this pull request as ready for review June 30, 2026 01:06
@provencher provencher merged commit d9519dd into cameroncooke/sentry-01-build-plumbing Jul 2, 2026
6 of 7 checks passed
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