Monitoring & Error Tracking Setup
Configure Sentry error tracking and PostHog analytics for your TinyKit Pro application. Both services are optional and independently configurable.
Configure Sentry error tracking and PostHog analytics for your TinyKit Pro application. Both services are optional and independently configurable — the app works normally without either.
Overview
TinyKit Pro integrates two monitoring services:
- Sentry — Error tracking with stack traces, error grouping, alerting, and automatic GitHub issue creation
- PostHog — Product analytics with user journey tracking, autocapture, and error-to-conversion correlation
Both services follow the graceful degradation pattern: if an API key is missing, that service is silently disabled with zero impact on the application.
Why Both Services?
| Service | Purpose | Key Capability |
|---|---|---|
| Sentry | Reactive error debugging | Stack traces, error grouping, GitHub auto-issue creation |
| PostHog | Proactive product analytics | User journeys, conversion funnels, feature usage |
Sentry Setup
1. Create a Sentry Account
- Sign up at sentry.io
- Create a new project — select Browser JavaScript as the platform
- Copy the DSN from Settings > Projects > [Your Project] > Client Keys (DSN)
2. Configure the Environment Variable
Add your Sentry DSN to .env.local:
NEXT_PUBLIC_SENTRY_DSN=https://examplekey@o1234.ingest.sentry.io/5678Or use the setup wizard:
bun setup:analytics3. How It Works
Sentry is initialized automatically via instrumentation-client.ts when the DSN is present. The integration includes:
- Error boundaries — React errors caught by
ConvexErrorBoundaryandErrorBoundaryare reported to Sentry with component stack traces - Global error handler —
global-error.tsxcatches layout-level errors outside the component tree - User context — Authenticated user IDs are attached to Sentry events (no PII like email)
- ConvexError classification — Intentional errors (validation, auth) are downgraded to
infoseverity to reduce alert noise
Error Severity Strategy
Frontend Error
├─► ConvexError (validation, auth, business logic) → Sentry level: "info"
└─► Unexpected error (bugs, crashes) → Sentry level: "error"This ensures Sentry alerts only fire for real bugs, not expected validation errors.
4. Convex Backend Errors (Optional)
Convex's native Sentry integration captures backend function errors with zero code changes:
- Go to your Convex Dashboard > Deployment Settings > Integrations
- Select the Sentry card
- Paste the same DSN
- Requires Convex Pro plan
Auto-applied tags include: func, func_type, func_runtime, request_id, environment, and user.
See Convex Sentry docs for details.
5. GitHub Integration (Optional)
Configure Sentry to auto-create GitHub issues from errors:
- Settings > Integrations > GitHub — Connect your repo
- Alerts > Issue Alerts — Create a rule:
- Condition: "A new issue is created"
- Filter: Level is
error(excludesinfo-level ConvexErrors) - Action: "Create a GitHub Issue"
- Use
fixes SENTRY-XXXin commit messages to auto-resolve issues
PostHog Setup
1. Create a PostHog Account
- Sign up at posthog.com (generous free tier)
- Copy your Project API Key from Settings > Project > API Key
2. Configure Environment Variables
Add to .env.local:
NEXT_PUBLIC_POSTHOG_KEY=phc_your_posthog_key_here
NEXT_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com3. How It Works
PostHog is initialized in instrumentation-client.ts with autocapture enabled. The configuration includes:
- Autocapture — Automatic click, page view, and form tracking
- Exception capture — Frontend errors linked to analytics sessions
- Privacy-first — Session replay, feature flags, and surveys are disabled by default
- Dev mode — Reduced network activity during local development
Error Capture Overlap
By default, both PostHog (capture_exceptions: true) and Sentry capture frontend errors. They serve different purposes:
- PostHog: Links errors to analytics sessions — "which user journey led to this error?"
- Sentry: Deep error debugging — stack traces, breadcrumbs, grouping, alerting
To let Sentry handle all error tracking, disable PostHog's error capture:
// instrumentation-client.ts
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, {
capture_exceptions: false, // Let Sentry handle errors
// ... rest of config
});Graceful Degradation
| Scenario | Behavior |
|---|---|
| No Sentry DSN | Error boundaries still work, errors only appear in browser console |
| No PostHog key | No analytics captured, app functions normally |
| Neither configured | App works normally — ideal for local development |
| Only Sentry | Error tracking active, no product analytics |
| Only PostHog | Analytics active, errors captured by PostHog only |
| Both configured | Full pipeline: PostHog for analytics, Sentry for error debugging |
Architecture
Key Files
| File | Purpose |
|---|---|
src/lib/sentry.ts | Sentry utility — initSentry(), captureError(), setSentryUser(), isConvexError() |
instrumentation-client.ts | Initializes both Sentry and PostHog on client startup |
src/app/global-error.tsx | Catches layout-level errors, reports to Sentry |
src/lib/providers/convex-error-boundary.tsx | Catches React errors, reports to Sentry |
Error Flow
Component Error
├─► ErrorBoundary.componentDidCatch
│ ├─► logger.error(...) // Structured logging
│ ├─► captureError(error, context) // Sentry (if configured)
│ └─► Render fallback UI
│
├─► PostHog (if capture_exceptions: true)
│ └─► Error linked to analytics session
│
└─► Sentry Dashboard
├─► Grouped by error type
├─► User context (userId only)
└─► Component stack traceVerification
After configuring either service:
- Sentry: Trigger a test error in development, then check the Sentry dashboard (errors only appear when
NODE_ENV=production, or temporarily setenabled: trueinsentry.tsfor testing) - PostHog: Visit your app and check the PostHog dashboard for page view events
- Graceful degradation: Remove the DSN/key from
.env.localand verify the app still works without errors