Skip to content

Commit 5844ca7

Browse files
authored
feat(dashboard): add structured logging and error filtering for Sentry (#4584)
* feat(dashboard): add structured logging and error filtering for Sentry - Add structured logger module with specialized methods for tRPC and user action logging - Create error classification utilities to categorize and map tRPC errors to appropriate log levels - Implement Sentry error filters to prevent expected tRPC errors from being reported as incidents - Add logging index module to export logging utilities and error classification functions - Update Sentry client and server configurations to use new error filtering - Update tRPC client configuration to integrate structured logging - Update instrumentation client to apply error filtering on client-side Sentry initialization - Provides consistent attribute naming and context tracking across all log entries - Improves observability by distinguishing between expected errors and actual issues * feat(dashboard): implement dynamic trace sampling across Sentry configs - Replace static tracesSampleRate with dynamic tracesSampler in client, edge, and server Sentry configurations - Prioritize 100% sampling for error-prone operations (auth, payment, api/key, tRPC, HTTP 4xx/5xx) - Reduce sampling to 1% for health checks and monitoring endpoints (healthcheck, health, ping, metrics) - Eliminate sampling (0%) for static assets (_next/static, favicon, robots.txt, sitemap) - Set default 10% sampling rate for general operations to reduce noise while maintaining observability - Add null-safety check for transaction names with 10% fallback sampling - Reduces Sentry quota usage while ensuring critical errors and operations are fully captured * Make a reusable trace-sampler
1 parent 33d4d6e commit 5844ca7

File tree

10 files changed

+1260
-36
lines changed

10 files changed

+1260
-36
lines changed

web/apps/dashboard/instrumentation-client.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
44

55
import * as Sentry from "@sentry/nextjs";
6+
import { createClientErrorFilter, createTracesSampler } from "./lib/sentry";
67

78
Sentry.init({
89
dsn: "https://08589d17fe3b4b7e8b70b6c916123ee5@o4510544758046720.ingest.us.sentry.io/4510544758308864",
910

11+
// Filter expected tRPC errors from being reported as Sentry errors
12+
beforeSend: createClientErrorFilter(),
13+
1014
// Add optional integrations for additional features
1115
integrations: [
1216
Sentry.replayIntegration({
@@ -42,8 +46,8 @@ Sentry.init({
4246
}),
4347
],
4448

45-
// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
46-
tracesSampleRate: 1,
49+
// Use dynamic sampling to reduce non-error traces while ensuring all errors are captured
50+
tracesSampler: createTracesSampler(),
4751
// Enable logs to be sent to Sentry
4852
enableLogs: true,
4953

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Logging module exports
3+
*
4+
* Provides structured logging capabilities for the dashboard application
5+
* with consistent attribute naming and Sentry integration.
6+
*/
7+
8+
export {
9+
logTRPCError,
10+
logUserAction,
11+
logOperation,
12+
type BaseLogAttributes,
13+
type TRPCLogAttributes,
14+
type UserActionAttributes,
15+
type LogAttributes,
16+
type LogContext,
17+
type LogLevel,
18+
} from "./structured-logger";
19+
20+
// Re-export error classification utilities for convenience
21+
export {
22+
isExpectedTRPCError,
23+
extractTRPCErrorInfo,
24+
getErrorLogLevel,
25+
classifyError,
26+
type TRPCErrorInfo,
27+
type ErrorClassification,
28+
} from "../utils/error-classification";

0 commit comments

Comments
 (0)