-
Notifications
You must be signed in to change notification settings - Fork 2k
/
sentry.service.ts
151 lines (123 loc) · 4.13 KB
/
sentry.service.ts
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import * as Sentry from '@sentry/react';
import { BrowserTracing } from '@sentry/tracing';
import { CurrentGameBuild, CurrentGameName, CurrentGamePureLevel } from 'cfx/base/gameRuntime';
import { ServicesContainer } from 'cfx/base/servicesContainer';
import { IAccountService } from 'cfx/common/services/account/account.service';
import { IAccount } from 'cfx/common/services/account/types';
import { AppContribution, registerAppContribution } from 'cfx/common/services/app/app.extensions';
import { fetcher } from 'cfx/utils/fetcher';
import { inject, injectable } from 'inversify';
import { mpMenu } from '../../mpMenu';
import { IConvarService } from '../convars/convars.service';
import { ASID } from "cfx/utils/asid";
const ENABLE_SENTRY = !__CFXUI_DEV__ && process.env.CI_PIPELINE_ID;
if (ENABLE_SENTRY) {
Sentry.init({
dsn: "https://cb2ef6d1855b4c5f83c5530b72b8aacb@sentry.fivem.net/12",
integrations: [new BrowserTracing({
tracingOrigins: ['localhost', 'nui-game-internal', /\.fivem.net/, /\.cfx.re/],
})],
tracesSampleRate: 0.05,
release: `cfx-${process.env.CI_PIPELINE_ID || 'dev'}`,
beforeSend(event, hint) {
// Ignore errors from console
if (event.exception?.values?.[0].stacktrace?.frames?.[0].filename === '<anonymous>') {
return null;
}
// Ignore handled exceptions
if (event.exception?.values?.[0]?.mechanism?.handled) {
return null;
}
const og = hint.originalException;
if (typeof og === 'object' && og) {
event.tags ??= {};
event.extra ??= {};
if (fetcher.HttpError.is(og)) {
event.tags.http_status_code = og.response.status;
event.tags.http_request_url = og.response.url;
event.extra.http_response_headers = og.response.headers;
}
if (fetcher.JsonParseError.is(og)) {
event.extra.json_original_string = og.originalString;
}
}
return event;
},
});
const id = ASID;
Sentry.setUser({
id,
username: id,
});
}
export function registerSentryService(container: ServicesContainer) {
if (!ENABLE_SENTRY) {
return;
}
registerAppContribution(container, SentryService);
}
@injectable()
class SentryService implements AppContribution {
constructor(
@inject(IAccountService)
protected readonly accountService: IAccountService,
@inject(IConvarService)
protected readonly convarService: IConvarService,
) { }
init() {
this.accountService.accountChange.addListener(({ account }) => this.setSentryUser(account));
this.setSentryUser(this.accountService.account);
this.setSentryContext();
}
private async setSentryContext() {
try {
const storageEstimate = await navigator.storage.estimate();
Sentry.setContext('System Limits', {
hasAtLeastThisAmountOfRam: (navigator as any).deviceMemory,
storageEstimateQuota: storageEstimate.quota || 'unknown',
storageEstimateUsage: storageEstimate.usage || 'unknown',
});
} catch (e) { }
Sentry.setContext('NUI', {
systemLanguages: mpMenu.systemLanguages,
gameName: CurrentGameName,
gameBuild: CurrentGameBuild,
gamePureLevel: CurrentGamePureLevel,
});
await this.convarService.whenPopulated();
Sentry.setContext('convars', Object.fromEntries(
Object.entries(this.convarService.getAll()).filter(([key, value]) => {
if (key.startsWith('cl_')) {
return false;
}
if (key.startsWith('cam_')) {
return false;
}
if (key.startsWith('net_')) {
return false;
}
if (key.startsWith('game_')) {
return false;
}
if (key.startsWith('voice_')) {
return false;
}
if (key.startsWith('profile_')) {
return false;
}
return true;
}),
));
}
private readonly setSentryUser = (account: IAccount | null) => {
if (account) {
Sentry.setContext('cfxUser', {
id: account.id,
link: `https://forum.cfx.re/u/${account.id}`,
username: account.username,
})
} else {
Sentry.setContext('cfxUser', null);
}
};
}