From a5693f2199c1dde52aa094182f14d27a55644bb5 Mon Sep 17 00:00:00 2001 From: Robin Huang Date: Mon, 14 Oct 2024 13:09:08 -0700 Subject: [PATCH] Set GPU info in Sentry context. (#79) * Get GPU information for Sentry. * Set GPU in sentry error context. * Set all available GPU as context. * Prettier. --- package.json | 1 + src/main.ts | 24 ++++++++++++++++++++++++ yarn.lock | 11 +++++++++++ 3 files changed, 36 insertions(+) diff --git a/package.json b/package.json index 704f5b5d..3dc6efa4 100644 --- a/package.json +++ b/package.json @@ -84,6 +84,7 @@ "jest": "^29.7.0", "react": "^18.3.1", "react-dom": "^18.3.1", + "systeminformation": "^5.23.5", "tar": "^7.4.3", "update-electron-app": "^3.0.0" } diff --git a/src/main.ts b/src/main.ts index 233fe037..46d15b69 100644 --- a/src/main.ts +++ b/src/main.ts @@ -13,6 +13,7 @@ import * as Sentry from '@sentry/electron/main'; import { updateElectronApp, UpdateSourceType } from 'update-electron-app'; import * as net from 'net'; +import { graphics } from 'systeminformation'; log.initialize(); // Handle creating/removing shortcuts on Windows when installing/uninstalling. @@ -69,6 +70,29 @@ if (!gotTheLock) { ], }); + graphics() + .then((graphicsInfo) => { + log.info('GPU Info: ', graphicsInfo); + + const gpuInfo = graphicsInfo.controllers.map((gpu, index) => ({ + [`gpu_${index}`]: { + vendor: gpu.vendor, + model: gpu.model, + vram: gpu.vram, + driver: gpu.driverVersion, + }, + })); + + // Combine all GPU info into a single object + const allGpuInfo = Object.assign({}, ...gpuInfo); + log.info('GPU Info: ', allGpuInfo); + // Set Sentry context with all GPU information + Sentry.setContext('gpus', allGpuInfo); + }) + .catch((e) => { + log.error('Error getting GPU info: ', e); + }); + // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. diff --git a/yarn.lock b/yarn.lock index 4b574ada..e39f3ff2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5849,6 +5849,7 @@ __metadata: react: "npm:^18.3.1" react-dom: "npm:^18.3.1" rimraf: "npm:^6.0.1" + systeminformation: "npm:^5.23.5" tar: "npm:^7.4.3" ts-jest: "npm:^29.2.5" ts-node: "npm:^10.0.0" @@ -12304,6 +12305,16 @@ __metadata: languageName: node linkType: hard +"systeminformation@npm:^5.23.5": + version: 5.23.5 + resolution: "systeminformation@npm:5.23.5" + bin: + systeminformation: lib/cli.js + checksum: 10c0/849283b2886c46ff5e79594e939c87202b5283b8aa16cd0d665c595781dba51913060728bae95b94837b78c3a515a0f00ab0a0471604990c5c778f555bd075ea + conditions: (os=darwin | os=linux | os=win32 | os=freebsd | os=openbsd | os=netbsd | os=sunos | os=android) + languageName: node + linkType: hard + "tar@npm:^6.0.5, tar@npm:^6.1.11, tar@npm:^6.1.2, tar@npm:^6.2.1": version: 6.2.1 resolution: "tar@npm:6.2.1"