Skip to content

Commit af8212b

Browse files
committed
feat: enhance Sentry integration with profiling and improved initialization
1 parent 061cd94 commit af8212b

File tree

6 files changed

+1443
-1645
lines changed

6 files changed

+1443
-1645
lines changed

electron/main/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { app } from 'electron';
22
import { config as initializeDotenv } from 'dotenv-flow';
3-
import { initializeApp } from './initialize-app.js';
43
import { initializeSentry } from './sentry/initialize-sentry.js';
54

65
// Unfortunately in development mode, the app name is 'Electron'.
@@ -13,4 +12,7 @@ app.setAppUserModelId('com.github.dragonrealms-phoenix.phoenix');
1312
initializeDotenv();
1413
initializeSentry();
1514

15+
// Wait to initialize the app until the above config and SDK's are ready.
16+
// Otherwise, the app may use the wrong app name/paths for logs, etc.
17+
const { initializeApp } = await import('./initialize-app.js');
1618
await initializeApp();

electron/main/sentry/__tests__/initialize-sentry.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ describe('initialize-sentry', () => {
2929

3030
expect(mockSentryElectronMain.init).toHaveBeenCalledWith({
3131
dsn: 'test:sentry:dsn',
32+
enableRendererProfiling: true,
3233
tracesSampleRate: 1,
34+
profilesSampleRate: 1,
3335
normalizeDepth: 5,
3436
debug: false,
3537
});

electron/main/sentry/initialize-sentry.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,31 @@ export const initializeSentry = (): void => {
44
SentryElectron.init({
55
dsn: process.env.SENTRY_DSN,
66

7-
// Adjust this value in production, or use tracesSampler for greater control
7+
/**
8+
* https://docs.sentry.io/platforms/javascript/guides/electron/profiling/browser-profiling/
9+
*/
10+
enableRendererProfiling: true,
11+
12+
/**
13+
* Adjust this to control the sample rate for profiling.
14+
* A number between 0.0 and 1.0 (100%).
15+
*/
816
tracesSampleRate: 1,
917

10-
// Maximum number of levels JSON logging will traverse in objects and arrays.
18+
/**
19+
* Sets profiling sample rate when @sentry/profiling-node is installed.
20+
* A number between 0.0 and 1.0 (100%).
21+
*/
22+
profilesSampleRate: 1,
23+
24+
/**
25+
* Maximum number of levels JSON logging will traverse in objects and arrays.
26+
*/
1127
normalizeDepth: 5,
1228

13-
// Setting this option to true will print useful information to the console while you're setting up Sentry.
29+
/**
30+
* Setting this option to true will print useful information to the console while you're setting up Sentry.
31+
*/
1432
debug: false,
1533
});
1634
};

electron/renderer/sentry.config.ts

+41-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,49 @@
11
// Sentry Config for Next.js
22
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
33

4+
import * as SentryElectron from '@sentry/electron/renderer';
45
import * as SentryNextjs from '@sentry/nextjs';
56

6-
SentryNextjs.init({
7-
dsn: process.env.SENTRY_DSN,
7+
SentryElectron.init<
8+
SentryElectron.BrowserOptions & SentryNextjs.BrowserOptions
9+
>(
10+
{
11+
/**
12+
* List of integrations that should be installed after SDK was initialized.
13+
* Accepts either a list of integrations or a function that receives
14+
* default integrations and returns a new, updated list.
15+
* https://docs.sentry.io/platforms/javascript/guides/electron/configuration/integrations/
16+
*/
17+
integrations: (integrations: Array<any>) => {
18+
return [
19+
...integrations,
20+
SentryElectron.browserTracingIntegration(),
21+
SentryElectron.browserProfilingIntegration(),
22+
SentryElectron.browserSessionIntegration(),
23+
];
24+
},
825

9-
// Adjust this value in production, or use tracesSampler for greater control
10-
tracesSampleRate: 1,
26+
/**
27+
* Adjust this to control the sample rate for profiling.
28+
* A number between 0.0 and 1.0 (100%).
29+
*/
30+
tracesSampleRate: 1,
1131

12-
// Maximum number of levels JSON logging will traverse in objects and arrays.
13-
normalizeDepth: 5,
32+
/**
33+
* Sets profiling sample rate when @sentry/profiling-node is installed.
34+
* A number between 0.0 and 1.0 (100%).
35+
*/
36+
profilesSampleRate: 1,
1437

15-
// Setting this option to true will print useful information to the console while you're setting up Sentry.
16-
debug: false,
17-
});
38+
/**
39+
* Maximum number of levels JSON logging will traverse in objects and arrays.
40+
*/
41+
normalizeDepth: 5,
42+
43+
/**
44+
* Setting this option to true will print useful information to the console while you're setting up Sentry.
45+
*/
46+
debug: false,
47+
},
48+
SentryNextjs.init
49+
);

next.config.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -274,16 +274,16 @@ const nextConfig = {
274274
};
275275

276276
export default withSentryConfig(nextConfig, {
277-
// For all available options, see:
278-
// https://github.com/getsentry/sentry-webpack-plugin#options
279-
280277
org: process.env.SENTRY_ORG,
281278
project: process.env.SENTRY_PROJECT,
282279
authToken: process.env.SENTRY_AUTH_TOKEN,
283280

284281
release: {
285282
286283
name: `${process.env.npm_package_name}@${process.env.npm_package_version}-${gitHash}`,
284+
setCommits: {
285+
auto: true,
286+
},
287287
},
288288

289289
// Suppresses source map uploading logs during build.
@@ -292,15 +292,12 @@ export default withSentryConfig(nextConfig, {
292292
// Don't send internal plugin errors and performance data to Sentry.
293293
telemetry: false,
294294

295-
// For all available options, see:
296-
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
295+
// Automatically tree-shake Sentry logger statements to reduce bundle size.
296+
disableLogger: true,
297297

298298
// Upload a larger set of source maps for prettier stack traces (increases build time).
299299
widenClientFileUpload: true,
300300

301-
// Automatically tree-shake Sentry logger statements to reduce bundle size.
302-
disableLogger: true,
303-
304301
sourcemaps: {
305302
// Reduce client bundle size by excluding source maps after upload.
306303
deleteSourcemapsAfterUpload: true,

0 commit comments

Comments
 (0)