Skip to content

Commit f66309f

Browse files
committed
improve/sentry error handeling (removed "any"
remove/deprecated sentry dependency fix/sentry syntax errors
1 parent 70772f9 commit f66309f

File tree

11 files changed

+56
-95
lines changed

11 files changed

+56
-95
lines changed

apps/frontend/src/lib/sentry-tracking.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function trackPerformanceIssue(operation: string, duration: number, thres
7575
}
7676
}
7777

78-
export function trackAPICall(method: string, url: string, status: number, duration: number, error?: any) {
78+
export function trackAPICall(method: string, url: string, status: number, duration: number, error?: Error | unknown) {
7979
const baseData = {
8080
method,
8181
url,

libraries/helpers/src/sentry/sentry.client.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class SentryClientService {
107107
});
108108
}
109109

110-
static captureException(error: any, context?: any) {
110+
static captureException(error: Error | unknown, context?: Record<string, unknown>) {
111111
if (typeof window === 'undefined') return;
112112

113113
return Sentry.withScope((scope) => {
@@ -118,7 +118,7 @@ export class SentryClientService {
118118
});
119119
}
120120

121-
static captureMessage(message: string, level: Sentry.SeverityLevel = 'info', context?: any) {
121+
static captureMessage(message: string, level: Sentry.SeverityLevel = 'info', context?: Record<string, unknown>) {
122122
if (typeof window === 'undefined') return;
123123

124124
return Sentry.withScope((scope) => {
@@ -135,7 +135,7 @@ export class SentryClientService {
135135
Sentry.setUser(user);
136136
}
137137

138-
static addBreadcrumb(message: string, category?: string, data?: any) {
138+
static addBreadcrumb(message: string, category?: string, data?: Record<string, unknown>) {
139139
if (typeof window === 'undefined') return;
140140

141141
Sentry.addBreadcrumb({
@@ -152,7 +152,7 @@ export class SentryClientService {
152152
Sentry.setTag(key, value);
153153
}
154154

155-
static setContext(key: string, context: any) {
155+
static setContext(key: string, context: Record<string, unknown>) {
156156
if (typeof window === 'undefined') return;
157157

158158
Sentry.setContext(key, context);

libraries/helpers/src/sentry/sentry.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface SentryConfig {
99
enabled: boolean;
1010
release?: string;
1111
serverName?: string;
12-
beforeSend?: (event: any, hint: any) => any;
12+
beforeSend?: (event: any, hint: { originalException?: Error | unknown }) => any;
1313
integrations?: any[];
1414
}
1515

libraries/helpers/src/sentry/sentry.nestjs.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class SentryNestJSService {
9090
});
9191
}
9292

93-
static captureException(error: any, context?: any) {
93+
static captureException(error: Error | unknown, context?: Record<string, unknown>) {
9494
if (!SentryConfigService.isEnabled()) return;
9595

9696
return Sentry.withScope((scope) => {
@@ -101,7 +101,7 @@ export class SentryNestJSService {
101101
});
102102
}
103103

104-
static captureMessage(message: string, level: Sentry.SeverityLevel = 'info', context?: any) {
104+
static captureMessage(message: string, level: Sentry.SeverityLevel = 'info', context?: Record<string, unknown>) {
105105
if (!SentryConfigService.isEnabled()) return;
106106

107107
return Sentry.withScope((scope) => {
@@ -118,7 +118,7 @@ export class SentryNestJSService {
118118
Sentry.setUser(user);
119119
}
120120

121-
static addBreadcrumb(message: string, category?: string, data?: any) {
121+
static addBreadcrumb(message: string, category?: string, data?: Record<string, unknown>) {
122122
if (!SentryConfigService.isEnabled()) return;
123123

124124
Sentry.addBreadcrumb({
@@ -135,7 +135,7 @@ export class SentryNestJSService {
135135
Sentry.setTag(key, value);
136136
}
137137

138-
static setContext(key: string, context: any) {
138+
static setContext(key: string, context: Record<string, unknown>) {
139139
if (!SentryConfigService.isEnabled()) return;
140140

141141
Sentry.setContext(key, context);

libraries/helpers/src/sentry/sentry.nextjs.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class SentryNextService {
126126
});
127127
}
128128

129-
static captureException(error: any, context?: any) {
129+
static captureException(error: Error | unknown, context?: Record<string, unknown>) {
130130
if (typeof window === 'undefined') return;
131131

132132
return Sentry.withScope((scope) => {
@@ -137,7 +137,7 @@ export class SentryNextService {
137137
});
138138
}
139139

140-
static captureMessage(message: string, level: Sentry.SeverityLevel = 'info', context?: any) {
140+
static captureMessage(message: string, level: Sentry.SeverityLevel = 'info', context?: Record<string, unknown>) {
141141
if (typeof window === 'undefined') return;
142142

143143
return Sentry.withScope((scope) => {
@@ -154,7 +154,7 @@ export class SentryNextService {
154154
Sentry.setUser(user);
155155
}
156156

157-
static addBreadcrumb(message: string, category?: string, data?: any) {
157+
static addBreadcrumb(message: string, category?: string, data?: Record<string, unknown>) {
158158
if (typeof window === 'undefined') return;
159159

160160
Sentry.addBreadcrumb({
@@ -171,7 +171,7 @@ export class SentryNextService {
171171
Sentry.setTag(key, value);
172172
}
173173

174-
static setContext(key: string, context: any) {
174+
static setContext(key: string, context: Record<string, unknown>) {
175175
if (typeof window === 'undefined') return;
176176

177177
Sentry.setContext(key, context);

libraries/helpers/src/sentry/sentry.react.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class SentryReactService {
9696
});
9797
}
9898

99-
static captureException(error: any, context?: any) {
99+
static captureException(error: Error | unknown, context?: Record<string, unknown>) {
100100
if (!SentryConfigService.isEnabled()) return;
101101

102102
return Sentry.withScope((scope) => {
@@ -107,7 +107,7 @@ export class SentryReactService {
107107
});
108108
}
109109

110-
static captureMessage(message: string, level: Sentry.SeverityLevel = 'info', context?: any) {
110+
static captureMessage(message: string, level: Sentry.SeverityLevel = 'info', context?: Record<string, unknown>) {
111111
if (!SentryConfigService.isEnabled()) return;
112112

113113
return Sentry.withScope((scope) => {
@@ -124,7 +124,7 @@ export class SentryReactService {
124124
Sentry.setUser(user);
125125
}
126126

127-
static addBreadcrumb(message: string, category?: string, data?: any) {
127+
static addBreadcrumb(message: string, category?: string, data?: Record<string, unknown>) {
128128
if (!SentryConfigService.isEnabled()) return;
129129

130130
Sentry.addBreadcrumb({
@@ -141,7 +141,7 @@ export class SentryReactService {
141141
Sentry.setTag(key, value);
142142
}
143143

144-
static setContext(key: string, context: any) {
144+
static setContext(key: string, context: Record<string, unknown>) {
145145
if (!SentryConfigService.isEnabled()) return;
146146

147147
Sentry.setContext(key, context);
@@ -154,7 +154,7 @@ export class SentryReactService {
154154
return Sentry.startSpan({
155155
name,
156156
op: op || 'custom',
157-
});
157+
}, (span) => span);
158158
}
159159

160160
static showReportDialog(eventId?: string) {

libraries/nestjs-libraries/src/services/sentry.exception.filter.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { SentryNestJSService } from '@gitroom/helpers/sentry';
55
@Catch()
66
export class SentryExceptionFilter implements ExceptionFilter {
77
private readonly logger = new Logger(SentryExceptionFilter.name);
8+
9+
private static readonly MONITORING_PATTERNS = ['/health', '/ping', '/status', '/monitor', '/metrics', '/favicon.ico'];
810

911
catch(exception: unknown, host: ArgumentsHost) {
1012
const ctx = host.switchToHttp();
@@ -75,7 +77,8 @@ export class SentryExceptionFilter implements ExceptionFilter {
7577

7678
// Don't log common monitoring/health check endpoints as errors
7779
if (status === 404) {
78-
if (SentryExceptionFilter.MONITORING_PATTERNS.some(pattern => request.url.includes(pattern))) {
80+
const monitoringPatterns = ['/health', '/ping', '/status', '/monitor', '/metrics', '/favicon.ico'];
81+
if (monitoringPatterns.some(pattern => request.url.includes(pattern))) {
7982
return false;
8083
}
8184

libraries/nestjs-libraries/src/services/sentry.notification.service.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,36 @@ export class SentryNotificationService {
3636
}
3737
}
3838

39+
private handleAttemptEvent(baseContext: any, data: any) {
40+
// Track post publishing attempt as breadcrumb
41+
SentryNestJSService.addBreadcrumb(
42+
`Post publishing attempt: ${data.provider}`,
43+
'post.attempt',
44+
baseContext
45+
);
46+
}
47+
48+
private handleSuccessEvent(baseContext: any, data: any) {
49+
// Track successful post publishing as breadcrumb only
50+
SentryNestJSService.addBreadcrumb(
51+
`Post published successfully: ${data.provider}`,
52+
'post.success',
53+
baseContext
54+
);
55+
}
56+
57+
private handleFailedEvent(baseContext: any, data: any) {
58+
// Track failed post publishing as error
59+
SentryNestJSService.captureException(data.error || new Error('Post publishing failed'), {
60+
extra: { ...baseContext, metadata: data.metadata },
61+
tags: {
62+
event: 'post_publishing_failed',
63+
provider: data.provider,
64+
},
65+
level: 'error',
66+
});
67+
}
68+
3969
/**
4070
* Track integration connection issues
4171
*/

libraries/nestjs-libraries/src/services/sentry.worker.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class SentryWorkerService {
2222
});
2323
}
2424

25-
trackJobFailed(jobName: string, jobId: string, error: any, attemptNumber: number, organizationId?: string) {
25+
trackJobFailed(jobName: string, jobId: string, error: Error | unknown, attemptNumber: number, organizationId?: string) {
2626
this._sentryNotificationService.trackWorkerJobEvent('failed', {
2727
jobName,
2828
jobId,

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,10 @@
7575
"@postiz/wallets": "^0.0.1",
7676
"@prisma/client": "^6.5.0",
7777
"@sentry/browser": "^8.47.0",
78-
"@sentry/integrations": "^7.119.2",
7978
"@sentry/nestjs": "^8.47.0",
8079
"@sentry/nextjs": "^8.47.0",
8180
"@sentry/profiling-node": "^8.47.0",
8281
"@sentry/react": "^8.47.0",
83-
"@sentry/tracing": "^7.119.2",
8482
"@solana/wallet-adapter-react": "^0.15.35",
8583
"@solana/wallet-adapter-react-ui": "^0.9.35",
8684
"@swc/helpers": "0.5.13",

0 commit comments

Comments
 (0)