-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathsentry.server.config.ts
More file actions
93 lines (81 loc) · 2.72 KB
/
sentry.server.config.ts
File metadata and controls
93 lines (81 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// This file configures the initialization of Sentry on the server.
// The config you add here will be used whenever the server handles a request.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
// But note tricky corner cases using vercel otel with sentry:
// https://docs.sentry.io/platforms/javascript/guides/nextjs/opentelemetry/custom-setup/
import { consoleLoggingIntegration, httpIntegration, init } from '@sentry/nextjs';
type DrizzleQueryError = Error & {
query: string;
params: unknown[];
cause?: { code?: string; message?: string };
};
function isDrizzleQueryError(error: unknown): error is DrizzleQueryError {
return (
error instanceof Error &&
'query' in error &&
'params' in error &&
typeof error.query === 'string'
);
}
const TRPC_4XX_CODES = new Set([
'BAD_REQUEST',
'UNAUTHORIZED',
'PAYMENT_REQUIRED',
'FORBIDDEN',
'NOT_FOUND',
'METHOD_NOT_SUPPORTED',
'TIMEOUT',
'CONFLICT',
'PRECONDITION_FAILED',
'PAYLOAD_TOO_LARGE',
'UNPROCESSABLE_CONTENT',
'TOO_MANY_REQUESTS',
'CLIENT_CLOSED_REQUEST',
]);
function isTRPC4xxError(error: unknown): boolean {
return (
error instanceof Error &&
'code' in error &&
typeof error.code === 'string' &&
TRPC_4XX_CODES.has(error.code)
);
}
if (process.env.NODE_ENV !== 'development') {
init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
tracesSampleRate: 0.05,
// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,
normalizeDepth: 5,
// Skip Sentry's OTEL setup because we are using Vercel's OTEL with SentrySpanProcessor
skipOpenTelemetrySetup: true,
integrations: [
// Keep Sentry's httpIntegration for correct request isolation, but do not
// emit spans here because tracing spans are produced by Vercel's OTel.
httpIntegration({ spans: false }),
// send console.log, console.error, and console.warn calls as logs to Sentry
consoleLoggingIntegration({ levels: ['log', 'error', 'warn'] }),
],
beforeSend(event, hint) {
const error = hint.originalException;
if (isTRPC4xxError(error)) {
return null;
}
// Drizzle Queries are wrapped and that prevents Sentry from properly grouping them
if (isDrizzleQueryError(error)) {
const pgCode = error.cause?.code;
event.fingerprint = [
'drizzle-query-error',
pgCode ?? 'generic',
error.cause?.message ?? 'generic',
];
event.tags = {
...event.tags,
'db.error_code': pgCode,
};
}
return event;
},
});
}